mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 12:52:07 +08:00
单元测试编译修复
This commit is contained in:
+7
-4
@@ -1,5 +1,7 @@
|
||||
package com.cf.imes.module.report.service.template;
|
||||
|
||||
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.test.core.util.RandomUtils;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetReqVO;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetSaveReqVO;
|
||||
@@ -45,6 +47,7 @@ public class ReportDatasetServiceImplTest extends ReportCommonServiceImplTest{
|
||||
public void testCreateDataset_success() {
|
||||
// 1、上下文添加组织id
|
||||
setOrganId();
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
|
||||
// 1、准备template参数
|
||||
// 2、插入template、断言自增id
|
||||
@@ -53,8 +56,8 @@ public class ReportDatasetServiceImplTest extends ReportCommonServiceImplTest{
|
||||
ReportTemplateRespVO reportTemplate = reportTemplateService.createReportTemplate(createReqVO);
|
||||
assertNotNull(reportTemplate);
|
||||
Long templateId = reportTemplate.getId();
|
||||
ReportTemplateDO template = reportTemplateService.getReportTemplate(templateId);
|
||||
assertNotNull(template);
|
||||
ReportDefinitionWrapper reportDefinitionWrapper = reportTemplateService.getReportTemplateDefinition(templateId, organId);
|
||||
assertNotNull(reportDefinitionWrapper);
|
||||
|
||||
// 1、准备datasource参数
|
||||
// 2、插入datasource、断言自增id
|
||||
@@ -87,13 +90,13 @@ public class ReportDatasetServiceImplTest extends ReportCommonServiceImplTest{
|
||||
ReportDatasetReqVO reqVO = new ReportDatasetReqVO();
|
||||
reqVO.setName(updateReqVO.getName());
|
||||
reqVO.setDatasourceId(updateReqVO.getDatasourceId());
|
||||
List<ReportDatasetDO> datasetList = reportDatasetService.getDatasetList(reqVO);
|
||||
List<ReportDatasetDO> datasetList = reportDatasetService.getDatasetList(reqVO, organId);
|
||||
|
||||
assertNotNull(datasetList);
|
||||
assertNotEquals(0, datasetList.size());
|
||||
|
||||
// 删除
|
||||
reportTemplateService.deleteReportTemplate(templateId);
|
||||
reportTemplateService.deleteReportTemplate(templateId, organId);
|
||||
reportDatasourceService.deleteDatasource(datasourceId);
|
||||
reportDatasetService.deleteDataset(datasetId);
|
||||
}
|
||||
|
||||
+6
-3
@@ -1,5 +1,7 @@
|
||||
package com.cf.imes.module.report.service.template;
|
||||
|
||||
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.test.core.util.RandomUtils;
|
||||
import com.cf.imes.module.report.controller.admin.datasource.vo.ReportDatasourceReqVO;
|
||||
import com.cf.imes.module.report.controller.admin.datasource.vo.ReportDatasourceSaveReqVO;
|
||||
@@ -37,6 +39,7 @@ public class ReportDatasourceServiceImplTest extends ReportCommonServiceImplTest
|
||||
public void testCreateTemplate_success() {
|
||||
// 1、上下文添加组织id
|
||||
setOrganId();
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
|
||||
// 1、准备template参数
|
||||
// 2、插入template、断言自增id
|
||||
@@ -45,8 +48,8 @@ public class ReportDatasourceServiceImplTest extends ReportCommonServiceImplTest
|
||||
ReportTemplateRespVO reportTemplate = reportTemplateService.createReportTemplate(createReqVO);
|
||||
Long templateId = reportTemplate.getId();
|
||||
assertNotNull(templateId);
|
||||
ReportTemplateDO template = reportTemplateService.getReportTemplate(templateId);
|
||||
assertNotNull(template);
|
||||
ReportDefinitionWrapper reportDefinitionWrapper = reportTemplateService.getReportTemplateDefinition(templateId, organId);
|
||||
assertNotNull(reportDefinitionWrapper);
|
||||
|
||||
// 1、准备datasource参数
|
||||
// 2、插入datasource、断言自增id
|
||||
@@ -78,7 +81,7 @@ public class ReportDatasourceServiceImplTest extends ReportCommonServiceImplTest
|
||||
assertNotEquals(0, templateDatasourceList.size());
|
||||
|
||||
// 删除
|
||||
reportTemplateService.deleteReportTemplate(templateId);
|
||||
reportTemplateService.deleteReportTemplate(templateId, organId);
|
||||
reportDatasourceService.deleteDatasource(datasourceId);
|
||||
}
|
||||
|
||||
|
||||
+22
-15
@@ -1,5 +1,7 @@
|
||||
package com.cf.imes.module.report.service.template;
|
||||
|
||||
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.test.core.util.RandomUtils;
|
||||
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateReqVO;
|
||||
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateRespVO;
|
||||
@@ -32,6 +34,8 @@ public class ReportTemplateServiceImplTest extends ReportCommonServiceImplTest {
|
||||
@Test
|
||||
public void testCreateTemplate_success() {
|
||||
setOrganId();
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
|
||||
// 准备参数
|
||||
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||
System.out.println("template压缩后大小:" + createReqVO.getContent().length());
|
||||
@@ -41,19 +45,18 @@ public class ReportTemplateServiceImplTest extends ReportCommonServiceImplTest {
|
||||
// 断言
|
||||
assertNotNull(templateId);
|
||||
// 校验是否插入
|
||||
ReportTemplateDO template = reportTemplateService.getReportTemplate(templateId);
|
||||
assertNotNull(template);
|
||||
String templateUnZip = template.getContent();
|
||||
System.out.println("从库中读取template大小:" + templateUnZip.length());
|
||||
// 校验解压内容是否正确
|
||||
assertEquals(TEMPLATE, JsonUtil.unzipString(templateUnZip));
|
||||
ReportDefinitionWrapper reportDefinitionWrapper = reportTemplateService.getReportTemplateDefinition(templateId, organId);
|
||||
assertNotNull(reportDefinitionWrapper);
|
||||
|
||||
// 删除
|
||||
reportTemplateService.deleteReportTemplate(templateId);
|
||||
reportTemplateService.deleteReportTemplate(templateId, organId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateTemplate_success() {
|
||||
setOrganId();
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
|
||||
// 准备参数
|
||||
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||
System.out.println("template压缩后大小:" + createReqVO.getContent().length());
|
||||
@@ -67,11 +70,11 @@ public class ReportTemplateServiceImplTest extends ReportCommonServiceImplTest {
|
||||
// 更新
|
||||
reportTemplateService.updateReportTemplate(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
ReportTemplateDO template = reportTemplateService.getReportTemplate(updateReqVO.getId()); // 获取最新的
|
||||
assertNotNull(template);
|
||||
isPojoEquals(template,updateReqVO);
|
||||
ReportDefinitionWrapper reportDefinitionWrapper = reportTemplateService.getReportTemplateDefinition(updateReqVO.getId(), organId); // 获取最新的
|
||||
assertNotNull(reportDefinitionWrapper);
|
||||
|
||||
// 删除
|
||||
reportTemplateService.deleteReportTemplate(templateId);
|
||||
reportTemplateService.deleteReportTemplate(templateId, organId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,6 +89,8 @@ public class ReportTemplateServiceImplTest extends ReportCommonServiceImplTest {
|
||||
@Test
|
||||
public void deleteTemplate_success() {
|
||||
setOrganId();
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
|
||||
// 准备参数
|
||||
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||
// 插入
|
||||
@@ -93,24 +98,26 @@ public class ReportTemplateServiceImplTest extends ReportCommonServiceImplTest {
|
||||
Long templateId = reportTemplate.getId();
|
||||
|
||||
// 删除
|
||||
reportTemplateService.deleteReportTemplate(templateId);
|
||||
reportTemplateService.deleteReportTemplate(templateId, organId);
|
||||
// 校验数据不存在了
|
||||
assertNull(reportTemplateService.getReportTemplate(templateId));
|
||||
assertNull(reportTemplateService.getReportTemplateDefinition(templateId, organId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteTemplate_notExists() {
|
||||
setOrganId();
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
// 准备参数
|
||||
Long id = RandomUtils.randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> reportTemplateService.deleteReportTemplate(id), TEMPLATE_NOT_EXISTS);
|
||||
assertServiceException(() -> reportTemplateService.deleteReportTemplate(id, organId), TEMPLATE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTemplateList_success() {
|
||||
setOrganId(2L);
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
|
||||
// 准备参数
|
||||
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||
@@ -128,6 +135,6 @@ public class ReportTemplateServiceImplTest extends ReportCommonServiceImplTest {
|
||||
assertEquals(2L, reportTemplateList.get(0).getOrganId());
|
||||
|
||||
// 删除
|
||||
reportTemplateService.deleteReportTemplate(templateId);
|
||||
reportTemplateService.deleteReportTemplate(templateId, organId);
|
||||
}
|
||||
}
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package com.cf.imes.module.system.controller.admin.oauth2;
|
||||
|
||||
import com.cf.imes.framework.es.core.service.ESDocumentService;
|
||||
import com.cf.imes.framework.test.core.ut.BaseMockitoUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class EsTest extends BaseMockitoUnitTest {
|
||||
|
||||
@Resource
|
||||
private ESDocumentService esDocumentService;
|
||||
|
||||
@Test
|
||||
public void t1() throws IOException {
|
||||
HashMap test2 = esDocumentService.getById("test2", "145116052710363136", HashMap.class);
|
||||
assertNotNull(test2);
|
||||
System.out.println(test2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void d1() throws IOException {
|
||||
Boolean delete = esDocumentService.deleteById("t1", "145125592260546560");
|
||||
assertTrue(delete);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+3
-3
@@ -26,7 +26,7 @@ import org.springframework.context.annotation.Import;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -106,7 +106,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
|
||||
void testValidTenant_expired() {
|
||||
// mock 数据
|
||||
OrganizationDO tenant = randomPojo(OrganizationDO.class, o -> o.setId(1L).setStatus(CommonStatusEnum.ENABLE.getStatus())
|
||||
.setExpireTime(LocalDate.now().minusDays(1)));
|
||||
.setExpireTime(LocalDateTime.now().minusDays(1)));
|
||||
tenantMapper.insert(tenant);
|
||||
|
||||
// 调用,并断言业务异常
|
||||
@@ -117,7 +117,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
|
||||
void testValidTenant_success() {
|
||||
// mock 数据
|
||||
OrganizationDO tenant = randomPojo(OrganizationDO.class, o -> o.setId(1L).setStatus(CommonStatusEnum.ENABLE.getStatus())
|
||||
.setExpireTime(LocalDate.now().plusDays(1)));
|
||||
.setExpireTime(LocalDateTime.now().plusDays(1)));
|
||||
tenantMapper.insert(tenant);
|
||||
|
||||
// 调用,并断言业务异常
|
||||
|
||||
+2
-2
@@ -472,7 +472,7 @@ class TokenConfigServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
|
||||
OrganizationDO disabledOrgan = new OrganizationDO();
|
||||
disabledOrgan.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
disabledOrgan.setExpireTime(LocalDate.now().minusDays(1));
|
||||
disabledOrgan.setExpireTime(LocalDateTime.now().minusDays(1));
|
||||
when(organMapper.selectById(any())).thenReturn(disabledOrgan);
|
||||
|
||||
assertServiceException(() -> tokenConfigService.checkTokenConfig("imes-valid-token"),
|
||||
@@ -489,7 +489,7 @@ class TokenConfigServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
|
||||
OrganizationDO disabledOrgan = new OrganizationDO();
|
||||
disabledOrgan.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
disabledOrgan.setExpireTime(LocalDate.now().plusDays(1));
|
||||
disabledOrgan.setExpireTime(LocalDateTime.now().plusDays(1));
|
||||
when(organMapper.selectById(any())).thenReturn(disabledOrgan);
|
||||
|
||||
Long result = tokenConfigService.checkTokenConfig("imes-valid-token");
|
||||
|
||||
Reference in New Issue
Block a user