refactor(消息管理): 补充单元测试

This commit is contained in:
guoyuqi 2023-10-17 10:07:16 +08:00 committed by f2c-ci-robot[bot]
parent e69b0bb25a
commit d9fd9b11aa
2 changed files with 15 additions and 15 deletions

View File

@ -35,15 +35,7 @@ public class NoticeTemplateControllerTests extends BaseTest {
@Sql(scripts = {"/dml/init_project_template.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Sql(scripts = {"/dml/init_project_template.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void getTemplateFieldsSuccess() throws Exception { public void getTemplateFieldsSuccess() throws Exception {
List<String> typeList = new ArrayList<>(); List<String> typeList = new ArrayList<>();
typeList.add(NoticeConstants.TaskType.API_DEFINITION_TASK); getTypeList(typeList);
typeList.add(NoticeConstants.TaskType.API_SCENARIO_TASK);
typeList.add(NoticeConstants.TaskType.TEST_PLAN_TASK);
typeList.add(NoticeConstants.TaskType.CASE_REVIEW_TASK);
typeList.add(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK);
typeList.add(NoticeConstants.TaskType.BUG_TASK);
typeList.add(NoticeConstants.TaskType.UI_SCENARIO_TASK);
typeList.add(NoticeConstants.TaskType.LOAD_TEST_TASK);
for (String s : typeList) { for (String s : typeList) {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/template/get/fields/project-template-test-1") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/template/get/fields/project-template-test-1")
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
@ -55,17 +47,15 @@ public class NoticeTemplateControllerTests extends BaseTest {
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
MessageTemplateResultDTO messageTemplateResultDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateResultDTO.class); MessageTemplateResultDTO messageTemplateResultDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateResultDTO.class);
List<MessageTemplateFieldDTO> projectList = messageTemplateResultDTO.getFieldList(); List<MessageTemplateFieldDTO> projectList = messageTemplateResultDTO.getFieldList();
if (s.equals(NoticeConstants.TaskType.SCHEDULE_TASK)) { if (s.equals(NoticeConstants.TaskType.LOAD_REPORT_TASK)) {
Assertions.assertTrue(CollectionUtils.isEmpty(projectList)); Assertions.assertTrue(CollectionUtils.isEmpty(projectList));
} else { } else {
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList)); Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
} }
} }
} }
@Test
@Order(2) private static void getTypeList(List<String> typeList) {
public void getTemplateFieldsEmptySuccess() throws Exception {
List<String> typeList = new ArrayList<>();
typeList.add(NoticeConstants.TaskType.API_DEFINITION_TASK); typeList.add(NoticeConstants.TaskType.API_DEFINITION_TASK);
typeList.add(NoticeConstants.TaskType.API_SCENARIO_TASK); typeList.add(NoticeConstants.TaskType.API_SCENARIO_TASK);
typeList.add(NoticeConstants.TaskType.TEST_PLAN_TASK); typeList.add(NoticeConstants.TaskType.TEST_PLAN_TASK);
@ -74,6 +64,15 @@ public class NoticeTemplateControllerTests extends BaseTest {
typeList.add(NoticeConstants.TaskType.BUG_TASK); typeList.add(NoticeConstants.TaskType.BUG_TASK);
typeList.add(NoticeConstants.TaskType.UI_SCENARIO_TASK); typeList.add(NoticeConstants.TaskType.UI_SCENARIO_TASK);
typeList.add(NoticeConstants.TaskType.LOAD_TEST_TASK); typeList.add(NoticeConstants.TaskType.LOAD_TEST_TASK);
typeList.add(NoticeConstants.TaskType.JENKINS_TASK);
typeList.add(NoticeConstants.TaskType.SCHEDULE_TASK);
}
@Test
@Order(2)
public void getTemplateFieldsEmptySuccess() throws Exception {
List<String> typeList = new ArrayList<>();
getTypeList(typeList);
for (String s : typeList) { for (String s : typeList) {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/template/get/fields/project-template-test-2" ) MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/template/get/fields/project-template-test-2" )
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)

View File

@ -32,7 +32,8 @@ public class MessageTemplateUtilsTests {
Assertions.assertTrue(CollectionUtils.isNotEmpty(defaultRelatedUser)); Assertions.assertTrue(CollectionUtils.isNotEmpty(defaultRelatedUser));
Map<String, String> defaultRelatedUserMap = MessageTemplateUtils.getDefaultRelatedUserMap(); Map<String, String> defaultRelatedUserMap = MessageTemplateUtils.getDefaultRelatedUserMap();
Assertions.assertTrue(MapUtils.isNotEmpty(defaultRelatedUserMap)); Assertions.assertTrue(MapUtils.isNotEmpty(defaultRelatedUserMap));
Map<String, String> fieldSourceMap = MessageTemplateUtils.getFieldSourceMap();
Assertions.assertTrue(MapUtils.isNotEmpty(fieldSourceMap));
for (String type : typeList) { for (String type : typeList) {
Field[] domainTemplateFields = MessageTemplateUtils.getDomainTemplateFields(type); Field[] domainTemplateFields = MessageTemplateUtils.getDomainTemplateFields(type);
Assertions.assertNotNull(domainTemplateFields); Assertions.assertNotNull(domainTemplateFields);