Skip to content

Commit

Permalink
feat(测试计划): 单个计划的详情
Browse files Browse the repository at this point in the history
  • Loading branch information
WangXu10 authored and fit2-zhao committed May 8, 2024
1 parent ef1b0c5 commit a872b43
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.TestPlanCountResponse;
import io.metersphere.plan.dto.response.TestPlanDetailResponse;
import io.metersphere.plan.dto.response.TestPlanResponse;
import io.metersphere.plan.service.TestPlanLogService;
import io.metersphere.plan.service.TestPlanManagementService;
Expand Down Expand Up @@ -128,11 +129,18 @@ public void archived(@NotBlank @PathVariable String id) {

@PostMapping("/copy")
@Operation(summary = "测试计划-复制测试计划")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ADD)
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
@Log(type = OperationLogType.COPY, expression = "#msClass.copyLog(#request)", msClass = TestPlanLogService.class)
public TestPlan copy(@Validated @RequestBody TestPlanCopyRequest request) {
return testPlanService.copy(request, SessionUtils.getUserId());
}

@GetMapping("/{id}")
@Operation(summary = "测试计划-抽屉详情(单个测试计划获取详情用于编辑)")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ)
@CheckOwner(resourceId = "#id", resourceType = "test_plan")
public TestPlanDetailResponse detail(@NotBlank @PathVariable String id) {
return testPlanService.detail(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.metersphere.plan.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
* @author wx
*/
@Data
public class TestPlanDetailResponse implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

@Schema(description = "测试计划ID")
private String id;

@Schema(description = "测试计划组Id")
private String groupId;
@Schema(description = "测试计划组名称")
private String groupName;

@Schema(description = "计划开始时间")
private Long plannedStartTime;

@Schema(description = "计划结束时间")
private Long plannedEndTime;

@Schema(description = "描述;描述")
private String description;

@Schema(description = "是否自定更新功能用例状态")
private Boolean automaticStatusUpdate;

@Schema(description = "是否允许重复添加用例")
private Boolean repeatCase;

@Schema(description = "测试计划通过阈值;0-100")
private Double passThreshold;

@Schema(description = "是否开启测试规划")
private Boolean testPlanning;


@Schema(description = "测试计划名称/测试计划组名称")
private String name;
@Schema(description = "标签")
private List<String> tags;
@Schema(description = "模块")
private String moduleName;
@Schema(description = "模块Id")
private String moduleId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.metersphere.plan.dto.request.TestPlanCreateRequest;
import io.metersphere.plan.dto.request.TestPlanUpdateRequest;
import io.metersphere.plan.dto.response.TestPlanCountResponse;
import io.metersphere.plan.dto.response.TestPlanDetailResponse;
import io.metersphere.plan.mapper.ExtTestPlanMapper;
import io.metersphere.plan.mapper.TestPlanConfigMapper;
import io.metersphere.plan.mapper.TestPlanFollowerMapper;
Expand All @@ -19,6 +20,7 @@
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.TestPlanModule;
import io.metersphere.system.domain.TestPlanModuleExample;
import io.metersphere.system.mapper.TestPlanModuleMapper;
import io.metersphere.system.uid.IDGenerator;
Expand Down Expand Up @@ -477,4 +479,47 @@ private void doHandleAssociateCase(List<String> ids, TestPlan testPlan) {
//TODO 复制关联接口用例/接口场景用例

}


/**
* 获取单个测试计划或测试计划组详情(用于编辑)
*
* @param id
* @return
*/
public TestPlanDetailResponse detail(String id) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(id);
TestPlanDetailResponse response = new TestPlanDetailResponse();
TestPlanModule testPlanModule = testPlanModuleMapper.selectByPrimaryKey(testPlan.getModuleId());
//计划组只有几个参数
response.setName(testPlan.getName());
response.setTags(testPlan.getTags());
response.setModuleId(testPlan.getModuleId());
response.setModuleName(testPlanModule.getName());
response.setDescription(testPlan.getDescription());
if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_PLAN)) {
//计划的 其他参数
getGroupName(response, testPlan);
response.setPlannedStartTime(testPlan.getPlannedStartTime());
response.setPlannedEndTime(testPlan.getPlannedEndTime());
getOtherConfig(response, testPlan);
}
return response;
}

