feat(功能用例): 新增功能用例详情查看评审评论

This commit is contained in:
guoyuqi 2023-12-22 18:55:31 +08:00 committed by f2c-ci-robot[bot]
parent db7363b458
commit 8d87368469
15 changed files with 180 additions and 87 deletions

View File

@ -2,6 +2,7 @@ package io.metersphere.functional.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.functional.dto.CaseReviewHistoryDTO;
import io.metersphere.functional.dto.FunctionalCaseReviewDTO;
import io.metersphere.functional.request.FunctionalCaseReviewListRequest;
import io.metersphere.functional.service.FunctionalCaseReviewService;
@ -13,14 +14,11 @@ 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 org.springframework.web.bind.annotation.*;
import java.util.List;
@Tag(name = "用例管理-功能用例-用例评审")
@Tag(name = "用例管理-功能用例-评审")
@RestController
@RequestMapping("/functional/case/review")
public class FunctionalCaseReviewController {
@ -29,11 +27,18 @@ public class FunctionalCaseReviewController {
private FunctionalCaseReviewService functionalCaseReviewService;
@PostMapping("/page")
@Operation(summary = "用例管理-功能用例-用例评审-列表")
@Operation(summary = "用例管理-功能用例-评审-列表")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ)
public Pager<List<FunctionalCaseReviewDTO>> getFunctionalCasePage(@Validated @RequestBody FunctionalCaseReviewListRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), "update_time desc");
return PageUtils.setPageInfo(page, functionalCaseReviewService.getFunctionalCaseReviewPage(request));
}
@GetMapping("/comment/{caseId}")
@Operation(summary = "用例管理-功能用例-评审-评论")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ)
public List<CaseReviewHistoryDTO> getCaseReviewHistory(@PathVariable String caseId) {
return functionalCaseReviewService.getCaseReviewHistory(caseId);
}
}

View File

