diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/junitgenerator-prj-settings.xml b/.idea/junitgenerator-prj-settings.xml new file mode 100644 index 0000000..a43fc3d --- /dev/null +++ b/.idea/junitgenerator-prj-settings.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/case-server/pom.xml b/case-server/pom.xml index 72a95d0..0d2a95f 100644 --- a/case-server/pom.xml +++ b/case-server/pom.xml @@ -198,6 +198,24 @@ spring-test + + junit + junit + 4.12 + test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + diff --git a/case-server/src/main/java/com/xiaoju/framework/controller/DirController.java b/case-server/src/main/java/com/xiaoju/framework/controller/DirController.java index 1a94a2e..4116959 100644 --- a/case-server/src/main/java/com/xiaoju/framework/controller/DirController.java +++ b/case-server/src/main/java/com/xiaoju/framework/controller/DirController.java @@ -118,6 +118,10 @@ public Response getDirCardTree(@RequestParam @NotNull(message = "业务线id @RequestParam @NotNull(message = "渠道为空") Integer channel) { return Response.success(dirService.getDirTree(productLineId, channel)); } + + @GetMapping("/getId") + public String getId(String parentId, Long productLineId, Integer channel, String text) { + return dirService.getId(parentId, productLineId, channel, text); /** * 移动文件夹,会文件夹下及其子文件夹全部移动 diff --git a/case-server/src/main/java/com/xiaoju/framework/controller/UserController.java b/case-server/src/main/java/com/xiaoju/framework/controller/UserController.java index 468519d..6dd6450 100644 --- a/case-server/src/main/java/com/xiaoju/framework/controller/UserController.java +++ b/case-server/src/main/java/com/xiaoju/framework/controller/UserController.java @@ -49,4 +49,9 @@ public Response login(@RequestBody UserLoginReq req, HttpServletRequest reque public Response logout(HttpServletRequest request,HttpServletResponse response) { return Response.success(userService.logout(request, response)); } + + @PostMapping("/logoff") + public Response logoff(String Username) { + return Response.success(userService.logoff(Username)); + } } diff --git a/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirCreateReq.java b/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirCreateReq.java index b4f5d5a..75fc277 100644 --- a/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirCreateReq.java +++ b/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirCreateReq.java @@ -3,6 +3,7 @@ import com.xiaoju.framework.entity.request.ParamValidate; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import org.springframework.util.StringUtils; /** @@ -12,6 +13,7 @@ * @date 2020/9/11 */ @Data +@NoArgsConstructor @AllArgsConstructor public class DirCreateReq implements ParamValidate { diff --git a/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirDeleteReq.java b/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirDeleteReq.java index 169ec69..6bfb528 100644 --- a/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirDeleteReq.java +++ b/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirDeleteReq.java @@ -4,6 +4,7 @@ import com.xiaoju.framework.entity.request.ParamValidate; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import org.springframework.util.StringUtils; /** @@ -13,6 +14,7 @@ * @date 2020/9/11 */ @Data +@NoArgsConstructor @AllArgsConstructor public class DirDeleteReq implements ParamValidate { diff --git a/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirRenameReq.java b/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirRenameReq.java index 29cccbe..78e7897 100644 --- a/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirRenameReq.java +++ b/case-server/src/main/java/com/xiaoju/framework/entity/request/dir/DirRenameReq.java @@ -3,6 +3,7 @@ import com.xiaoju.framework.entity.request.ParamValidate; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import org.springframework.util.StringUtils; import static com.xiaoju.framework.constants.BizConstant.UNSORTED_BIZ_ID; @@ -14,6 +15,7 @@ * @date 2020/9/11 */ @Data +@NoArgsConstructor @AllArgsConstructor public class DirRenameReq implements ParamValidate { diff --git a/case-server/src/main/java/com/xiaoju/framework/mapper/UserMapper.java b/case-server/src/main/java/com/xiaoju/framework/mapper/UserMapper.java index ec2178e..46615a4 100644 --- a/case-server/src/main/java/com/xiaoju/framework/mapper/UserMapper.java +++ b/case-server/src/main/java/com/xiaoju/framework/mapper/UserMapper.java @@ -16,4 +16,6 @@ public interface UserMapper { int updateByPrimaryKeySelective(User record); int updateByPrimaryKey(User record); + + int deleteByUserName(String username); } \ No newline at end of file diff --git a/case-server/src/main/java/com/xiaoju/framework/service/DirService.java b/case-server/src/main/java/com/xiaoju/framework/service/DirService.java index 424d008..759a462 100644 --- a/case-server/src/main/java/com/xiaoju/framework/service/DirService.java +++ b/case-server/src/main/java/com/xiaoju/framework/service/DirService.java @@ -25,6 +25,9 @@ public interface DirService { */ DirNodeDto addDir(DirCreateReq request); + + // 通过其他三个信息找到delid值 + String getId(String parentId, Long productLineId, Integer channel, String text); /** * 重命名文件夹 * diff --git a/case-server/src/main/java/com/xiaoju/framework/service/UserService.java b/case-server/src/main/java/com/xiaoju/framework/service/UserService.java index b906a16..b992f1d 100644 --- a/case-server/src/main/java/com/xiaoju/framework/service/UserService.java +++ b/case-server/src/main/java/com/xiaoju/framework/service/UserService.java @@ -14,6 +14,7 @@ public interface UserService { Integer register(UserRegisterReq req, HttpServletRequest request, HttpServletResponse response); Integer login(UserLoginReq req, HttpServletRequest request, HttpServletResponse response); Integer logout(HttpServletRequest request, HttpServletResponse response); + Integer logoff(String Username); /** * 获取用户对应权限的路径匹配列表 diff --git a/case-server/src/main/java/com/xiaoju/framework/service/impl/DirServiceImpl.java b/case-server/src/main/java/com/xiaoju/framework/service/impl/DirServiceImpl.java index 6377331..f19fbf2 100644 --- a/case-server/src/main/java/com/xiaoju/framework/service/impl/DirServiceImpl.java +++ b/case-server/src/main/java/com/xiaoju/framework/service/impl/DirServiceImpl.java @@ -61,6 +61,23 @@ public DirNodeDto addDir(DirCreateReq request) { return root; } + + @Override + public String getId(String parentId, Long productLineId, Integer channel, String text){ + DirNodeDto root = getDirTree(productLineId, channel); + DirNodeDto dir = getDir(parentId, root); + if(dir == null) + return null; + Iterator iterator = dir.getChildren().iterator(); + while (iterator.hasNext()) { + DirNodeDto next = iterator.next(); + if (text.equals(next.getText())) { + return next.getId(); + } + } + return null; + } + @Override @Transactional(rollbackFor = Exception.class) public DirNodeDto renameDir(DirRenameReq request) { diff --git a/case-server/src/main/java/com/xiaoju/framework/service/impl/FileServiceImpl.java b/case-server/src/main/java/com/xiaoju/framework/service/impl/FileServiceImpl.java index d3b5997..d18030f 100644 --- a/case-server/src/main/java/com/xiaoju/framework/service/impl/FileServiceImpl.java +++ b/case-server/src/main/java/com/xiaoju/framework/service/impl/FileServiceImpl.java @@ -480,8 +480,10 @@ public CaseCreateReq buildCaseByXml(FileImportReq request, String fileName, Http JSONArray jsonArray = new JSONArray(); String fileXml = "content.xml"; -// String picXml = "attachments"; // 存放图片的文件夹 -// String picName = (fileName + picXml).replace("/", File.separator); + String picXml1 = "attachments"; + String picXml2 = "resources"; + String picName1 = (fileName + picXml1).replace("/", File.separator); + String picName2 = (fileName + picXml2).replace("/", File.separator); String contentFullName = (fileName + fileXml).replace("/", File.separator); File file = new File(contentFullName); if(!file.exists()) // 判断文件是否存在 @@ -494,7 +496,7 @@ public CaseCreateReq buildCaseByXml(FileImportReq request, String fileName, Http String eleName = childElement.getName(); if(eleName.equalsIgnoreCase("sheet")) { - jsonArray = TreeUtil.importDataByXml(request, childElement, fileName, requests, uploadPath); + jsonArray = TreeUtil.importDataByXml(request, childElement, picName1, picName2, requests, uploadPath); } return buildCaseCreateReq(request, jsonArray); } diff --git a/case-server/src/main/java/com/xiaoju/framework/service/impl/UserServiceImpl.java b/case-server/src/main/java/com/xiaoju/framework/service/impl/UserServiceImpl.java index 5a63e62..652ecca 100644 --- a/case-server/src/main/java/com/xiaoju/framework/service/impl/UserServiceImpl.java +++ b/case-server/src/main/java/com/xiaoju/framework/service/impl/UserServiceImpl.java @@ -140,6 +140,11 @@ public Integer logout(HttpServletRequest request, HttpServletResponse response) } @Override + public Integer logoff(String username){ + // 4.注销该用户 + return userMapper.deleteByUserName(username); + } + public List getUserAuthorityContent(String username) { User user = userMapper.selectByUserName(username); if (Objects.isNull(user)) { diff --git a/case-server/src/main/java/com/xiaoju/framework/util/TreeUtil.java b/case-server/src/main/java/com/xiaoju/framework/util/TreeUtil.java index e4f417a..9077c5f 100644 --- a/case-server/src/main/java/com/xiaoju/framework/util/TreeUtil.java +++ b/case-server/src/main/java/com/xiaoju/framework/util/TreeUtil.java @@ -498,7 +498,7 @@ public static void importDataByJson(JSONArray children, JSONObject rootTopic, St //导入xml内容 - public static JSONArray importDataByXml(FileImportReq request, Element e, String fileName, HttpServletRequest requests, String uploadPath) throws IOException { + public static JSONArray importDataByXml(FileImportReq request, Element e, String fileName1, String fileName2, HttpServletRequest requests, String uploadPath) throws IOException { JSONArray jsonArray = new JSONArray(); List elementList = e.elements(); if(elementList.size() == 0) @@ -527,6 +527,14 @@ public static JSONArray importDataByXml(FileImportReq request, Element e, String String path = element.attributeValue("src"); // 将文件传入到temp文件下,因此需要将文件进行转换,将file文件类型转化为MultipartFile类型,然后进行上传 + File file = null; + File file1 = new File(fileName1 + "/" + path.split("/")[1]); + File file2 = new File(fileName2 + "/" + path.split("/")[1]); + if(file1.exists()) + file = file1; + else + file = file2; + LOGGER.info("file为:" + file); File file = new File(fileName + path.split(":")[1]); try { if (StringUtils.isEmpty(element.attributeValue("width")) || StringUtils.isEmpty(element.attributeValue("height"))) { @@ -569,7 +577,7 @@ else if (element.getName().equalsIgnoreCase("title")) { { if(childEle.getName().equalsIgnoreCase("topics")) { - JSONArray jsonArray1 = importDataByXml(request, childEle, fileName, requests, uploadPath); + JSONArray jsonArray1 = importDataByXml(request, childEle, fileName1, fileName2, requests, uploadPath); if(jsonArray1.size()>0){ childrenNext.addAll(jsonArray1); } @@ -597,22 +605,22 @@ else if (element.getName().equalsIgnoreCase("title")) { } - //根据xml文件获取优先级 - private static Integer getPriorityByElement(Element element) - { - Integer priorityId = 0; - Map priorityIds = getAllPriority(); - List markers = element.elements(); - if (markers != null && markers.size() > 0) { - for (Element mark : markers) { - String markId = mark.attributeValue("marker-id"); - if (priorityIds.containsKey(markId)) { - priorityId = priorityIds.get(markId); - } - } - } - return priorityId; - } + //根据xml文件获取优先级 + private static Integer getPriorityByElement(Element element) + { + Integer priorityId = 0; + Map priorityIds = getAllPriority(); + List markers = element.elements(); + if (markers != null && markers.size() > 0) { + for (Element mark : markers) { + String markId = mark.attributeValue("marker-id"); + if (priorityIds.containsKey(markId)) { + priorityId = priorityIds.get(markId); + } + } + } + return priorityId; + } //根据content.json文件获取优先级 private static Integer getPriorityByJsonArray(JSONArray markers) @@ -656,17 +664,17 @@ private static String getPriorityByJson(JSONObject jsonObject) } //获取所有优先级 - private static Map getAllPriority(){ - Map priorityIds = new HashMap<>(); - priorityIds.put("priority-1", 1); - priorityIds.put("priority-2", 2); - priorityIds.put("priority-3", 3); - priorityIds.put("priority-4", 3); - priorityIds.put("priority-5", 3); - priorityIds.put("priority-6", 3); - priorityIds.put("priority-7", 3); - priorityIds.put("priority-8", 3); - priorityIds.put("priority-9", 3); - return priorityIds; - } + private static Map getAllPriority(){ + Map priorityIds = new HashMap<>(); + priorityIds.put("priority-1", 1); + priorityIds.put("priority-2", 2); + priorityIds.put("priority-3", 3); + priorityIds.put("priority-4", 3); + priorityIds.put("priority-5", 3); + priorityIds.put("priority-6", 3); + priorityIds.put("priority-7", 3); + priorityIds.put("priority-8", 3); + priorityIds.put("priority-9", 3); + return priorityIds; + } } diff --git a/case-server/src/main/resources/com/xiaoju/framework/mapper/UserMapper.xml b/case-server/src/main/resources/com/xiaoju/framework/mapper/UserMapper.xml index 752e9c0..1976f8e 100644 --- a/case-server/src/main/resources/com/xiaoju/framework/mapper/UserMapper.xml +++ b/case-server/src/main/resources/com/xiaoju/framework/mapper/UserMapper.xml @@ -32,6 +32,10 @@ delete from user where id = #{id,jdbcType=BIGINT} + + delete from user + where username = #{id,jdbcType=VARCHAR} + insert into user (id, username, password, salt, authority_name, is_delete, channel, diff --git a/case-server/src/test/java/com/xiaoju/framework/BackupControllerTests.java b/case-server/src/test/java/com/xiaoju/framework/BackupControllerTests.java new file mode 100644 index 0000000..93be41a --- /dev/null +++ b/case-server/src/test/java/com/xiaoju/framework/BackupControllerTests.java @@ -0,0 +1,114 @@ +package com.xiaoju.framework; + +import com.alibaba.fastjson.JSONObject; +import com.xiaoju.framework.controller.BackupController; +import com.xiaoju.framework.controller.UploadController; +import com.xiaoju.framework.entity.persistent.CaseBackup; +import lombok.extern.slf4j.Slf4j; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +import java.util.Date; + + +/** + * Created by yimfeng on 2021/11/22. + */ +public class BackupControllerTests extends CaseServerTest { + @Autowired + private BackupController backupController; + + private MockMvc mockMvc; + + @Before + public void setup() { + mockMvc = MockMvcBuilders.standaloneSetup(backupController).build(); + } + + @Test + public void exportTest1() throws Exception { + + // 测试add接口 post方法 + CaseBackup caseBackup = new CaseBackup(); + caseBackup.setId(1635L); + caseBackup.setCaseId(2654L); + caseBackup.setCreator("yimfeng"); + caseBackup.setCaseContent("{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"中心主题\"},\"children\":[{\"data\":{\"id\":\"cg9k2vx2cr40\",\"created\":1638929669164,\"text\":\"111\"},\"children\":[]}]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":3,\"right\":1}"); + caseBackup.setTitle("离开自动保存用例"); + caseBackup.setExtra(""); + caseBackup.setGmtCreated(new Date()); + caseBackup.setIsDelete(0); + caseBackup.setRecordContent(""); + + MvcResult mvcResultadd = mockMvc.perform(MockMvcRequestBuilders.post("/api/backup/add") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(caseBackup))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentAdd = mvcResultadd.getResponse().getContentAsString(); + JSONObject jsonAdd = JSONObject.parseObject(contentAdd); + System.out.println("data的内容为 : " + jsonAdd.getString("data")); + + // 测试getBackupByCaseId接口 get方法 + MvcResult mvcResultGet = mockMvc.perform(MockMvcRequestBuilders.get("/api/backup/getBackupByCaseId") + .accept(MediaType.APPLICATION_JSON).param("caseId", "2637") + .accept(MediaType.APPLICATION_JSON).param("beginTime", "1635696000000") + .accept(MediaType.APPLICATION_JSON).param("endTime", "2638374399999")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentGet = mvcResultGet.getResponse().getContentAsString(); + JSONObject jsonGet = JSONObject.parseObject(contentGet); + System.out.println("data的内容为 : " + jsonGet.getString("data")); + + // 测试getCaseDiff接口 get方法 + MvcResult mvcResultDiff = mockMvc.perform(MockMvcRequestBuilders.get("/api/backup/getCaseDiff") + .accept(MediaType.APPLICATION_JSON).param("caseId1", "1606") + .accept(MediaType.APPLICATION_JSON).param("caseId2", "1608")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentDiff = mvcResultDiff.getResponse().getContentAsString(); + JSONObject jsonDiff = JSONObject.parseObject(contentDiff); + System.out.println("data的内容为 : " + jsonDiff.getString("data")); + + + // 测试deleteByCaseId接口 get方法 + MvcResult mvcResultDelete = mockMvc.perform(MockMvcRequestBuilders.get("/api/backup/deleteByCaseId") + .accept(MediaType.APPLICATION_JSON).param("caseId", "2637")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentDelete = mvcResultDelete.getResponse().getContentAsString(); + JSONObject jsonDelete = JSONObject.parseObject(contentDelete); + System.out.println("data的内容为 : " + jsonDelete.getString("data")); + + } + +} diff --git a/case-server/src/test/java/com/xiaoju/framework/CaseControllerTests.java b/case-server/src/test/java/com/xiaoju/framework/CaseControllerTests.java new file mode 100644 index 0000000..9afabed --- /dev/null +++ b/case-server/src/test/java/com/xiaoju/framework/CaseControllerTests.java @@ -0,0 +1,191 @@ +package com.xiaoju.framework; + +import com.alibaba.fastjson.JSONObject; +import com.xiaoju.framework.controller.CaseController; +import com.xiaoju.framework.entity.request.cases.CaseCreateReq; +import com.xiaoju.framework.entity.request.cases.CaseDeleteReq; +import com.xiaoju.framework.entity.request.cases.CaseEditReq; +import com.xiaoju.framework.entity.request.ws.WsSaveReq; +import org.assertj.core.api.Assertions; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + + +/** + * Created by yimfeng on 2021/11/22. + */ +public class CaseControllerTests extends CaseServerTest { + @Autowired + private CaseController caseController; + private MockMvc mockMvc; + + @Before + public void setup() { + mockMvc = MockMvcBuilders.standaloneSetup(caseController).build(); + } + + @Test + public void exportTest1() throws Exception { + + // 测试list接口 put方法 + MvcResult mvcResultList = mockMvc.perform(MockMvcRequestBuilders.get("/api/case/list") + .accept(MediaType.APPLICATION_JSON).param("channel", "1") + .accept(MediaType.APPLICATION_JSON).param("productLineId", "1") + .accept(MediaType.APPLICATION_JSON).param("bizId", "-1") + .accept(MediaType.APPLICATION_JSON).param("title", "done测试") + .accept(MediaType.APPLICATION_JSON).param("creator", "yimfeng") + .accept(MediaType.APPLICATION_JSON).param("requirementId", "") + .accept(MediaType.APPLICATION_JSON).param("beginTime", "111") + .accept(MediaType.APPLICATION_JSON).param("endTime", "222") + .accept(MediaType.APPLICATION_JSON).param("pageNum", "1") + .accept(MediaType.APPLICATION_JSON).param("pageSize", "10")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentList = mvcResultList.getResponse().getContentAsString(); + JSONObject jsonList = JSONObject.parseObject(contentList); + System.out.println("data中的内容为 : " + jsonList.getString("data")); + + + // 测试create接口 post方法 + CaseCreateReq caseCreateReq = new CaseCreateReq(); + caseCreateReq.setCreator("yimfeng"); + caseCreateReq.setProductLineId(1L); + caseCreateReq.setCaseType(0); + caseCreateReq.setCaseContent("{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"中心主题\"},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":0}"); + caseCreateReq.setTitle("copy of done测试"); + caseCreateReq.setChannel(1); + caseCreateReq.setBizId("-1"); + caseCreateReq.setId(2483L); + caseCreateReq.setRequirementId("111"); + caseCreateReq.setDescription("这是个测试"); + + MvcResult mvcResultCreate = mockMvc.perform(MockMvcRequestBuilders.post("/api/case/create") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(caseCreateReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentCreate = mvcResultCreate.getResponse().getContentAsString(); + JSONObject jsonCreate = JSONObject.parseObject(contentCreate); + System.out.println("data中的内容为 : " + jsonCreate.getString("data")); + + Long id = Long.valueOf(jsonCreate.getString("data")); + + // 测试edit接口 post方法 + CaseEditReq caseEditReq = new CaseEditReq(); + caseEditReq.setId(id); + caseEditReq.setCaseType(0); + caseEditReq.setTitle("done测试"); + caseEditReq.setModifier("yimfeng"); + caseEditReq.setBizId("-1"); + caseEditReq.setChannel(1); + caseEditReq.setRequirementId("111"); + caseEditReq.setDescription("编辑用例集"); + + + MvcResult mvcResultEdit = mockMvc.perform(MockMvcRequestBuilders.post("/api/case/edit") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(caseEditReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentEdit = mvcResultEdit.getResponse().getContentAsString(); + JSONObject jsonEdit = JSONObject.parseObject(contentEdit); + System.out.println("data中的内容为 : " + jsonEdit.getString("data")); + + + // 测试delete接口 post方法 + CaseDeleteReq caseDeleteReq = new CaseDeleteReq(); + caseDeleteReq.setId(id); + MvcResult mvcResultDelete = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/case/delete") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(caseDeleteReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentDelete = mvcResultDelete.getResponse().getContentAsString(); + JSONObject jsonDelete = JSONObject.parseObject(contentDelete); + System.out.println("data中的内容为 : " + jsonDelete.getString("data")); + + + + // 测试listCreators接口 get方法 + MvcResult mvcResultCreators = mockMvc.perform(MockMvcRequestBuilders.get("/api/case/listCreators") + .accept(MediaType.APPLICATION_JSON).param("caseType", "0") + .accept(MediaType.APPLICATION_JSON).param("productLineId", "1")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentCreators = mvcResultCreators.getResponse().getContentAsString(); + JSONObject jsonCreators = JSONObject.parseObject(contentCreators); + System.out.println("data中的内容为 : " + jsonCreators.getString("data")); + + + // 测试CastInfo接口 get方法 + MvcResult mvcResultInfo = mockMvc.perform(MockMvcRequestBuilders.get("/api/case/getCaseInfo") + .accept(MediaType.APPLICATION_JSON).param("id", "2483")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentInfo = mvcResultInfo.getResponse().getContentAsString(); + JSONObject jsonInfo = JSONObject.parseObject(contentInfo); + System.out.println("data中的内容为 : " + jsonInfo.getString("data")); + + + // 测试update接口 post方法 + WsSaveReq wsSaveReq = new WsSaveReq(); + wsSaveReq.setId(id); + wsSaveReq.setCaseContent("{\"root\":{\"data\":{\"created\":1562059643204,\"id\":\"bv8nxhi3c800\",\"text\":\"中心主题\"},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":1}"); + wsSaveReq.setModifier("yimfeng"); + wsSaveReq.setRecordId(null); + MvcResult mvcResultUpdate = mockMvc.perform(MockMvcRequestBuilders.post("/api/case/update") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(wsSaveReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentUpdate = mvcResultUpdate.getResponse().getContentAsString(); + JSONObject jsonUpdate = JSONObject.parseObject(contentUpdate); + System.out.println("data中的内容为 : " + jsonUpdate.getString("data")); + } + +} diff --git a/case-server/src/test/java/com/xiaoju/framework/CaseEditTest.java b/case-server/src/test/java/com/xiaoju/framework/CaseEditTest.java new file mode 100644 index 0000000..fce683d --- /dev/null +++ b/case-server/src/test/java/com/xiaoju/framework/CaseEditTest.java @@ -0,0 +1,339 @@ +package com.xiaoju.framework; + +import com.alibaba.fastjson.JSONObject; +import com.xiaoju.framework.controller.CaseController; +import com.xiaoju.framework.entity.request.ws.WsSaveReq; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import javax.websocket.Session; +import javax.websocket.WebSocketContainer; +import java.net.URI; +import java.util.Queue; +import java.util.concurrent.TimeUnit; + +/** + * Created by didi on 2021/11/22. + */ +@ClientEndpoint +public class CaseEditTest extends CaseServerTest { + private final String url = "ws://127.0.0.1:8094/api/case/2237/undefined/0/yimfeng"; + @Autowired + private CaseController caseController; + private MockMvc mockMvc; + + @Before + public void setup() { + mockMvc = MockMvcBuilders.standaloneSetup(caseController).build(); + } + + @Test + public void PingPongTest() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try { + do { + session.getBasicRemote().sendText("0pong pong pong"); // 发送pong信号 + Thread.sleep(5000); + } while(true) ; + } catch (Exception e) { + e.printStackTrace(); + } + } + + // 编辑测试.测试场景包括(新增节点|删除节点|编辑内容|添加备注|添加图片|添加优先级|添加tag|添加link|undo|redo) + // 所有编辑操作成对出现.确保内容恢复 + + // 新增节点 + @Test + public void addMessage() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + // 添加数据 + String caseContent1 = "1{\"case\": {\"root\": {\"data\": {\"id\": \"bv8nxhi3c800\",\"created\": 1562059643204,\"text\": \"websocket\"},\"children\": [{\"data\": {\"id\": \"ch3l66s9zlc0\",\"created\": 1641979547721,\"text\": \"分支主题\"},\"children\": []}]},\"template\": \"default\",\"theme\": \"fresh-blue\",\"version\": \"1.4.43\",\"base\": 2,\"right\": 1},\"patch\": [[{\"op\": \"add\",\"path\": \"/root/children/0\",\"value\": {\"data\": {\"id\": \"ch3l66s9zlc0\",\"created\": 1641979547721,\"text\": \"分支主题\"},\"children\": []}}]]}"; + session.getBasicRemote().sendText(caseContent1); // 新增节点分为两步,首先创建一个分支主题 + Thread.sleep(5000); + String caseContent2 = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"websocket\"},\"children\":[{\"data\":{\"id\":\"ch3lialqzkg0\",\"created\":1641980496404,\"text\":\"新增节点\"},\"children\":[]}]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":3,\"right\":1},\"patch\":[[{\"op\":\"replace\",\"path\":\"/root/children/0/data/text\",\"value\":\"新增节点\"}]]}"; + session.getBasicRemote().sendText(caseContent2); // 修改分支主题的数据 + Thread.sleep(5000); + session.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + // 删除节点 + @Test + public void deleteMessage() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"websocket\"},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":4,\"right\":1},\"patch\":[[{\"op\":\"remove\",\"path\":\"/root/children/0\"}]]}"; // 将新增节点删除 + session.getBasicRemote().sendText(caseContent); + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + // 编辑内容 + @Test + public void editMessage() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"case\"},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":5,\"right\":1},\"patch\":[[{\"op\":\"replace\",\"path\":\"/root/data/text\",\"value\":\"case\"}]]}"; // 将websocket修改为case + session.getBasicRemote().sendText(caseContent); + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + // 添加备注 + @Test + public void addRemarks() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent1 = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"case\",\"note\":\"# test\\n\"},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":6,\"right\":1},\"patch\":[[{\"op\":\"add\",\"path\":\"/root/data/note\",\"value\":\"# test\\n\"}]]}"; + session.getBasicRemote().sendText(caseContent1); + Thread.sleep(5000); + String caseContent2 = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"case\",\"note\":\"# test\\n1111\"},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":10,\"right\":1},\"patch\":[[{\"op\":\"replace\",\"path\":\"/root/data/note\",\"value\":\"# test\\n1111\"}]]}"; + session.getBasicRemote().sendText(caseContent2); + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + // 添加图片 + @Test + public void addPicture() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"case\",\"note\":\"# test\\n1111\",\"image\":\"http://localhost:8094/2022/01/13/1511cca7-b9b0-4a54-b99e-7fe45a906dc5.png\",\"imageSize\":{\"width\":200,\"height\":142}},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":7,\"right\":1},\"patch\":[[{\"op\":\"add\",\"path\":\"/root/data/image\",\"value\":\"http://localhost:8094/2022/01/13/1511cca7-b9b0-4a54-b99e-7fe45a906dc5.png\"},{\"op\":\"add\",\"path\":\"/root/data/imageSize\",\"value\":{\"width\":200,\"height\":142}}]]}"; + session.getBasicRemote().sendText(caseContent); + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + // 添加优先级 + @Test + public void addPriority() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"case\",\"note\":\"# test\\n1111\",\"image\":\"http://localhost:8094/2022/01/13/1511cca7-b9b0-4a54-b99e-7fe45a906dc5.png\",\"imageSize\":{\"width\":200,\"height\":142},\"priority\":1},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":8,\"right\":1},\"patch\":[[{\"op\":\"replace\",\"path\":\"/root/data/priority\",\"value\":1}]]}"; + session.getBasicRemote().sendText(caseContent); + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + // 添加标签 + @Test + public void addTags() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"case\",\"note\":\"# test\\n1111\",\"image\":\"http://localhost:8094/2022/01/13/1511cca7-b9b0-4a54-b99e-7fe45a906dc5.png\",\"imageSize\":{\"width\":200,\"height\":142},\"priority\":1,\"resource\":[\"前置条件\"]},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":9,\"right\":1},\"patch\":[[{\"op\":\"add\",\"path\":\"/root/data/resource\",\"value\":[\"前置条件\"]}]]}"; + session.getBasicRemote().sendText(caseContent); + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // 添加link + @Test + public void addLink() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"case\",\"note\":\"# test\\n1111\",\"image\":\"http://localhost:8094/2022/01/13/1511cca7-b9b0-4a54-b99e-7fe45a906dc5.png\",\"imageSize\":{\"width\":200,\"height\":142},\"priority\":1,\"resource\":[\"前置条件\"],\"hyperlink\":\"www.baidu.com\"},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":10,\"right\":1},\"patch\":[[{\"op\":\"add\",\"path\":\"/root/data/hyperlink\",\"value\":\"www.baidu.com\"}]]}"; + session.getBasicRemote().sendText(caseContent); + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // undo操作 + @Test + public void undo() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent1 = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"case\"},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":5,\"right\":1},\"patch\":[[{\"op\":\"replace\",\"path\":\"/root/data/text\",\"value\":\"case\"}]]}"; // 将websocket修改为case + session.getBasicRemote().sendText(caseContent1); // 发送删除消息 + String caseContent2 = "1undo"; + Thread.sleep(5000); + session.getBasicRemote().sendText(caseContent2); // 发送undo消息 + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + // redo操作 + @Test + public void redo() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent1 = "1{\"case\":{\"root\":{\"data\":{\"id\":\"bv8nxhi3c800\",\"created\":1562059643204,\"text\":\"case\"},\"children\":[]},\"template\":\"default\",\"theme\":\"fresh-blue\",\"version\":\"1.4.43\",\"base\":5,\"right\":1},\"patch\":[[{\"op\":\"replace\",\"path\":\"/root/data/text\",\"value\":\"case\"}]]}"; // 将websocket修改为case + session.getBasicRemote().sendText(caseContent1); // 发送删除消息 + Thread.sleep(5000); + String caseContent2 = "1undo"; + session.getBasicRemote().sendText(caseContent2); // 发送undo消息 + Thread.sleep(5000); + String caseContent3 = "1redo"; + session.getBasicRemote().sendText(caseContent3); // 发送redo消息 + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + // 控制测试.测试场景包括(lock) + @Test + public void CaseControllTest() { + Session session = null; + try { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + URI uri = URI.create(url); + session = container.connectToServer(this, uri); + } catch (Exception e) { + e.printStackTrace(); + } + + try{ + String caseContent = "2lock"; + session.getBasicRemote().sendText(caseContent); + Thread.sleep(5000); + session.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/case-server/src/test/java/com/xiaoju/framework/CaseServerTest.java b/case-server/src/test/java/com/xiaoju/framework/CaseServerTest.java new file mode 100644 index 0000000..b21a2c7 --- /dev/null +++ b/case-server/src/test/java/com/xiaoju/framework/CaseServerTest.java @@ -0,0 +1,22 @@ +package com.xiaoju.framework; +import org.junit.After; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +//@WebAppConfiguration +public class CaseServerTest { + @Before + public void init() { + System.out.println("start"); + } + + @After + public void after() { + System.out.println("end"); + } +} diff --git a/case-server/src/test/java/com/xiaoju/framework/DirControllerTests.java b/case-server/src/test/java/com/xiaoju/framework/DirControllerTests.java new file mode 100644 index 0000000..12ac269 --- /dev/null +++ b/case-server/src/test/java/com/xiaoju/framework/DirControllerTests.java @@ -0,0 +1,130 @@ +package com.xiaoju.framework; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.xiaoju.framework.controller.DirController; +import com.xiaoju.framework.entity.request.dir.DirCreateReq; +import com.xiaoju.framework.entity.request.dir.DirDeleteReq; +import com.xiaoju.framework.entity.request.dir.DirRenameReq; +import com.xiaoju.framework.service.DirService; +import org.dom4j.Element; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + + +/** + * Created by yimfeng on 2021/11/22. + */ +public class DirControllerTests extends CaseServerTest { + @Autowired + private DirController dirController; + + private MockMvc mockMvc; + + @Before + public void setup() { + mockMvc = MockMvcBuilders.standaloneSetup(dirController).build(); + } + + @Test + public void exportTest1() throws Exception { + + // 测试list接口,get方法 + MvcResult mvcResultList = mockMvc.perform(MockMvcRequestBuilders.get("/api/dir/list") + .accept(MediaType.APPLICATION_JSON).param("productLineId", "1") + .accept(MediaType.APPLICATION_JSON).param("channel", "1")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentList = mvcResultList.getResponse().getContentAsString(); + JSONObject jsonList = JSONObject.parseObject(contentList); + System.out.println("data中的内容为 : " + jsonList.getString("data")); + + // 测试add接口, post方法 + DirCreateReq dirCreateReq = new DirCreateReq("root", 1L, "测试节点", 1); + + MvcResult mvcResultAdd = mockMvc.perform(MockMvcRequestBuilders.post("/api/dir/add") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(dirCreateReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentAdd = mvcResultAdd.getResponse().getContentAsString(); + JSONObject jsonAdd = JSONObject.parseObject(contentAdd); + System.out.println("data中的内容为 : " + jsonAdd.getString("data")); + + + // 通过其他信息获得id + String id = dirController.getId("root", 1L, 1, "测试节点"); + System.out.println("id的数据为:" + id); + + // 测试rename接口, post方法 + DirRenameReq dirRenameReq = new DirRenameReq(id, 1L, "1234567", 1); + + MvcResult mvcResultRename = mockMvc.perform(MockMvcRequestBuilders.post("/api/dir/rename") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(dirRenameReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + + String contentRename = mvcResultRename.getResponse().getContentAsString(); + JSONObject jsonRename = JSONObject.parseObject(contentRename); + System.out.println("data中的内容为 : " + jsonRename.getString("data")); + + + // 测试delete接口,post方法 + DirDeleteReq dirDeleteReq = new DirDeleteReq("root", 1L, id, 1); + + MvcResult mvcResultDelete = mockMvc.perform(MockMvcRequestBuilders.post("/api/dir/delete") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(dirDeleteReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + + String contentDelete = mvcResultDelete.getResponse().getContentAsString(); + JSONObject jsonDelete = JSONObject.parseObject(contentDelete); + System.out.println("data中的内容为 : " + jsonDelete.getString("data")); + + // 测试cardTree接口,get方法 + dirController.getDirTree(1L, 1); + MvcResult mvcResultDirTree = mockMvc.perform(MockMvcRequestBuilders.get("/api/dir/cardTree") + .accept(MediaType.APPLICATION_JSON).param("productLineId", "1") + .accept(MediaType.APPLICATION_JSON).param("channel", "1")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentDirTree = mvcResultDirTree.getResponse().getContentAsString(); + JSONObject jsonDirTree = JSONObject.parseObject(contentDirTree); + System.out.println("data中的内容为 : " + jsonDirTree.getString("data")); + } +} \ No newline at end of file diff --git a/case-server/src/test/java/com/xiaoju/framework/RecordControllerTests.java b/case-server/src/test/java/com/xiaoju/framework/RecordControllerTests.java new file mode 100644 index 0000000..4493834 --- /dev/null +++ b/case-server/src/test/java/com/xiaoju/framework/RecordControllerTests.java @@ -0,0 +1,155 @@ +package com.xiaoju.framework; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.xiaoju.framework.controller.RecordController; +import com.xiaoju.framework.entity.request.record.RecordAddReq; +import com.xiaoju.framework.entity.request.record.RecordDeleteReq; +import com.xiaoju.framework.entity.request.record.RecordUpdateReq; +import com.xiaoju.framework.entity.request.ws.RecordWsClearReq; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + + +/** + * Created by yimfeng on 2021/11/22. + */ +public class RecordControllerTests extends CaseServerTest { + + @Autowired + private RecordController RecordController; + + private MockMvc mockMvc; + + @Before + public void setup() { + mockMvc = MockMvcBuilders.standaloneSetup(RecordController).build(); + } + + @Test + public void exportTest1() throws Exception { + + // 测试list接口 get方法 + MvcResult mvcResultList = mockMvc.perform(MockMvcRequestBuilders.get("/api/record/list") + .accept(MediaType.APPLICATION_JSON).param("caseId", "2212")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentList = mvcResultList.getResponse().getContentAsString(); + JSONObject jsonList = JSONObject.parseObject(contentList); + System.out.println("data中的内容为 : " + jsonList.getString("data")); + + + // 测试create接口 post方法 + RecordAddReq recordAddReq = new RecordAddReq(); + recordAddReq.setCaseId(2494L); + recordAddReq.setCreator("yimfeng"); + recordAddReq.setTitle("测试record123"); + recordAddReq.setChooseContent("{\"priority\":[\"0\"],\"resource\":[]}"); + recordAddReq.setDescription("这是一个测试"); + recordAddReq.setExpectStartTime(1635696000000L); + recordAddReq.setExpectEndTime(1638374399999L); + + MvcResult mvcResultCreate = mockMvc.perform(MockMvcRequestBuilders.post("/api/record/create") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(recordAddReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) // 查看是否正常update + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentCreate = mvcResultCreate.getResponse().getContentAsString(); + JSONObject jsonCreate = JSONObject.parseObject(contentCreate); + System.out.println("data中的内容为 : " + jsonCreate.getString("data")); + + + + // 测试edit接口 post方法 + RecordUpdateReq recordUpdateReq = new RecordUpdateReq(); + recordUpdateReq.setId(967L); + recordUpdateReq.setModifier("yimfeng"); + recordUpdateReq.setOwner("yimfeng"); + recordUpdateReq.setTitle("测试record1111111"); + recordUpdateReq.setChooseContent("{\"priority\":[\"0\"],\"resource\":[]}"); + recordUpdateReq.setDescription("这是一个测试1"); + recordUpdateReq.setExpectStartTime(1635696000000L); + recordUpdateReq.setExpectEndTime(1638374399999L); + + MvcResult mvcResultEdit = mockMvc.perform(MockMvcRequestBuilders.post("/api/record/edit") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(recordUpdateReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + + // 测试delete接口 post方法 + RecordDeleteReq recordDeleteReq = new RecordDeleteReq(); + recordDeleteReq.setId(964L); + MvcResult mvcResultDelete = mockMvc.perform(MockMvcRequestBuilders.post("/api/record/delete") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(recordDeleteReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").value("删除成功")) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentDelete = mvcResultDelete.getResponse().getContentAsString(); + JSONObject jsonDelete = JSONObject.parseObject(contentDelete); + System.out.println("data中的内容为 : " + jsonDelete.getString("data")); + + + // 测试clear接口 post方法 + RecordWsClearReq recordWsClearReq = new RecordWsClearReq(); + recordWsClearReq.setId(965L); + recordWsClearReq.setModifier("yimfeng"); + MvcResult mvcResultClear = mockMvc.perform(MockMvcRequestBuilders.post("/api/record/clear") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(recordWsClearReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentClear = mvcResultClear.getResponse().getContentAsString(); + JSONObject jsonClear = JSONObject.parseObject(contentClear); + System.out.println("data中的内容为 : " + jsonClear.getString("data")); + + + // 测试getrecordInfo接口 get方法 + MvcResult mvcResultInfo = mockMvc.perform(MockMvcRequestBuilders.get("/api/record/getRecordInfo") + .accept(MediaType.APPLICATION_JSON).param("id", "966")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + String contentInfo = mvcResultInfo.getResponse().getContentAsString(); + JSONObject jsonInfo = JSONObject.parseObject(contentInfo); + System.out.println("data中的内容为 : " + jsonInfo.getString("data")); + } + +} diff --git a/case-server/src/test/java/com/xiaoju/framework/UploadControllerTests.java b/case-server/src/test/java/com/xiaoju/framework/UploadControllerTests.java new file mode 100644 index 0000000..699f57f --- /dev/null +++ b/case-server/src/test/java/com/xiaoju/framework/UploadControllerTests.java @@ -0,0 +1,92 @@ +package com.xiaoju.framework; + +import com.xiaoju.framework.controller.CaseController; +import com.xiaoju.framework.controller.UploadController; +import org.apache.http.entity.ContentType; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + + +import java.io.File; +import java.io.FileInputStream; + +/** + * Created by didi on 2021/11/19. + */ +public class UploadControllerTests extends CaseServerTest { + @Autowired + private UploadController uploadController; + private CaseController caseController; + + private MockHttpServletRequest request; + private MockHttpServletResponse response; + + private MockMvc mockMvc; + + @Before + public void setup() { + mockMvc = MockMvcBuilders.standaloneSetup(uploadController).build(); + } + + @Test + public void exportTest1() throws Exception { + request = new MockHttpServletRequest(); + request.setServerPort(8094); + request.setCharacterEncoding("utf-8"); + response = new MockHttpServletResponse(); + + // 测试import接口 post方法 + File file = new File("/Users/didi/Desktop/picture.xmind"); + MockMultipartFile multipartFile = new MockMultipartFile( + "file", // 需要对应接口中的MultipartFile file参数的名字 + "picture.xmind", // 文件的名字 + null, //文件类型 + new FileInputStream(file) //文件流 + ); + + uploadController.importXmind(multipartFile, "yimfeng", "-1", 1L, "done测试1", "测试", 1, "123", request); + + + // 测试uploadAttachment接口 post方法 + File picfile = new File("/Users/didi/Desktop/sql.png"); + MockMultipartFile picMultipartFile = new MockMultipartFile( + "file", + "sql.png", + ContentType.APPLICATION_OCTET_STREAM.toString(), //文件类型 + new FileInputStream(picfile) //文件流 + ); + + uploadController.uploadAttachment(picMultipartFile, request); + MvcResult mvcResultUpload = mockMvc.perform(MockMvcRequestBuilders.multipart("/api/file/uploadAttachment") + .file(picMultipartFile)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isNotEmpty()) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(2)) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + System.out.print(mvcResultUpload); + + + // 测试export接口 get方法 + uploadController.exportXmind(2223l, request, response); + System.out.print(response); + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/api/file/export") + .accept(MediaType.APPLICATION_JSON).param("id", "2223")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + System.out.print(mvcResult); + } +} diff --git a/case-server/src/test/java/com/xiaoju/framework/UserControllerTests.java b/case-server/src/test/java/com/xiaoju/framework/UserControllerTests.java new file mode 100644 index 0000000..7fea12b --- /dev/null +++ b/case-server/src/test/java/com/xiaoju/framework/UserControllerTests.java @@ -0,0 +1,88 @@ +package com.xiaoju.framework; + +import com.alibaba.fastjson.JSONObject; +import com.xiaoju.framework.controller.UserController; +import com.xiaoju.framework.entity.request.auth.UserLoginReq; +import com.xiaoju.framework.entity.request.auth.UserRegisterReq; +import com.xiaoju.framework.service.UserService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + + +/** + * Created by yimfeng on 2021/11/22. + */ +public class UserControllerTests extends CaseServerTest { + @Autowired + private UserController userController; + private UserService userService; + + private MockHttpServletRequest request; + private MockHttpServletResponse response; + + private MockMvc mockMvc; + + @Before + public void setup() { + mockMvc = MockMvcBuilders.standaloneSetup(userController).build(); + } + + + @Test + public void exportTest1() throws Exception { + + request = new MockHttpServletRequest(); + request.setCharacterEncoding("utf-8"); + response = new MockHttpServletResponse(); + + + // 测试register接口 post方法 + UserRegisterReq userRegisterReq = new UserRegisterReq(); + + userRegisterReq.setUsername("nimeng2"); + userRegisterReq.setPassword("123456"); + + + MvcResult mvcResultRegister = mockMvc.perform(MockMvcRequestBuilders.post("/api/user/register") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(userRegisterReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + // 测试login接口 post方法 + UserLoginReq userLoginReq = new UserLoginReq(); + userLoginReq.setUsername("nimeng2"); + userLoginReq.setPassword("123456"); + + + MvcResult mvcResultLogin = mockMvc.perform(MockMvcRequestBuilders.post("/api/user/login") + .contentType(MediaType.APPLICATION_JSON) + .content(JSONObject.toJSONString(userLoginReq))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value("200")) + .andExpect(MockMvcResultMatchers.jsonPath("$.length()").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isEmpty()) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + + + // 注销注册的用户 + userController.logoff("nimeng2"); + System.out.println("已将注册的用户从数据库中删除"); + } + +}