private void getOtherConfig(TestPlanDetailResponse response, TestPlan testPlan) {
TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(testPlan.getId());
response.setAutomaticStatusUpdate(testPlanConfig.getAutomaticStatusUpdate());
response.setRepeatCase(testPlanConfig.getRepeatCase());
response.setPassThreshold(testPlanConfig.getPassThreshold());
response.setTestPlanning(testPlanConfig.getTestPlanning());
}

private void getGroupName(TestPlanDetailResponse response, TestPlan testPlan) {
if (!StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) {
TestPlan group = testPlanMapper.selectByPrimaryKey(testPlan.getGroupId());
response.setGroupId(testPlan.getGroupId());
response.setGroupName(group.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class TestPlanTests extends BaseTest {
private static final String URL_TEST_PLAN_EDIT_FOLLOWER = "/test-plan/edit/follower";
private static final String URL_TEST_PLAN_ARCHIVED = "/test-plan/archived/%s";
private static final String URL_TEST_PLAN_COPY = "/test-plan/copy";
private static final String URL_TEST_PLAN_DETAIL = "/test-plan/%s";

private static String groupTestPlanId7 = null;
private static String groupTestPlanId15 = null;
Expand Down Expand Up @@ -2152,4 +2153,29 @@ public void testCopy() throws Exception {
}


@Test
@Order(303)
public void testDetail() throws Exception {
//计划
MvcResult mvcResult = this.requestGetWithOkAndReturn(String.format(URL_TEST_PLAN_DETAIL, "wx_test_plan_id_1"));
String returnStr = mvcResult.getResponse().getContentAsString();
ResultHolder holder = JSON.parseObject(returnStr, ResultHolder.class);
String returnId = holder.getData().toString();
Assertions.assertNotNull(returnId);

//计划组
MvcResult mvcResult1 = this.requestGetWithOkAndReturn(String.format(URL_TEST_PLAN_DETAIL, "wx_test_plan_id_2"));
String returnStr1 = mvcResult1.getResponse().getContentAsString();
ResultHolder holder1 = JSON.parseObject(returnStr1, ResultHolder.class);
String returnId1 = holder1.getData().toString();
Assertions.assertNotNull(returnId1);

//计划
MvcResult mvcResult2 = this.requestGetWithOkAndReturn(String.format(URL_TEST_PLAN_DETAIL, "wx_test_plan_id_4"));
String returnStr2 = mvcResult2.getResponse().getContentAsString();
ResultHolder holder2 = JSON.parseObject(returnStr2, ResultHolder.class);
String returnId2 = holder2.getData().toString();
Assertions.assertNotNull(returnId2);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ VALUES

INSERT INTO `test_plan_functional_case`(`id`, `num`, `test_plan_id`, `functional_case_id`, `create_time`, `create_user`, `execute_user`, `last_exec_time`, `last_exec_result`, `pos`)
VALUES ('wx_tpfc_1', 5000, 'wx_test_plan_id_4', 'wx_fc_1', 1714980158000, 'admin', NULL, NULL, NULL, 1);


INSERT INTO `test_plan_module`(`id`, `project_id`, `name`, `parent_id`, `pos`, `create_time`, `update_time`, `create_user`, `update_user`)
VALUES
('1', '123', 'wx_测试模块名称', 'ROOT', 1, 1714980158000, 1714980158000, 'admin', 'admin');


INSERT INTO `test_plan_config`(`test_plan_id`, `automatic_status_update`, `repeat_case`, `pass_threshold`, `test_planning`)
VALUES
('wx_test_plan_id_1', b'0', b'0', 100, b'0'),
('wx_test_plan_id_4', b'0', b'0', 100, b'0');

0 comments on commit a872b43

Please sign in to comment.