build: issue test demo

This commit is contained in:
chenjianxing 2023-06-01 12:03:14 +08:00 committed by jianxing
parent 805682d92b
commit fa0d4e079b
9 changed files with 326 additions and 77 deletions

View File

@ -1,5 +1,23 @@
-- set innodb lock wait timeout -- set innodb lock wait timeout
SET SESSION innodb_lock_wait_timeout = 7200; SET SESSION innodb_lock_wait_timeout = 7200;
CREATE TABLE IF NOT EXISTS issue(
`id` VARCHAR(50) NOT NULL COMMENT 'ID' ,
`num` INT NOT NULL COMMENT '业务ID' ,
`title` VARCHAR(300) NOT NULL COMMENT '缺陷标题' ,
`create_time` BIGINT NOT NULL COMMENT '创建时间' ,
`update_time` BIGINT NOT NULL COMMENT '更新时间' ,
`platform` VARCHAR(50) NOT NULL COMMENT '缺陷平台' ,
`project_id` VARCHAR(50) NOT NULL COMMENT '项目ID' ,
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人' ,
`source_id` VARCHAR(50) COMMENT '缺陷来源记录创建该缺陷的测试计划的ID' ,
`platform_status` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '第三方平台状态' ,
`platform_id` VARCHAR(50) COMMENT '第三方平台缺陷ID' ,
PRIMARY KEY (id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = '缺陷';
-- set innodb lock wait timeout to default -- set innodb lock wait timeout to default
SET SESSION innodb_lock_wait_timeout = DEFAULT; SET SESSION innodb_lock_wait_timeout = DEFAULT;

View File

@ -55,12 +55,12 @@ public class RestControllerExceptionHandler {
} }
if (errorCode instanceof MsHttpResultCode) { if (errorCode instanceof MsHttpResultCode) {
// 如果是 MsHttpResultCode, 则设置响应的状态码 // 如果是 MsHttpResultCode则设置响应的状态码取状态码的后三位
return ResponseEntity.status(errorCode.getCode() % 1000) // 取状态码的后三位 return ResponseEntity.status(errorCode.getCode() % 1000)
.body(new ResultHolder(errorCode.getCode(), errorCode.getMessage(), e.getMessage())); .body(new ResultHolder(errorCode.getCode(), errorCode.getMessage(), e.getMessage()));
} else { } else {
// 业务错误返回 200以及业务状态码 // 响应码返回 500设置业务状态码
return ResponseEntity.ok() return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new ResultHolder(errorCode.getCode(), errorCode.getMessage(), e.getMessage())); .body(new ResultHolder(errorCode.getCode(), errorCode.getMessage(), e.getMessage()));
} }
} }

View File

@ -0,0 +1,48 @@
package io.metersphere.issue.controller;
import io.metersphere.issue.domain.Issue;
import io.metersphere.issue.service.IssueService;
import io.metersphere.validation.groups.Created;
import io.swagger.annotations.Api;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author : jianxing
* @date : 2023-5-17
*/
@Api(tags = "缺陷")
@RestController
@RequestMapping("/issue")
public class IssueController {
@Resource
private IssueService issueService;
@GetMapping("/list-all")
public List<Issue> listAll() {
return issueService.list();
}
@GetMapping("/get/{id}")
public Issue get(@PathVariable String id) {
return issueService.get(id);
}
@PostMapping("/add")
public Issue add(@Validated({Created.class}) @RequestBody Issue issue) {
return issueService.add(issue);
}
@PostMapping("/update")
public Issue update(@Validated({Created.class}) @RequestBody Issue issue) {
return issueService.update(issue);
}
@GetMapping("/delete/{id}")
public int delete(@PathVariable String id) {
return issueService.delete(id);
}
}

View File

@ -1,72 +0,0 @@
package io.metersphere.track.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class TestCase implements Serializable {
private String id;
private String nodeId;
private String testId;
private String nodePath;
private String projectId;
private String name;
private String type;
private String maintainer;
private String priority;
private String method;
private Long createTime;
private Long updateTime;
private Integer sort;
private Integer num;
private String reviewStatus;
private String tags;
private String demandId;
private String demandName;
private String status;
private String stepModel;
private String customNum;
private String createUser;
private String originalStatus;
private Long deleteTime;
private String deleteUserId;
private Long order;
private Boolean casePublic;
private String versionId;
private String refId;
private Boolean latest;
private String lastExecuteResult;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,58 @@
package io.metersphere.issue.service;
import io.metersphere.issue.controller.result.IssueResultCode;
import io.metersphere.issue.domain.Issue;
import io.metersphere.issue.domain.IssueExample;
import io.metersphere.issue.mapper.IssueMapper;
import io.metersphere.sdk.exception.MSException;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* @author jianxing
* @date : 2023-5-17
*/
@Service
@Transactional
public class IssueService {
@Resource
private IssueMapper issueMapper;
public List<Issue> list() {
return new ArrayList<>();
}
public Issue get(String id) {
return issueMapper.selectByPrimaryKey(id);
}
public Issue add(Issue issue) {
IssueExample example = new IssueExample();
example.createCriteria().andTitleEqualTo(issue.getTitle());
example.createCriteria().andProjectIdEqualTo(issue.getProjectId());
List<Issue> issues = issueMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(issues)) {
MSException.throwException(IssueResultCode.ISSUE_EXIST_EXCEPTION);
}
issue.setCreateTime(System.currentTimeMillis());
issue.setUpdateTime(System.currentTimeMillis());
issueMapper.insert(issue);
return issue;
}
public Issue update(Issue issue) {
issueMapper.updateByPrimaryKeySelective(issue);
return issue;
}
public int delete(String id) {
return issueMapper.deleteByPrimaryKey(id);
}
}

