build: modify test plan domain and add test plan test
This commit is contained in:
parent
37d56b3870
commit
e3714c7c7a
|
@ -46,7 +46,7 @@ public class TestPlan implements Serializable {
|
|||
@Schema(title = "创建时间")
|
||||
private Long createTime;
|
||||
|
||||
@Schema(title = "创建人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(title = "创建人")
|
||||
private String createUser;
|
||||
|
||||
@Schema(title = "更新时间")
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.validation.groups.Created;
|
|||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
@ -34,12 +35,11 @@ public class TestPlanApiCase implements Serializable {
|
|||
@Schema(title = "创建时间")
|
||||
private Long createTime;
|
||||
|
||||
@Schema(title = "创建人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(title = "创建人")
|
||||
private String createUser;
|
||||
|
||||
@Schema(title = "自定义排序,间隔5000", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan_api_case.pos.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 19, message = "{test_plan_api_case.pos.length_range}", groups = {Created.class, Updated.class})
|
||||
@NotNull(message = "{test_plan_api_case.pos.not_blank}", groups = {Created.class})
|
||||
private Long pos;
|
||||
|
||||
@Schema(title = "所属环境")
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.validation.groups.Created;
|
|||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
@ -30,8 +31,7 @@ public class TestPlanApiScenario implements Serializable {
|
|||
private String createUser;
|
||||
|
||||
@Schema(title = "自定义排序,间隔5000", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan_api_scenario.pos.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 19, message = "{test_plan_api_scenario.pos.length_range}", groups = {Created.class, Updated.class})
|
||||
@NotNull(message = "{test_plan_api_scenario.pos.not_blank}", groups = {Created.class})
|
||||
private Long pos;
|
||||
|
||||
@Schema(title = "环境类型")
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.validation.groups.Created;
|
|||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
@ -17,17 +18,14 @@ public class TestPlanConfig implements Serializable {
|
|||
|
||||
@Schema(title = "是否自定更新功能用例状态", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan_config.automatic_status_update.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 1, message = "{test_plan_config.automatic_status_update.length_range}", groups = {Created.class, Updated.class})
|
||||
private Boolean automaticStatusUpdate;
|
||||
|
||||
@Schema(title = "是否允许重复添加用例", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan_config.repeat_case.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 1, message = "{test_plan_config.repeat_case.length_range}", groups = {Created.class, Updated.class})
|
||||
private Boolean repeatCase;
|
||||
|
||||
@Schema(title = "测试计划通过阈值;0-100", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan_config.pass_threshold.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 10, message = "{test_plan_config.pass_threshold.length_range}", groups = {Created.class, Updated.class})
|
||||
@NotNull(message = "{test_plan_config.pass_threshold.not_blank}", groups = {Created.class})
|
||||
private Integer passThreshold;
|
||||
|
||||
@Schema(title = "运行模式", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.validation.groups.Created;
|
|||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
@ -28,12 +29,11 @@ public class TestPlanFunctionCase implements Serializable {
|
|||
@Schema(title = "创建时间")
|
||||
private Long createTime;
|
||||
|
||||
@Schema(title = "创建人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(title = "创建人")
|
||||
private String createUser;
|
||||
|
||||
@Schema(title = "自定义排序,间隔5000", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan_function_case.pos.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 19, message = "{test_plan_function_case.pos.length_range}", groups = {Created.class, Updated.class})
|
||||
@NotNull(message = "{test_plan_function_case.pos.not_blank}", groups = {Created.class})
|
||||
private Long pos;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class TestPlanFunctionCaseResult implements Serializable {
|
|||
@Size(min = 1, max = 50, message = "{test_plan_function_case_result.result.length_range}", groups = {Created.class, Updated.class})
|
||||
private String result;
|
||||
|
||||
@Schema(title = "创建人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(title = "创建人")
|
||||
private String createUser;
|
||||
|
||||
@Schema(title = "创建时间")
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.validation.groups.Created;
|
|||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
@ -28,15 +29,14 @@ public class TestPlanLoadCase implements Serializable {
|
|||
@Schema(title = "创建时间")
|
||||
private Long createTime;
|
||||
|
||||
@Schema(title = "创建人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(title = "创建人")
|
||||
private String createUser;
|
||||
|
||||
@Schema(title = "所用测试资源池ID")
|
||||
private String testResourcePoolId;
|
||||
|
||||
@Schema(title = "自定义排序,间隔5000", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan_load_case.pos.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 19, message = "{test_plan_load_case.pos.length_range}", groups = {Created.class, Updated.class})
|
||||
@NotNull(message = "{test_plan_load_case.pos.not_blank}", groups = {Created.class})
|
||||
private Long pos;
|
||||
|
||||
@Schema(title = "压力配置")
|
||||
|
|
|
@ -25,7 +25,7 @@ public class TestPlanReport implements Serializable {
|
|||
@Size(min = 1, max = 255, message = "{test_plan_report.name.length_range}", groups = {Created.class, Updated.class})
|
||||
private String name;
|
||||
|
||||
@Schema(title = "创建人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(title = "创建人")
|
||||
private String createUser;
|
||||
|
||||
@Schema(title = "创建时间")
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.validation.groups.Created;
|
|||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
@ -25,15 +26,14 @@ public class TestPlanUiScenario implements Serializable {
|
|||
@Size(min = 1, max = 50, message = "{test_plan_ui_scenario.ui_scenario_id.length_range}", groups = {Created.class, Updated.class})
|
||||
private String uiScenarioId;
|
||||
|
||||
@Schema(title = "创建人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(title = "创建人")
|
||||
private String createUser;
|
||||
|
||||
@Schema(title = "创建时间")
|
||||
private Long createTime;
|
||||
|
||||
@Schema(title = "排序,默认值5000", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{test_plan_ui_scenario.pos.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 19, message = "{test_plan_ui_scenario.pos.length_range}", groups = {Created.class, Updated.class})
|
||||
@NotNull(message = "{test_plan_ui_scenario.pos.not_blank}", groups = {Created.class})
|
||||
private Long pos;
|
||||
|
||||
@Schema(title = "环境类型")
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package io.metersphere.plan.controller;
|
||||
|
||||
import io.metersphere.plan.dto.TestPlanApiCaseDTO;
|
||||
import io.metersphere.plan.service.TestPlanApiCaseService;
|
||||
import io.metersphere.validation.groups.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/test-plan/api/case")
|
||||
public class TestPlanApiCaseController {
|
||||
|
||||
@Resource
|
||||
private TestPlanApiCaseService testPlanApiCaseService;
|
||||
|
||||
@PostMapping("/add")
|
||||
public void add(@Validated({Created.class}) @RequestBody TestPlanApiCaseDTO testPlanApiCaseDTO) {
|
||||
testPlanApiCaseService.add(testPlanApiCaseDTO);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
public void update(@Validated({Updated.class}) @RequestBody TestPlanApiCaseDTO testPlanApiCaseDTO) {
|
||||
testPlanApiCaseService.update(testPlanApiCaseDTO);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public int delete(@PathVariable String id) {
|
||||
return testPlanApiCaseService.delete(id);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public TestPlanApiCaseDTO get(@PathVariable String id) {
|
||||
return testPlanApiCaseService.get(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package io.metersphere.plan.dto;
|
||||
|
||||
import io.metersphere.plan.domain.TestPlanApiCase;
|
||||
|
||||
public class TestPlanApiCaseDTO extends TestPlanApiCase {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package io.metersphere.plan.service;
|
||||
|
||||
import io.metersphere.plan.domain.TestPlanApiCase;
|
||||
import io.metersphere.plan.domain.TestPlanApiCaseExample;
|
||||
import io.metersphere.plan.dto.TestPlanApiCaseDTO;
|
||||
import io.metersphere.plan.mapper.TestPlanApiCaseMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class TestPlanApiCaseService {
|
||||
|
||||
@Resource
|
||||
TestPlanApiCaseMapper testPlanApiCaseMapper;
|
||||
|
||||
public void add(TestPlanApiCaseDTO testPlanApiCaseDTO) {
|
||||
TestPlanApiCase testPlanApiCase = new TestPlanApiCase();
|
||||
BeanUtils.copyBean(testPlanApiCase, testPlanApiCaseDTO);
|
||||
testPlanApiCase.setCreateTime(System.currentTimeMillis());
|
||||
testPlanApiCase.setCreateUser("admin");
|
||||
testPlanApiCaseMapper.insert(testPlanApiCase);
|
||||
}
|
||||
|
||||
public void update(TestPlanApiCaseDTO testPlanApiCaseDTO) {
|
||||
TestPlanApiCase testPlanApiCase = new TestPlanApiCase();
|
||||
BeanUtils.copyBean(testPlanApiCase, testPlanApiCaseDTO);
|
||||
testPlanApiCaseMapper.updateByPrimaryKeySelective(testPlanApiCase);
|
||||
}
|
||||
|
||||
public int delete(String id) {
|
||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||
example.createCriteria().andIdEqualTo(id);
|
||||
return testPlanApiCaseMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public TestPlanApiCaseDTO get(String id) {
|
||||
TestPlanApiCaseDTO testPlanApiCaseDTO = new TestPlanApiCaseDTO();
|
||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseMapper.selectByPrimaryKey(id);
|
||||
if (testPlanApiCase == null) {
|
||||
return null;
|
||||
}
|
||||
BeanUtils.copyBean(testPlanApiCaseDTO, testPlanApiCase);
|
||||
return testPlanApiCaseDTO;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package io.metersphere.plan.controller;
|
||||
|
||||
import io.metersphere.plan.dto.TestPlanApiCaseDTO;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
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.MockMvc;
|
||||
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 java.util.UUID;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@Sql(scripts = {"/ddl/test_plan_api_case.sql"},
|
||||
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public class TestPlanApiCaseControllerTests {
|
||||
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
|
||||
public static final String REQ_PREFIX = "/test-plan/api/case";
|
||||
|
||||
public static final String PARAM_TEST_ID = "test-plan-api-case-id";
|
||||
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void testAdd() throws Exception {
|
||||
TestPlanApiCaseDTO testPlanApiCaseDTO = new TestPlanApiCaseDTO();
|
||||
testPlanApiCaseDTO.setId(UUID.randomUUID().toString());
|
||||
testPlanApiCaseDTO.setTestPlanId(UUID.randomUUID().toString());
|
||||
testPlanApiCaseDTO.setApiCaseId(UUID.randomUUID().toString());
|
||||
testPlanApiCaseDTO.setPos(10001L);
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(REQ_PREFIX + "/add")
|
||||
.content(JSON.toJSONString(testPlanApiCaseDTO))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(MockMvcResultHandlers.print());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
public void testGet() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(REQ_PREFIX + "/get/" + PARAM_TEST_ID))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(MockMvcResultHandlers.print());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void testUpdate() throws Exception {
|
||||
TestPlanApiCaseDTO testPlanApiCaseDTO = new TestPlanApiCaseDTO();
|
||||
testPlanApiCaseDTO.setId(PARAM_TEST_ID);
|
||||
testPlanApiCaseDTO.setPos(15001L);
|
||||
mockMvc.perform(MockMvcRequestBuilders.put(REQ_PREFIX + "/update")
|
||||
.content(JSON.toJSONString(testPlanApiCaseDTO))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(MockMvcResultHandlers.print());
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(REQ_PREFIX + "/get/" + PARAM_TEST_ID))
|
||||
.andExpect(status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$.data.pos").value(15001L))
|
||||
.andDo(MockMvcResultHandlers.print());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void testDelete() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.delete(REQ_PREFIX + "/delete/" + PARAM_TEST_ID))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(MockMvcResultHandlers.print());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
DROP TABLE IF EXISTS test_plan_api_case;
|
||||
CREATE TABLE test_plan_api_case(
|
||||
`id` VARCHAR(50) NOT NULL COMMENT 'ID' ,
|
||||
`test_plan_id` VARCHAR(50) NOT NULL COMMENT '测试计划ID' ,
|
||||
`api_case_id` VARCHAR(50) NOT NULL COMMENT '接口用例ID' ,
|
||||
`environment_type` VARCHAR(20) COMMENT '环境类型' ,
|
||||
`environment` LONGTEXT COMMENT '所属环境' ,
|
||||
`environment_group_id` VARCHAR(50) COMMENT '环境组ID' ,
|
||||
`create_time` BIGINT NOT NULL COMMENT '创建时间' ,
|
||||
`create_user` VARCHAR(40) NOT NULL COMMENT '创建人' ,
|
||||
`pos` BIGINT NOT NULL COMMENT '自定义排序,间隔5000' ,
|
||||
PRIMARY KEY (id)
|
||||
) COMMENT = '测试计划关联接口用例';
|
||||
|
||||
INSERT INTO test_plan_api_case value ('test-plan-api-case-id', UUID(), UUID(), null, null, null, CURRENT_TIMESTAMP, 'admin', 1);
|
Loading…
Reference in New Issue