From c89d59f53008d323afc71b6b1c5cda1fc088d046 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Thu, 9 Nov 2023 19:02:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=85=B3=E8=81=94=E9=99=84=E4=BB=B6-=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8=E5=88=86=E9=A1=B5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FunctionalCaseAttachmentController.java | 40 +++++++++++++ .../controller/FunctionalCaseController.java | 9 ++- ...sFieldDTO.java => CaseCustomFieldDTO.java} | 4 +- .../functional/dto/FunctionalCasePageDTO.java | 2 +- .../request/FunctionalCaseAddRequest.java | 4 +- .../FunctionalCaseCustomFieldService.java | 38 ++++++------ .../service/FunctionalCaseNoticeService.java | 12 ++-- .../service/FunctionalCaseService.java | 14 ++--- ...nctionalCaseAttachmentControllerTests.java | 34 +++++++++++ .../FunctionalCaseControllerTests.java | 60 +++++++++++-------- .../resources/dml/init_file_metadata_test.sql | 2 +- .../service/ProjectTemplateService.java | 2 +- .../ProjectTemplateControllerTests.java | 6 +- 13 files changed, 155 insertions(+), 72 deletions(-) create mode 100644 backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseAttachmentController.java rename backend/services/case-management/src/main/java/io/metersphere/functional/dto/{CaseCustomsFieldDTO.java => CaseCustomFieldDTO.java} (88%) create mode 100644 backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseAttachmentControllerTests.java diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseAttachmentController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseAttachmentController.java new file mode 100644 index 0000000000..89b0c0e980 --- /dev/null +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseAttachmentController.java @@ -0,0 +1,40 @@ +package io.metersphere.functional.controller; + +import io.metersphere.project.dto.filemanagement.request.FileMetadataTableRequest; +import io.metersphere.project.dto.filemanagement.response.FileInformationResponse; +import io.metersphere.project.service.FileMetadataService; +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.utils.Pager; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @author wx + */ +@Tag(name = "用例管理-功能用例-附件") +@RestController +@RequestMapping("/attachment/") +public class FunctionalCaseAttachmentController { + + @Resource + private FileMetadataService fileMetadataService; + + + //TODO 附件操作:文件删除/文件下载/文件预览/文件转存/文件更新 + + @PostMapping("/page") + @Operation(summary = "功能用例-关联文件列表分页接口") + @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) + public Pager> page(@Validated @RequestBody FileMetadataTableRequest request) { + return fileMetadataService.page(request); + } +} diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java index 187380a1c2..bf5cbd73f4 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java @@ -50,7 +50,6 @@ public class FunctionalCaseController { //TODO 获取模板列表(多模板功能暂时不做) - //TODO 附件操作:文件删除/文件下载/文件预览/文件转存/文件更新 @GetMapping("/default/template/field/{projectId}") @Operation(summary = "功能用例-获取默认模板自定义字段") @@ -65,7 +64,7 @@ public class FunctionalCaseController { @Operation(summary = "功能用例-新增用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_ADD) @Log(type = OperationLogType.ADD, expression = "#msClass.addFunctionalCaseLog(#request, #files)", msClass = FunctionalCaseLogService.class) - @SendNotice(taskType = NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.getMainFunctionalCaseDTO(#request.name, #request.caseEditType, #request.projectId, #request.customsFields)", targetClass = FunctionalCaseNoticeService.class) + @SendNotice(taskType = NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.getMainFunctionalCaseDTO(#request.name, #request.caseEditType, #request.projectId, #request.customFields)", targetClass = FunctionalCaseNoticeService.class) public FunctionalCase addFunctionalCase(@Validated @RequestPart("request") FunctionalCaseAddRequest request, @RequestPart(value = "files", required = false) List files) { String userId = SessionUtils.getUserId(); return functionalCaseService.addFunctionalCase(request, files, userId); @@ -84,7 +83,7 @@ public class FunctionalCaseController { @Operation(summary = "功能用例-更新用例") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateFunctionalCaseLog(#request, #files)", msClass = FunctionalCaseLogService.class) - @SendNotice(taskType = NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getMainFunctionalCaseDTO(#request.name, #request.caseEditType, #request.projectId, #request.customsFields)", targetClass = FunctionalCaseNoticeService.class) + @SendNotice(taskType = NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getMainFunctionalCaseDTO(#request.name, #request.caseEditType, #request.projectId, #request.customFields)", targetClass = FunctionalCaseNoticeService.class) public FunctionalCase updateFunctionalCase(@Validated @RequestPart("request") FunctionalCaseEditRequest request, @RequestPart(value = "files", required = false) List files) { String userId = SessionUtils.getUserId(); return functionalCaseService.updateFunctionalCase(request, files, userId); @@ -149,8 +148,8 @@ public class FunctionalCaseController { @GetMapping("/custom/field/{projectId}") @Operation(summary = "功能用例-获取表头自定义字段(高级搜索中的自定义字段)") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) - public List getTableCustomsField(@PathVariable String projectId) { - return projectTemplateService.getTableCustomsField(projectId, TemplateScene.FUNCTIONAL.name()); + public List getTableCustomField(@PathVariable String projectId) { + return projectTemplateService.getTableCustomField(projectId, TemplateScene.FUNCTIONAL.name()); } @PostMapping("/batch/move") diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseCustomsFieldDTO.java b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseCustomFieldDTO.java similarity index 88% rename from backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseCustomsFieldDTO.java rename to backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseCustomFieldDTO.java index c461eccf6d..aafe034f97 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseCustomsFieldDTO.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseCustomFieldDTO.java @@ -13,7 +13,7 @@ import java.util.Objects; */ @Data @EqualsAndHashCode(callSuper = false) -public class CaseCustomsFieldDTO implements Serializable { +public class CaseCustomFieldDTO implements Serializable { private static final long serialVersionUID = 1L; @@ -28,7 +28,7 @@ public class CaseCustomsFieldDTO implements Serializable { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - CaseCustomsFieldDTO that = (CaseCustomsFieldDTO) o; + CaseCustomFieldDTO that = (CaseCustomFieldDTO) o; return Objects.equals(fieldId, that.fieldId) && Objects.equals(value, that.value); } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCasePageDTO.java b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCasePageDTO.java index 97b8e843af..d02327031b 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCasePageDTO.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCasePageDTO.java @@ -17,5 +17,5 @@ public class FunctionalCasePageDTO extends FunctionalCase { @Schema(description = "自定义字段集合") - private List customsFields; + private List customFields; } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseAddRequest.java b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseAddRequest.java index a75d19c827..f6d3593058 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseAddRequest.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseAddRequest.java @@ -1,6 +1,6 @@ package io.metersphere.functional.request; -import io.metersphere.functional.dto.CaseCustomsFieldDTO; +import io.metersphere.functional.dto.CaseCustomFieldDTO; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import lombok.Data; @@ -65,7 +65,7 @@ public class FunctionalCaseAddRequest implements Serializable { @Schema(description = "自定义字段集合") - private List customsFields; + private List customFields; @Schema(description = "关联文件ID集合") diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCustomFieldService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCustomFieldService.java index 1e9642dc2d..c9fa68a5df 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCustomFieldService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCustomFieldService.java @@ -3,7 +3,7 @@ package io.metersphere.functional.service; import io.metersphere.functional.domain.FunctionalCaseCustomField; import io.metersphere.functional.domain.FunctionalCaseCustomFieldExample; -import io.metersphere.functional.dto.CaseCustomsFieldDTO; +import io.metersphere.functional.dto.CaseCustomFieldDTO; import io.metersphere.functional.mapper.ExtFunctionalCaseCustomFieldMapper; import io.metersphere.functional.mapper.FunctionalCaseCustomFieldMapper; import jakarta.annotation.Resource; @@ -34,14 +34,14 @@ public class FunctionalCaseCustomFieldService { /** * 保存 用例-自定义字段关系 * - * @param customsFields + * @param customFields */ - public void saveCustomField(String caseId, List customsFields) { - customsFields.forEach(customsField -> { + public void saveCustomField(String caseId, List customFields) { + customFields.forEach(custom -> { FunctionalCaseCustomField customField = new FunctionalCaseCustomField(); customField.setCaseId(caseId); - customField.setFieldId(customsField.getFieldId()); - customField.setValue(customsField.getValue()); + customField.setFieldId(custom.getFieldId()); + customField.setValue(custom.getValue()); functionalCaseCustomFieldMapper.insertSelective(customField); }); } @@ -69,21 +69,21 @@ public class FunctionalCaseCustomFieldService { * 更新自定义字段 * * @param caseId - * @param customsFields + * @param customFields */ - public void updateCustomField(String caseId, List customsFields) { - List fieldIds = customsFields.stream().map(CaseCustomsFieldDTO::getFieldId).collect(Collectors.toList()); + public void updateCustomField(String caseId, List customFields) { + List fieldIds = customFields.stream().map(CaseCustomFieldDTO::getFieldId).collect(Collectors.toList()); FunctionalCaseCustomFieldExample example = new FunctionalCaseCustomFieldExample(); example.createCriteria().andFieldIdIn(fieldIds).andCaseIdEqualTo(caseId); List defaultFields = functionalCaseCustomFieldMapper.selectByExample(example); Map collect = defaultFields.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getFieldId, (item) -> item)); - List addFields = new ArrayList<>(); - List updateFields = new ArrayList<>(); - customsFields.forEach(customsField -> { - if (collect.containsKey(customsField.getFieldId())) { - updateFields.add(customsField); + List addFields = new ArrayList<>(); + List updateFields = new ArrayList<>(); + customFields.forEach(customField -> { + if (collect.containsKey(customField.getFieldId())) { + updateFields.add(customField); } else { - addFields.add(customsField); + addFields.add(customField); } }); if (CollectionUtils.isNotEmpty(addFields)) { @@ -95,12 +95,12 @@ public class FunctionalCaseCustomFieldService { } } - private void updateField(String caseId, List updateFields) { - updateFields.forEach(customsField -> { + private void updateField(String caseId, List updateFields) { + updateFields.forEach(custom -> { FunctionalCaseCustomField customField = new FunctionalCaseCustomField(); customField.setCaseId(caseId); - customField.setFieldId(customsField.getFieldId()); - customField.setValue(customsField.getValue()); + customField.setFieldId(custom.getFieldId()); + customField.setValue(custom.getValue()); functionalCaseCustomFieldMapper.updateByPrimaryKeySelective(customField); }); } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseNoticeService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseNoticeService.java index c75621cd14..ec025dd085 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseNoticeService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseNoticeService.java @@ -3,7 +3,7 @@ package io.metersphere.functional.service; import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.functional.domain.FunctionalCaseCustomField; import io.metersphere.functional.domain.FunctionalCaseCustomFieldExample; -import io.metersphere.functional.dto.CaseCustomsFieldDTO; +import io.metersphere.functional.dto.CaseCustomFieldDTO; import io.metersphere.functional.dto.FunctionalCaseDTO; import io.metersphere.functional.mapper.FunctionalCaseCustomFieldMapper; import io.metersphere.functional.mapper.FunctionalCaseMapper; @@ -114,7 +114,7 @@ public class FunctionalCaseNoticeService { return optionDTOList; } - public FunctionalCaseDTO getMainFunctionalCaseDTO(String name, String caseEditType,String projectId, List customsFields) { + public FunctionalCaseDTO getMainFunctionalCaseDTO(String name, String caseEditType,String projectId, List customFields) { String userId = SessionUtils.getUserId(); FunctionalCaseDTO functionalCaseDTO = new FunctionalCaseDTO(); functionalCaseDTO.setName(name); @@ -122,15 +122,15 @@ public class FunctionalCaseNoticeService { functionalCaseDTO.setCaseEditType(caseEditType); functionalCaseDTO.setCreateUser(userId); List fields = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(customsFields)) { - for (CaseCustomsFieldDTO customsFieldDTO : customsFields) { + if (CollectionUtils.isNotEmpty(customFields)) { + for (CaseCustomFieldDTO customFieldDTO : customFields) { OptionDTO optionDTO = new OptionDTO(); - CustomField customField = customFieldMapper.selectByPrimaryKey(customsFieldDTO.getFieldId()); + CustomField customField = customFieldMapper.selectByPrimaryKey(customFieldDTO.getFieldId()); if (customField == null) { continue; } optionDTO.setId(customField.getName()); - optionDTO.setName(customsFieldDTO.getValue()); + optionDTO.setName(customFieldDTO.getValue()); fields.add(optionDTO); } } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index 3206c0654b..ebc58d6c2f 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -1,7 +1,7 @@ package io.metersphere.functional.service; import io.metersphere.functional.domain.*; -import io.metersphere.functional.dto.CaseCustomsFieldDTO; +import io.metersphere.functional.dto.CaseCustomFieldDTO; import io.metersphere.functional.dto.FunctionalCaseDetailDTO; import io.metersphere.functional.dto.FunctionalCasePageDTO; import io.metersphere.functional.dto.FunctionalCaseVersionDTO; @@ -117,10 +117,10 @@ public class FunctionalCaseService { BeanUtils.copyBean(functionalCaseBlob, request); functionalCaseBlobMapper.insertSelective(functionalCaseBlob); //保存自定义字段 - List customsFields = request.getCustomsFields(); - if (CollectionUtils.isNotEmpty(customsFields)) { - customsFields = customsFields.stream().distinct().collect(Collectors.toList()); - functionalCaseCustomFieldService.saveCustomField(caseId, customsFields); + List customFields = request.getCustomFields(); + if (CollectionUtils.isNotEmpty(customFields)) { + customFields = customFields.stream().distinct().collect(Collectors.toList()); + functionalCaseCustomFieldService.saveCustomField(caseId, customFields); } return functionalCase; } @@ -260,7 +260,7 @@ public class FunctionalCaseService { functionalCaseBlobMapper.updateByPrimaryKeySelective(functionalCaseBlob); //更新自定义字段 - functionalCaseCustomFieldService.updateCustomField(request.getId(), request.getCustomsFields()); + functionalCaseCustomFieldService.updateCustomField(request.getId(), request.getCustomFields()); } @@ -387,7 +387,7 @@ public class FunctionalCaseService { List customFields = functionalCaseCustomFieldService.getCustomFieldByCaseIds(ids); Map> collect = customFields.stream().collect(Collectors.groupingBy(FunctionalCaseCustomField::getCaseId)); functionalCaseLists.forEach(functionalCasePageDTO -> { - functionalCasePageDTO.setCustomsFields(collect.get(functionalCasePageDTO.getId())); + functionalCasePageDTO.setCustomFields(collect.get(functionalCasePageDTO.getId())); }); return functionalCaseLists; diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseAttachmentControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseAttachmentControllerTests.java new file mode 100644 index 0000000000..e4b734728b --- /dev/null +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseAttachmentControllerTests.java @@ -0,0 +1,34 @@ +package io.metersphere.functional.controller; + +import io.metersphere.project.dto.filemanagement.request.FileMetadataTableRequest; +import io.metersphere.sdk.util.JSON; +import io.metersphere.system.base.BaseTest; +import io.metersphere.system.controller.handler.ResultHolder; +import org.junit.jupiter.api.*; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MvcResult; + +import java.nio.charset.StandardCharsets; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +@AutoConfigureMockMvc +public class FunctionalCaseAttachmentControllerTests extends BaseTest { + + public static final String ATTACHMENT_PAGE_URL = "/attachment/page"; + + @Test + @Order(1) + public void testAttachmentPage() throws Exception { + FileMetadataTableRequest request = new FileMetadataTableRequest(); + request.setProjectId(DEFAULT_PROJECT_ID); + request.setCurrent(1); + request.setPageSize(10); + MvcResult mvcResult = this.requestPostWithOkAndReturn(ATTACHMENT_PAGE_URL, request); + String updateReturnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder updateResultHolder = JSON.parseObject(updateReturnData, ResultHolder.class); + Assertions.assertNotNull(updateResultHolder); + + } +} diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java index bd8311ae14..68c8be2d54 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java @@ -1,7 +1,7 @@ package io.metersphere.functional.controller; import io.metersphere.functional.domain.FunctionalCase; -import io.metersphere.functional.dto.CaseCustomsFieldDTO; +import io.metersphere.functional.dto.CaseCustomFieldDTO; import io.metersphere.functional.request.*; import io.metersphere.functional.result.FunctionalCaseResultCode; import io.metersphere.functional.utils.FileBaseUtils; @@ -48,6 +48,7 @@ public class FunctionalCaseControllerTests extends BaseTest { public static final String FUNCTIONAL_CASE_TABLE_URL = "/functional/case/custom/field/"; public static final String FUNCTIONAL_CASE_BATCH_MOVE_URL = "/functional/case/batch/move"; public static final String FUNCTIONAL_CASE_BATCH_COPY_URL = "/functional/case/batch/copy"; + public static final String FUNCTIONAL_CASE_VERSION_URL = "/functional/case/version/"; @Resource private NotificationMapper notificationMapper; @@ -73,8 +74,8 @@ public class FunctionalCaseControllerTests extends BaseTest { Assertions.assertNotNull(resultHolder); //设置自定义字段 - List dtoList = creatCustomsFields(); - request.setCustomsFields(dtoList); + List dtoList = creatCustomFields(); + request.setCustomFields(dtoList); //设置文件 String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.JPG")).getPath(); @@ -125,30 +126,30 @@ public class FunctionalCaseControllerTests extends BaseTest { Assertions.assertNotNull(resultHolder); } - private List creatCustomsFields() { + private List creatCustomFields() { insertCustomField(); - List list = new ArrayList<>(); - CaseCustomsFieldDTO customsFieldDTO = new CaseCustomsFieldDTO(); - customsFieldDTO.setFieldId("customs_field_id_1"); - customsFieldDTO.setValue("customs_field_value_1"); - list.add(customsFieldDTO); - CaseCustomsFieldDTO customsFieldDTO2 = new CaseCustomsFieldDTO(); - customsFieldDTO2.setFieldId("customs_field_id_2"); - customsFieldDTO2.setValue("customs_field_value_2"); - list.add(customsFieldDTO2); + List list = new ArrayList<>(); + CaseCustomFieldDTO customFieldDTO = new CaseCustomFieldDTO(); + customFieldDTO.setFieldId("custom_field_id_1"); + customFieldDTO.setValue("custom_field_value_1"); + list.add(customFieldDTO); + CaseCustomFieldDTO customFieldDTO2 = new CaseCustomFieldDTO(); + customFieldDTO2.setFieldId("custom_field_id_2"); + customFieldDTO2.setValue("custom_field_value_2"); + list.add(customFieldDTO2); return list; } private void insertCustomField() { CustomField customField = new CustomField(); - customField.setId("customs_field_id_1"); - customField.setName("test_customs_field_id_1"); + customField.setId("custom_field_id_1"); + customField.setName("test_custom_field_id_1"); customField.setType(CustomFieldType.INPUT.toString()); customField.setScene(TemplateScene.FUNCTIONAL.name()); customField.setCreateUser("gyq"); customField.setCreateTime(System.currentTimeMillis()); customField.setUpdateTime(System.currentTimeMillis()); - customField.setRefId("test_customs_field_id_1"); + customField.setRefId("test_custom_field_id_1"); customField.setScopeId(DEFAULT_PROJECT_ID); customField.setScopeType(TemplateScopeType.PROJECT.name()); customField.setInternal(false); @@ -173,8 +174,8 @@ public class FunctionalCaseControllerTests extends BaseTest { public void testUpdateFunctionalCase() throws Exception { FunctionalCaseEditRequest request = creatEditRequest(); //设置自定义字段 - List list = updateCustomsFields(request); - request.setCustomsFields(list); + List list = updateCustomFields(request); + request.setCustomFields(list); LinkedMultiValueMap paramMap = new LinkedMultiValueMap<>(); List files = new ArrayList<>(); paramMap.add("request", JSON.toJSONString(request)); @@ -196,14 +197,14 @@ public class FunctionalCaseControllerTests extends BaseTest { } - private List updateCustomsFields(FunctionalCaseEditRequest editRequest) { - List list = new ArrayList<>() {{ - add(new CaseCustomsFieldDTO() {{ - setFieldId("customs_field_id_1"); + private List updateCustomFields(FunctionalCaseEditRequest editRequest) { + List list = new ArrayList<>() {{ + add(new CaseCustomFieldDTO() {{ + setFieldId("custom_field_id_1"); setValue("测试更新"); }}); - add(new CaseCustomsFieldDTO() {{ - setFieldId("customs_field_id_2"); + add(new CaseCustomFieldDTO() {{ + setFieldId("custom_field_id_2"); setValue("更新时存在新字段"); }}); }}; @@ -271,7 +272,7 @@ public class FunctionalCaseControllerTests extends BaseTest { //自定义字段 测试 Map map = new HashMap<>(); - map.put("customs", Arrays.asList(new LinkedHashMap() {{ + map.put("custom", Arrays.asList(new LinkedHashMap() {{ put("id", "TEST_FIELD_ID"); put("operator", "in"); put("value", "222"); @@ -351,4 +352,13 @@ public class FunctionalCaseControllerTests extends BaseTest { this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_COPY_URL, request); } + @Test + @Order(2) + public void testVersion() throws Exception { + MvcResult mvcResult = this.requestGetWithOkAndReturn(FUNCTIONAL_CASE_VERSION_URL + "TEST_FUNCTIONAL_CASE_ID"); + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + Assertions.assertNotNull(resultHolder); + } + } diff --git a/backend/services/case-management/src/test/resources/dml/init_file_metadata_test.sql b/backend/services/case-management/src/test/resources/dml/init_file_metadata_test.sql index 087260fc21..e05b36e454 100644 --- a/backend/services/case-management/src/test/resources/dml/init_file_metadata_test.sql +++ b/backend/services/case-management/src/test/resources/dml/init_file_metadata_test.sql @@ -23,7 +23,7 @@ INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, r VALUES ('TEST_FUNCTIONAL_CASE_ID_6', 6, 'TEST_MOUDLE_ID', '100001100001', '100001', 'copy_测试多版本', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'TEST_REF_ID_1', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL); INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) -VALUES ('TEST_FUNCTIONAL_CASE_ID_7', 7, 'TEST_MOUDLE_ID', '100001100001', '100001', 'copy_测试多版本', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'TEST_REF_ID_2', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL); +VALUES ('TEST_FUNCTIONAL_CASE_ID_7', 7, 'TEST_MOUDLE_ID', '100001100001', '100001', 'copy_long_name_11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111', 'UN_REVIEWED', NULL, 'STEP', 0, 'v3.0.0', 'TEST_REF_ID_2', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL); INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('TEST_FUNCTIONAL_CASE_ID', 'STEP', '1111', NULL, NULL, 'TEST'); INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('TEST_FUNCTIONAL_CASE_ID_1', 'STEP', '1111', NULL, NULL, '1111'); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java index e5cac3c19b..d5b8e1feb4 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java @@ -394,7 +394,7 @@ public class ProjectTemplateService extends BaseTemplateService { * @param scene * @return */ - public List getTableCustomsField(String projectId, String scene) { + public List getTableCustomField(String projectId, String scene) { TemplateExample example = new TemplateExample(); example.createCriteria().andScopeIdEqualTo(projectId).andSceneEqualTo(scene); List