View File

@ -0,0 +1,22 @@
package io.metersphere.issue;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration;
import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication(exclude = {
QuartzAutoConfiguration.class,
LdapAutoConfiguration.class,
Neo4jAutoConfiguration.class
})
@ServletComponentScan
@ComponentScan(basePackages = {"io.metersphere.sdk", "io.metersphere.issue"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,79 @@
package io.metersphere.issue.controller;
import io.metersphere.issue.domain.Issue;
import io.metersphere.sdk.util.JSON;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
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.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.UUID;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@SpringBootTest
@AutoConfigureMockMvc
class IssueControllerTest {
@Resource
private MockMvc mockMvc;
@Test
void listAll() {
}
@Test
void get() {
}
@Test
void add() throws Exception {
Issue issue = new Issue();
issue.setTitle("test");
issue.setId(UUID.randomUUID().toString());
issue.setProjectId(UUID.randomUUID().toString());
issue.setCreateUser(UUID.randomUUID().toString());
issue.setNum(1);
issue.setPlatformStatus(UUID.randomUUID().toString());
issue.setPlatform(UUID.randomUUID().toString());
issue.setSourceId(UUID.randomUUID().toString());
mockMvc.perform(
MockMvcRequestBuilders.post("/issue/add")
.content(JSON.toJSONString(issue))
.contentType(MediaType.APPLICATION_JSON))
// 检查状态
.andExpect(status().isOk())
// 检查响应头
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
// 检查数据
.andExpect(jsonPath("$.data.title").value("test"))
.andDo(print());
// 缺陷已存在校验
mockMvc.perform(
MockMvcRequestBuilders.post("/issue/add")
.content(JSON.toJSONString(issue))
.contentType(MediaType.APPLICATION_JSON))
// 检查失败状态码
.andExpect(status().is5xxServerError())
// 检查响应头
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
// 检查业务状态码
.andExpect(jsonPath("$.code").value(108001))
.andDo(print());
}
@Test
void update() {
}
@Test
void delete() {
}
}

View File

@ -0,0 +1,83 @@
spring.application.name=metersphere
management.server.port=7005
server.port=8005
# ?? gzip ??
server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css,text/javascript,image/jpeg
server.compression.min-response-size=2048
#
quartz.enabled=false
quartz.scheduler-name=msScheduler
quartz.thread-count=10
quartz.properties.org.quartz.jobStore.acquireTriggersWithinLock=true
#
logging.file.path=/opt/metersphere/logs/metersphere
# Hikari
spring.datasource.url=jdbc:mysql://${embedded.mysql.host}:${embedded.mysql.port}/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
spring.datasource.username=${embedded.mysql.user}
spring.datasource.password=${embedded.mysql.password}
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.maximum-pool-size=100
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.idle-timeout=300000
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
#
# spring.kafka
spring.kafka.bootstrap-servers=${embedded.kafka.brokerList}
spring.kafka.consumer.group-id=metersphere_group_id
spring.kafka.consumer.debug.group-id=metersphere_group_id_${random.uuid}
spring.kafka.listener.missing-topics-fatal=false
spring.kafka.producer.properties.max.request.size=32428800
spring.kafka.producer.batch-size=16384
spring.kafka.consumer.properties.max.partition.fetch.bytes=52428800
# mybatis
mybatis.configuration.cache-enabled=true
mybatis.configuration.lazy-loading-enabled=false
mybatis.configuration.aggressive-lazy-loading=true
mybatis.configuration.multiple-result-sets-enabled=true
mybatis.configuration.use-column-label=true
mybatis.configuration.auto-mapping-behavior=full
mybatis.configuration.default-statement-timeout=25000
mybatis.configuration.map-underscore-to-camel-case=true
# view
spring.mvc.throw-exception-if-no-handler-found=true
# flyway enable
spring.flyway.enabled=true
spring.flyway.baseline-on-migrate=true
spring.flyway.locations=filesystem:../../app/src/main/resources/migration
spring.flyway.table=metersphere_version
spring.flyway.baseline-version=0
spring.flyway.encoding=UTF-8
spring.flyway.validate-on-migrate=false
# jmeter
jmeter.home=/opt/jmeter
# file upload
spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
# i18n
spring.messages.basename=i18n/commons,i18n/api,i18n/issue,i18n/load,i18n/project,i18n/system,i18n/plan,i18n/functional,i18n/ui,i18n/workstation
# actuator
management.endpoints.web.exposure.include=*
management.endpoints.enabled-by-default=false
# redis
spring.session.timeout=43200s
spring.data.redis.host=${embedded.redis.host}
spring.data.redis.password=${embedded.redis.password}
spring.data.redis.port=${embedded.redis.port}
spring.session.redis.repository-type=indexed
#
spring.freemarker.check-template-location=false
spring.groovy.template.check-template-location=false
#
minio.endpoint=http://${embedded.minio.host}:${embedded.minio.port}
minio.access-key=${embedded.minio.accessKey}
minio.secret-key=${embedded.minio.secretKey}
logging.level.org.springframework.jdbc.core=debug
logging.level.io.metersphere.sdk.mapper=debug
logging.level.io.metersphere.system.mapper=debug

View File

@ -0,0 +1,13 @@
# embedded config
embedded.containers.enabled=true
embedded.containers.forceShutdown=true
# mysql
embedded.mysql.enabled=true
embedded.mysql.encoding=utf8mb4
embedded.mysql.collation=utf8mb4_general_ci
# redis
embedded.redis.enabled=true
# kafka
embedded.kafka.enabled=false
# minio
embedded.minio.enabled=false