单元测试编译修复

This commit is contained in:
gaoqr
2026-07-07 16:46:03 +08:00
parent e9dbf203f1
commit 8fc60b5d57
6 changed files with 40 additions and 62 deletions
@@ -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);
}
@@ -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);
}
@@ -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);
}
}