@ -19,10 +19,6 @@ public interface ExtCaseReviewFunctionalCaseMapper {
void updateStatus(@Param("caseId") String caseId, @Param("reviewId") String reviewId, @Param("status") String status);
Long getUnCompletedCaseCount(@Param("reviewId") String reviewId, @Param("statusList") List<String> statusList);
Long getUnCompletedCaseCountExcludes(@Param("reviewId") String reviewId, @Param("statusList") List<String> statusList, @Param("ids") List<String> ids);
List<String> getCaseIdsByReviewId(@Param("reviewId") String reviewId);
List<ReviewFunctionalCaseDTO> page(@Param("request") ReviewFunctionalCasePageRequest request, @Param("deleted") boolean deleted, @Param("userId") String userId, @Param("sort") String sort);

View File

@ -16,34 +16,6 @@
</if>
</select>
<select id="getUnCompletedCaseCount" resultType="java.lang.Long">
SELECT
count(1)
FROM
case_review_functional_case
where review_id = #{reviewId}
and status in
<foreach collection="statusList" item="status" open="(" separator="," close=")">
#{status}
</foreach>
</select>
<select id="getUnCompletedCaseCountExcludes" resultType="java.lang.Long">
SELECT
count(1)
FROM
case_review_functional_case
where review_id = #{reviewId}
and status in
<foreach collection="statusList" item="status" open="(" separator="," close=")">
#{status}
</foreach>
and id not in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<update id="updateStatus">
update case_review_functional_case
set status = #{status},

View File

@ -12,4 +12,6 @@ public interface ExtCaseReviewHistoryMapper {
List<CaseReviewHistoryDTO> list(@Param("caseId") String caseId, @Param("reviewId") String reviewId);
void updateDelete(@Param("caseIds") List<String> caseIds, @Param("reviewId") String reviewId, @Param("delete") boolean delete);
}

View File

@ -18,9 +18,24 @@
case_review_history ch
left join user u on ch.create_user = u.id
left join user_extend ux on ch.create_user = ux.id
where ch.case_id = #{caseId} and ch.review_id = #{reviewId}
where ch.case_id = #{caseId}
<if test="reviewId != null and reviewId != ''">
and ch.review_id = #{reviewId}
</if>
</select>
<update id="updateDelete">
update case_review_history
set deleted = #{delete}
where review_id = #{reviewId}
<if test="caseIds != null and caseIds.size() > 0">
and case_id in
<foreach collection="caseIds" item="caseId" separator="," open="(" close=")">
#{caseId}
</foreach>
</if>
</update>
</mapper>

View File

@ -4,10 +4,7 @@ import io.metersphere.functional.constants.CaseEvent;
import io.metersphere.functional.constants.CaseReviewStatus;
import io.metersphere.functional.constants.FunctionalCaseReviewStatus;
import io.metersphere.functional.domain.*;
import io.metersphere.functional.mapper.CaseReviewFunctionalCaseMapper;
import io.metersphere.functional.mapper.CaseReviewFunctionalCaseUserMapper;
import io.metersphere.functional.mapper.CaseReviewMapper;
import io.metersphere.functional.mapper.ExtCaseReviewFunctionalCaseMapper;
import io.metersphere.functional.mapper.*;
import io.metersphere.functional.service.ReviewSendNoticeService;
import io.metersphere.provider.BaseCaseProvider;
import io.metersphere.sdk.util.JSON;
@ -39,6 +36,8 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
private ReviewSendNoticeService reviewSendNoticeService;
@Resource
private ExtCaseReviewFunctionalCaseMapper extCaseReviewFunctionalCaseMapper;
@Resource
private ExtCaseReviewHistoryMapper extCaseReviewHistoryMapper;
@Async
@Override
@ -95,6 +94,8 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
updateCaseReview(reviewId, caseReview.getCaseCount() - caseCount, passNumber, unCompletedCaseList.size(), paramMap.get(CaseEvent.Param.USER_ID).toString());
//删除用例和用例评审人的关系
deleteCaseReviewFunctionalCaseUser(paramMap);
//将评审历史状态置为true
extCaseReviewHistoryMapper.updateDelete(caseIdList,reviewId,true);
}
/**
@ -116,6 +117,8 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
updateCaseReview(reviewId, oldCaseCount - caseIdList.size(), passNumber, unCompletedCount, paramMap.get(CaseEvent.Param.USER_ID).toString());
//删除用例和用例评审人的关系
deleteCaseReviewFunctionalCaseUser(paramMap);
//将评审历史状态置为true
extCaseReviewHistoryMapper.updateDelete(caseIdList,reviewId,true);
}
/**
@ -267,7 +270,7 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
}
/**
* 重新计算用例评审的通过率和用例数
* 重新计算用例评审的通过率和用例数以及评审状态
*/
private void updateCaseReview(String reviewId, int caseCount, int passNumber, int unCompleteCount, String userId) {
CaseReview caseReview = new CaseReview();

View File

@ -147,9 +147,9 @@ public class CaseReviewFunctionalCaseService {
statusList.add(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString());
statusList.add(FunctionalCaseReviewStatus.RE_REVIEWED.toString());
List<CaseReviewFunctionalCase> unCompletedCaseList = caseReviewFunctionalCases.stream().filter(t -> !ids.contains(t.getId()) && statusList.contains(t.getStatus())).toList();
List<String> list = caseReviewFunctionalCases.stream().filter(t -> ids.contains(t.getId())).map(CaseReviewFunctionalCase::getCaseId).toList();
Map<String, Object> param = new HashMap<>();
param.put(CaseEvent.Param.CASE_COUNT, ids.size());
param.put(CaseEvent.Param.CASE_IDS, list.size());
param.put(CaseEvent.Param.REVIEW_ID, reviewId);
param.put(CaseEvent.Param.PASS_COUNT, passList.size());
param.put(CaseEvent.Param.UN_COMPLETED_COUNT, unCompletedCaseList.size());
@ -274,7 +274,7 @@ public class CaseReviewFunctionalCaseService {
List<CaseReviewFunctionalCase> caseReviewFunctionalCaseList = doCaseReviewFunctionalCases(request);
List<String> caseIds = caseReviewFunctionalCaseList.stream().map(CaseReviewFunctionalCase::getCaseId).toList();
CaseReviewHistoryExample caseReviewHistoryExample = new CaseReviewHistoryExample();
caseReviewHistoryExample.createCriteria().andCaseIdIn(caseIds).andReviewIdEqualTo(reviewId);
caseReviewHistoryExample.createCriteria().andCaseIdIn(caseIds).andReviewIdEqualTo(reviewId).andDeletedEqualTo(false);
List<CaseReviewHistory> caseReviewHistories = caseReviewHistoryMapper.selectByExample(caseReviewHistoryExample);
Map<String, List<CaseReviewHistory>> caseHistoryMap = caseReviewHistories.stream().collect(Collectors.groupingBy(CaseReviewHistory::getCaseId, Collectors.toList()));
@ -295,6 +295,8 @@ public class CaseReviewFunctionalCaseService {
List<CaseReviewHistory> histories = new ArrayList<>();
histories.add(caseReviewHistory);
caseHistoryMap.put(caseId, histories);
} else {
caseHistoryMap.get(caseId).add(caseReviewHistory);
}
//根据评审规则更新用例评审和功能用例关系表中的状态 1.单人评审直接更新评审结果 2.多人评审需要计算
setStatus(request, caseReviewFunctionalCase, caseHistoryMap, reviewerMap);
@ -334,24 +336,26 @@ public class CaseReviewFunctionalCaseService {
List<CaseReviewHistory> caseReviewHistoriesExp = caseHistoryMap.get(caseReviewFunctionalCase.getCaseId());
Map<String, List<CaseReviewHistory>> hasReviewedUserMap = caseReviewHistoriesExp.stream().sorted(Comparator.comparingLong(CaseReviewHistory::getCreateTime).reversed()).collect(Collectors.groupingBy(CaseReviewHistory::getCreateUser, Collectors.toList()));
List<CaseReviewFunctionalCaseUser> caseReviewFunctionalCaseUsersExp = reviewerMap.get(caseReviewFunctionalCase.getCaseId());
if (caseReviewFunctionalCaseUsersExp != null && caseReviewFunctionalCaseUsersExp.size() > hasReviewedUserMap.size()) {
AtomicInteger passCount = new AtomicInteger();
AtomicInteger unPassCount = new AtomicInteger();
hasReviewedUserMap.forEach((k, v) -> {
if (StringUtils.equalsIgnoreCase(v.get(0).getStatus(), FunctionalCaseReviewStatus.PASS.toString())) {
passCount.set(passCount.get() + 1);
}
if (StringUtils.equalsIgnoreCase(v.get(0).getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) {
unPassCount.set(unPassCount.get() + 1);
}
});
if (unPassCount.get() > 0) {
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString());
} else if (caseReviewFunctionalCaseUsersExp != null && caseReviewFunctionalCaseUsersExp.size() > hasReviewedUserMap.size()) {
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString());
} else {
AtomicInteger passCount = new AtomicInteger();
hasReviewedUserMap.forEach((k, v) -> {
if (StringUtils.equalsIgnoreCase(v.get(0).getStatus(), FunctionalCaseReviewStatus.PASS.toString())) {
passCount.set(passCount.get() + 1);
}
});
if (StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) {
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString());
//检查是否全部是通过全是才是PASS,否则是评审中
if (passCount.get() == hasReviewedUserMap.size()) {
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.PASS.toString());
} else {
//检查是否全部是通过全是才是PASS,否则是评审中
if (passCount.get() == hasReviewedUserMap.size()) {
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.PASS.toString());
} else {
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString());
}
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString());
}
}
}

View File

@ -79,6 +79,8 @@ public class CaseReviewService {
private ExtFunctionalCaseMapper extFunctionalCaseMapper;
@Resource
private BaseCaseProvider provider;
@Resource
private ExtCaseReviewHistoryMapper extCaseReviewHistoryMapper;
private static final String CASE_MODULE_COUNT_ALL = "all";
@ -467,9 +469,9 @@ public class CaseReviewService {
Map<String, Object> param = new HashMap<>();
param.put(CaseEvent.Param.USER_ID, userId);
param.put(CaseEvent.Param.REVIEW_ID, caseReviewId);
param.put(CaseEvent.Param.CASE_IDS,castIds);
param.put(CaseEvent.Param.CASE_COUNT,caseRealIds.size());
param.put(CaseEvent.Param.EVENT_NAME,CaseEvent.Event.ASSOCIATE);
param.put(CaseEvent.Param.CASE_IDS, castIds);
param.put(CaseEvent.Param.CASE_COUNT, caseRealIds.size());
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.ASSOCIATE);
provider.updateCaseReview(param);
}
@ -550,7 +552,8 @@ public class CaseReviewService {
public void deleteCaseReview(String reviewId, String projectId) {
deleteCaseReviewService.deleteCaseReviewResource(List.of(reviewId), projectId, false);
//将评审历史状态置为true
extCaseReviewHistoryMapper.updateDelete(new ArrayList<>(), reviewId, true);
}
public void disassociate(String reviewId, String caseId, String userId) {
@ -563,7 +566,7 @@ public class CaseReviewService {
param.put(CaseEvent.Param.REVIEW_ID, reviewId);
param.put(CaseEvent.Param.CASE_IDS, List.of(caseId));
param.put(CaseEvent.Param.USER_ID, userId);
param.put(CaseEvent.Param.EVENT_NAME,CaseEvent.Event.DISASSOCIATE);
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.DISASSOCIATE);
provider.updateCaseReview(param);
}

View File

@ -1,13 +1,18 @@
package io.metersphere.functional.service;
import io.metersphere.functional.dto.CaseReviewHistoryDTO;
import io.metersphere.functional.dto.FunctionalCaseReviewDTO;
import io.metersphere.functional.mapper.ExtCaseReviewFunctionalCaseMapper;
import io.metersphere.functional.mapper.ExtCaseReviewHistoryMapper;
import io.metersphere.functional.request.FunctionalCaseReviewListRequest;
import io.metersphere.sdk.util.Translator;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.nio.charset.StandardCharsets;
import java.util.List;
@ -23,7 +28,23 @@ public class FunctionalCaseReviewService {
@Resource
private ExtCaseReviewFunctionalCaseMapper extCaseReviewFunctionalCaseMapper;
@Resource
private ExtCaseReviewHistoryMapper extCaseReviewHistoryMapper;
public List<FunctionalCaseReviewDTO> getFunctionalCaseReviewPage(FunctionalCaseReviewListRequest request) {
return extCaseReviewFunctionalCaseMapper.list(request);
}
public List<CaseReviewHistoryDTO> getCaseReviewHistory(String caseId) {
List<CaseReviewHistoryDTO> list = extCaseReviewHistoryMapper.list(caseId, null);
for (CaseReviewHistoryDTO caseReviewHistoryDTO : list) {
if (StringUtils.equalsIgnoreCase(caseReviewHistoryDTO.getCreateUser(), "system")) {
caseReviewHistoryDTO.setUserName(Translator.get("case_review_history.system"));
}
if (caseReviewHistoryDTO.getContent() != null) {
caseReviewHistoryDTO.setContentText(new String(caseReviewHistoryDTO.getContent(), StandardCharsets.UTF_8));
}
}
return list;
}
}

View File

@ -56,7 +56,7 @@ public class ReviewFunctionalCaseService {
String caseId = request.getCaseId();
CaseReviewHistory caseReviewHistory = buildReviewHistory(request, userId);
CaseReviewHistoryExample caseReviewHistoryExample = new CaseReviewHistoryExample();
caseReviewHistoryExample.createCriteria().andCaseIdEqualTo(request.getCaseId()).andReviewIdEqualTo(request.getReviewId());
caseReviewHistoryExample.createCriteria().andCaseIdEqualTo(request.getCaseId()).andReviewIdEqualTo(request.getReviewId()).andDeletedEqualTo(false);
List<CaseReviewHistory> caseReviewHistories = caseReviewHistoryMapper.selectByExample(caseReviewHistoryExample);
Map<String, List<CaseReviewHistory>> hasReviewedUserMap = caseReviewHistories.stream().sorted(Comparator.comparingLong(CaseReviewHistory::getCreateTime).reversed()).collect(Collectors.groupingBy(CaseReviewHistory::getCreateUser, Collectors.toList()));
if (hasReviewedUserMap.get(userId) ==null) {
@ -77,7 +77,6 @@ public class ReviewFunctionalCaseService {
//发送评审通过不通过通知评审中不发
if (StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) {
reviewSendNoticeService.sendNoticeCase(new ArrayList<>(), userId, caseId, NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.REVIEW_FAIL, reviewId);
}
if (StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.PASS.toString())) {
reviewSendNoticeService.sendNoticeCase(new ArrayList<>(), userId, caseId, NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.REVIEW_PASSED, reviewId);
@ -107,24 +106,26 @@ public class ReviewFunctionalCaseService {
CaseReviewFunctionalCaseUserExample caseReviewFunctionalCaseUserExample = new CaseReviewFunctionalCaseUserExample();
caseReviewFunctionalCaseUserExample.createCriteria().andReviewIdEqualTo(request.getReviewId()).andCaseIdEqualTo(request.getCaseId());
long reviewerNum = caseReviewFunctionalCaseUserMapper.countByExample(caseReviewFunctionalCaseUserExample);
if ((int) reviewerNum > hasReviewedUserMap.size()) {
AtomicInteger passCount = new AtomicInteger();
AtomicInteger unPassCount = new AtomicInteger();
hasReviewedUserMap.forEach((k, v) -> {
if (StringUtils.equalsIgnoreCase(v.get(0).getStatus(), FunctionalCaseReviewStatus.PASS.toString())) {
passCount.set(passCount.get() + 1);
}
if (StringUtils.equalsIgnoreCase(v.get(0).getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) {
unPassCount.set(unPassCount.get() + 1);
}
});
if (unPassCount.get()>0) {
functionalCaseStatus = FunctionalCaseReviewStatus.UN_PASS.toString();
} else if ((int) reviewerNum > hasReviewedUserMap.size()) {
functionalCaseStatus = FunctionalCaseReviewStatus.UNDER_REVIEWED.toString();
} else {
AtomicInteger passCount = new AtomicInteger();
hasReviewedUserMap.forEach((k, v) -> {
if (StringUtils.equalsIgnoreCase(v.get(0).getStatus(), FunctionalCaseReviewStatus.PASS.toString())) {
passCount.set(passCount.get() + 1);
}
});
if (StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) {
functionalCaseStatus = FunctionalCaseReviewStatus.UN_PASS.toString();
//检查是否全部是通过全是才是PASS,否则是评审中
if (passCount.get() == hasReviewedUserMap.size()) {
functionalCaseStatus = FunctionalCaseReviewStatus.PASS.toString();
} else {
//检查是否全部是通过全是才是PASS,否则是评审中
if (passCount.get() == hasReviewedUserMap.size()) {
functionalCaseStatus = FunctionalCaseReviewStatus.PASS.toString();
} else {
functionalCaseStatus = FunctionalCaseReviewStatus.UNDER_REVIEWED.toString();
}
functionalCaseStatus = FunctionalCaseReviewStatus.UNDER_REVIEWED.toString();
}
}
}

View File

@ -4,7 +4,9 @@ import io.metersphere.functional.constants.CaseReviewPassRule;
import io.metersphere.functional.constants.FunctionalCaseReviewStatus;
import io.metersphere.functional.domain.CaseReviewFunctionalCase;
import io.metersphere.functional.domain.CaseReviewFunctionalCaseExample;
import io.metersphere.functional.domain.CaseReviewFunctionalCaseUser;
import io.metersphere.functional.mapper.CaseReviewFunctionalCaseMapper;
import io.metersphere.functional.mapper.CaseReviewFunctionalCaseUserMapper;
import io.metersphere.functional.request.*;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
@ -45,6 +47,9 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest {
@Resource
private CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper;
@Resource
private CaseReviewFunctionalCaseUserMapper caseReviewFunctionalCaseUserMapper;
@Test
@Order(1)
public void testGetCaseIds() throws Exception {
@ -179,6 +184,14 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest {
@Test
@Order(7)
public void testBatchReview() throws Exception {
List<CaseReviewFunctionalCase> caseReviewList = getCaseReviewFunctionalCase("wx_review_id_1");
List<CaseReviewFunctionalCase> list = caseReviewList.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getCreateUser(), "admin")).toList();
CaseReviewFunctionalCaseUser caseReviewFunctionalCaseUser = new CaseReviewFunctionalCaseUser();
caseReviewFunctionalCaseUser.setReviewId("wx_review_id_1");
caseReviewFunctionalCaseUser.setCaseId(list.get(0).getCaseId());
caseReviewFunctionalCaseUser.setUserId("admin");
caseReviewFunctionalCaseUserMapper.insertSelective(caseReviewFunctionalCaseUser);
BatchReviewFunctionalCaseRequest request = new BatchReviewFunctionalCaseRequest();
request.setReviewId("wx_review_id_1");
request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString());
@ -189,7 +202,7 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest {
request = new BatchReviewFunctionalCaseRequest();
request.setReviewId("wx_review_id_1");
request.setReviewPassRule(CaseReviewPassRule.SINGLE.toString());
request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString());
request.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString());
request.setSelectAll(true);
List<String>excludeIds = new ArrayList<>();

View File

@ -1,21 +1,33 @@
package io.metersphere.functional.controller;
import io.metersphere.functional.constants.FunctionalCaseReviewStatus;
import io.metersphere.functional.domain.CaseReviewHistory;
import io.metersphere.functional.dto.CaseReviewHistoryDTO;
import io.metersphere.functional.dto.FunctionalCaseReviewDTO;
import io.metersphere.functional.mapper.CaseReviewHistoryMapper;
import io.metersphere.functional.request.FunctionalCaseReviewListRequest;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
@ -23,6 +35,11 @@ public class FunctionalCaseReviewControllerTests extends BaseTest {
private static final String URL_CASE_REVIEW_PAGE = "/functional/case/review/page";
private static final String URL_CASE_REVIEW_COMMENT = "/functional/case/review/comment/";
@Resource
private CaseReviewHistoryMapper caseReviewHistoryMapper;
@Test
@Order(1)
@Sql(scripts = {"/dml/init_case_review_functional_case.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
@ -45,5 +62,43 @@ public class FunctionalCaseReviewControllerTests extends BaseTest {
System.out.println(jsonString);
}
@Test
@Order(2)
public void getCaseReviewHistory() throws Exception {
CaseReviewHistory caseReviewHistory = new CaseReviewHistory();
caseReviewHistory.setReviewId("用例关系名称1");
caseReviewHistory.setCaseId("gyqReviewCaseTest");
caseReviewHistory.setCreateUser("system");
caseReviewHistory.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.toString());
caseReviewHistory.setId("test");
String content = "你好评论";
caseReviewHistory.setContent(content.getBytes());
caseReviewHistory.setCreateTime(System.currentTimeMillis());
caseReviewHistoryMapper.insertSelective(caseReviewHistory);
List<CaseReviewHistoryDTO> gyqReviewCaseTest = getCaseReviewHistoryList("gyqReviewCaseTest");
Assertions.assertTrue(StringUtils.isNotBlank(gyqReviewCaseTest.get(0).getContentText()));
caseReviewHistory = new CaseReviewHistory();
caseReviewHistory.setReviewId("用例关系名称2");
caseReviewHistory.setCaseId("gyqReviewCaseTest");
caseReviewHistory.setCreateUser("admin");
caseReviewHistory.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.toString());
caseReviewHistory.setId("testNoContent");
caseReviewHistory.setCreateTime(System.currentTimeMillis());
caseReviewHistoryMapper.insertSelective(caseReviewHistory);
gyqReviewCaseTest = getCaseReviewHistoryList("gyqReviewCaseTest");
Assertions.assertTrue(gyqReviewCaseTest.size()>1);
}
public List<CaseReviewHistoryDTO> getCaseReviewHistoryList(String caseId) throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(URL_CASE_REVIEW_COMMENT + caseId).header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.header(SessionConstants.CURRENT_PROJECT, DEFAULT_PROJECT_ID)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
return JSON.parseArray(JSON.toJSONString(resultHolder.getData()), CaseReviewHistoryDTO.class);
}
}

View File

@ -223,7 +223,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest {
caseReviewHistory.setCaseId("gyqReviewCaseTest");
caseReviewHistory.setCreateUser("system");
caseReviewHistory.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.toString());
caseReviewHistory.setId("test");
caseReviewHistory.setId("testList");
caseReviewHistory.setCreateTime(System.currentTimeMillis());
caseReviewHistoryMapper.insertSelective(caseReviewHistory);
List<CaseReviewHistoryDTO> gyqReviewCaseTest = getCaseReviewHistoryList("gyqReviewCaseTest", reviewId);

View File

@ -15,3 +15,6 @@ VALUES ('associate_id1', 'case_review_associate_Id', 'associate_case_gyq_id', 'P

View File

@ -36,7 +36,7 @@ VALUES ('wx_test_1', 'wx_review_id_1', 'wx_case_id_1', 'PASS', 1698058347559,'ad
INSERT INTO case_review_functional_case_user(case_id, review_id, user_id)
VALUES ('wx_case_id_1', 'wx_review_id_1', 'admin'),
('wx_case_id_1', 'wx_review_id_1', 'gyq'),
('gyq_case_id_3', 'wx_review_id_1', 'gyq'),
('gyq_case_id_3', 'wx_review_id_1', 'gyq2'),
('gyq_case_id_4', 'wx_review_id_1', 'gyq');