提交 d2e0e8e1 authored 作者: 黄夏豪's avatar 黄夏豪

fix(base): 新增testJobMapper中的分页查询

上级 6b7891e2
...@@ -2,6 +2,7 @@ package org.matrix.actuators.usecase; ...@@ -2,6 +2,7 @@ package org.matrix.actuators.usecase;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils;
import org.matrix.actuators.Actuator; import org.matrix.actuators.Actuator;
import org.matrix.actuators.checkpoint.CheckPointActuator; import org.matrix.actuators.checkpoint.CheckPointActuator;
import org.matrix.actuators.httpclient.HttpClientActuator; import org.matrix.actuators.httpclient.HttpClientActuator;
...@@ -23,6 +24,7 @@ import org.springframework.web.socket.TextMessage; ...@@ -23,6 +24,7 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.WebSocketSession;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
...@@ -56,7 +58,7 @@ public class CaseActuator implements Actuator { ...@@ -56,7 +58,7 @@ public class CaseActuator implements Actuator {
*/ */
public TestCaseExecuteResult executeTestCase(TestCaseBTO testCaseBto, Long envId, Long projectId) { public TestCaseExecuteResult executeTestCase(TestCaseBTO testCaseBto, Long envId, Long projectId) {
try { try {
LogQueueRuntime.addNewLog("[用例执行器] 开始执行单条用例数据!!"); LogQueueRuntime.addNewLog("[用例执行器] 开始执行用例!!");
LogQueueRuntime.addNewLog(String.format("[用例执行器] 当前正在执行用例ID: %s 用例名: %s", testCaseBto.getTestCase().getId(), testCaseBto.getTestCase().getName())); LogQueueRuntime.addNewLog(String.format("[用例执行器] 当前正在执行用例ID: %s 用例名: %s", testCaseBto.getTestCase().getId(), testCaseBto.getTestCase().getName()));
//执行前置动作 //执行前置动作
executeMove(testCaseBto.getTestCase().getMoveAfterCase() executeMove(testCaseBto.getTestCase().getMoveAfterCase()
...@@ -99,7 +101,9 @@ public class CaseActuator implements Actuator { ...@@ -99,7 +101,9 @@ public class CaseActuator implements Actuator {
LogQueueRuntime.addNewLog("[用例执行器] 开始执行用例!!" ); LogQueueRuntime.addNewLog("[用例执行器] 开始执行用例!!" );
try { try {
LogQueueRuntime.addNewLog(String.format("[用例执行器] 当前正在执行用例ID: %s 用例名: %s", testCaseBto.getTestCase().getId(), testCaseBto.getTestCase().getName())); LogQueueRuntime.addNewLog(String.format("[用例执行器] 当前正在执行用例ID: %s 用例名: %s", testCaseBto.getTestCase().getId(), testCaseBto.getTestCase().getName()));
//todo 黄夏豪 执行前置动作 //执行前置动作
executeMove(testCaseBto.getTestCase().getMoveAfterCase()
, envId, projectId, null, MoveStrategy.PRE_MOVE);
LogQueueRuntime.addNewLog("[用例执行器] 开始执行前置动作!!"); LogQueueRuntime.addNewLog("[用例执行器] 开始执行前置动作!!");
//执行测试用例的本体内容 //执行测试用例的本体内容
List<TestCaseExecuteResult> resultList = new ArrayList<>(); List<TestCaseExecuteResult> resultList = new ArrayList<>();
...@@ -114,7 +118,9 @@ public class CaseActuator implements Actuator { ...@@ -114,7 +118,9 @@ public class CaseActuator implements Actuator {
testCaseBto.getTestCase(), testCaseBto.getTestCase(),
testData); testData);
LogQueueRuntime.addNewLog("[用例执行器] 即将开始执行中置动作"); LogQueueRuntime.addNewLog("[用例执行器] 即将开始执行中置动作");
//todo 黄夏豪 执行测试后动作 //执行中置动作
executeMove(testCaseBto.getTestCase().getMoveAfterTest()
, envId, projectId, baseTestCaseResponseDetail.getResponseBody(), MoveStrategy.MID_MOVE);
CheckPointResult checkPointResult = getCheckPointResult(testCaseBto.getTestCase(), CheckPointResult checkPointResult = getCheckPointResult(testCaseBto.getTestCase(),
testData, testData,
envId, envId,
...@@ -122,15 +128,18 @@ public class CaseActuator implements Actuator { ...@@ -122,15 +128,18 @@ public class CaseActuator implements Actuator {
baseTestCaseResponseDetail); baseTestCaseResponseDetail);
TestCaseExecuteResult testCaseExecuteResult = new TestCaseExecuteResult(baseTestCaseResponseDetail, checkPointResult); TestCaseExecuteResult testCaseExecuteResult = new TestCaseExecuteResult(baseTestCaseResponseDetail, checkPointResult);
resultList.add(testCaseExecuteResult); resultList.add(testCaseExecuteResult);
LogQueueRuntime.addNewLog(JSON.toJSONString(testCaseExecuteResult)); LogQueueRuntime.addNewLog("用例执行结果:" + JSON.toJSONString(testCaseExecuteResult));
//todo 黄夏豪 执行后置动作 //执行后置动作
executeMove(testCaseBto.getTestCase().getMoveAfterTest()
, envId, projectId, baseTestCaseResponseDetail.getResponseBody(), MoveStrategy.AFT_MOVE);
changeExecutionHistoryStatus(ExecutionHistoryStatus.FINISH); changeExecutionHistoryStatus(ExecutionHistoryStatus.FINISH);
} }
//将线程中正在执行的DataId清除
LogQueueRuntime.clearTestData();
return resultList; return resultList;
} catch (Exception e) { } catch (Exception e) {
throw e; throw e;
}finally {
//将线程中正在执行的DataId清除
LogQueueRuntime.clearTestData();
} }
} }
...@@ -144,7 +153,7 @@ public class CaseActuator implements Actuator { ...@@ -144,7 +153,7 @@ public class CaseActuator implements Actuator {
* @param strategy 动作的策略,即是前置/中间/后置,具体查看{@link MoveStrategy} * @param strategy 动作的策略,即是前置/中间/后置,具体查看{@link MoveStrategy}
*/ */
private void executeMove(String moveString, Long envId, Long projectId, String caseResultData, MoveStrategy strategy) { private void executeMove(String moveString, Long envId, Long projectId, String caseResultData, MoveStrategy strategy) {
String[] moveIds = moveString.split(","); String[] moveIds = StringUtils.isEmpty(moveString) ? new String[]{} : moveString.split(",");
for (String moveId : moveIds) { for (String moveId : moveIds) {
getMoveActuator().runMove( getMoveActuator().runMove(
Long.valueOf(moveId), Long.valueOf(moveId),
...@@ -208,6 +217,12 @@ public class CaseActuator implements Actuator { ...@@ -208,6 +217,12 @@ public class CaseActuator implements Actuator {
//将websocketSession 加入到socket池子中 //将websocketSession 加入到socket池子中
TestCaseExecuteSocketPool.add(currentThreadId, session); TestCaseExecuteSocketPool.add(currentThreadId, session);
List<TestCaseListDataBto> testCaseListDataBtoList = caseExecuteVo.getTestCaseListDataBtoList(); List<TestCaseListDataBto> testCaseListDataBtoList = caseExecuteVo.getTestCaseListDataBtoList();
for (int i = 0; i < testCaseListDataBtoList.size(); i++) {
Long caseProjectId = testCaseListDataBtoList.get(i).getTestCase().getProjectId();
if (!caseExecuteVo.getProjectId().equals(caseProjectId)){
throw new GlobalException("本次执行中,存在非相同项目的测试用例");
}
}
//建立执行历史(ExecutionHistory) //建立执行历史(ExecutionHistory)
insertExecutionHistory(unionKey, caseExecuteVo); insertExecutionHistory(unionKey, caseExecuteVo);
for (TestCaseListDataBto testCaseListDataBto : testCaseListDataBtoList) { for (TestCaseListDataBto testCaseListDataBto : testCaseListDataBtoList) {
...@@ -219,7 +234,6 @@ public class CaseActuator implements Actuator { ...@@ -219,7 +234,6 @@ public class CaseActuator implements Actuator {
, caseExecuteVo.getType() , caseExecuteVo.getType()
, unionKey , unionKey
); );
//执行测试用例 //执行测试用例
return executeTestCases(testCaseListDataBto, caseExecuteVo.getEnvId(), caseExecuteVo.getProjectId()); return executeTestCases(testCaseListDataBto, caseExecuteVo.getEnvId(), caseExecuteVo.getProjectId());
} }
...@@ -239,11 +253,12 @@ public class CaseActuator implements Actuator { ...@@ -239,11 +253,12 @@ public class CaseActuator implements Actuator {
ioException.printStackTrace(); ioException.printStackTrace();
} }
} finally { } finally {
//将数据库中的执行历史状态设置为完成
endExecutionHistory();
//将本次产生的数据清除 //将本次产生的数据清除
TestCaseExecuteSocketPool.remove(currentThreadId); TestCaseExecuteSocketPool.remove(currentThreadId);
//将本次产生的日志从执行状态设为停止状态 //将本次产生的日志从执行状态设为停止状态
LogQueueRuntime.remove(currentThreadId); LogQueueRuntime.remove(currentThreadId);
//todo 黄夏豪 将数据库中的执行历史状态设置为完成
} }
return null; return null;
} }
...@@ -253,12 +268,15 @@ public class CaseActuator implements Actuator { ...@@ -253,12 +268,15 @@ public class CaseActuator implements Actuator {
for (TestCaseListDataBto testCaseListDataBto : testCaseListDataBtoList) { for (TestCaseListDataBto testCaseListDataBto : testCaseListDataBtoList) {
List<TestData> testDataList = testCaseListDataBto.getTestDataList(); List<TestData> testDataList = testCaseListDataBto.getTestDataList();
TestCase testCase = testCaseListDataBto.getTestCase(); TestCase testCase = testCaseListDataBto.getTestCase();
for (TestData testData : testDataList) { for (int i = 0; i < testDataList.size(); i++) {
ExecutionHistory executionHistory = new ExecutionHistory(); ExecutionHistory executionHistory = new ExecutionHistory();
executionHistory.setJobId(caseExecuteVo.getJobId()); executionHistory.setJobId(caseExecuteVo.getJobId());
executionHistory.setCaseId(testCase.getId()); executionHistory.setCaseId(testCase.getId());
executionHistory.setDataId(testData.getId()); executionHistory.setDataId(testDataList.get(i).getId());
executionHistory.setUnionKey(unionKey); executionHistory.setUnionKey(unionKey);
if (i==0){
executionHistory.setStartTime(LocalDateTime.now());
}
executionHistoryService.save(executionHistory); executionHistoryService.save(executionHistory);
} }
} }
...@@ -269,17 +287,39 @@ public class CaseActuator implements Actuator { ...@@ -269,17 +287,39 @@ public class CaseActuator implements Actuator {
TestExecuteLog currentTestExecute = LogQueueRuntime.getCurrentTestExecute(ThreadUtil.currentThreadId()); TestExecuteLog currentTestExecute = LogQueueRuntime.getCurrentTestExecute(ThreadUtil.currentThreadId());
if (currentTestExecute!=null){ if (currentTestExecute!=null){
ExecutionHistory executionHistory = new ExecutionHistory(); ExecutionHistory executionHistory = new ExecutionHistory();
if (executionHistoryStatus.equals(ExecutionHistoryStatus.RUN)){
executionHistory.setStartTime(LocalDateTime.now());
}else if (executionHistoryStatus.equals(ExecutionHistoryStatus.FINISH)){
executionHistory.setEndTime(LocalDateTime.now());
}
executionHistory.setStatus(executionHistoryStatus); executionHistory.setStatus(executionHistoryStatus);
executionHistoryService.update(executionHistory, Wrappers executionHistoryService.update(executionHistory, Wrappers
.lambdaUpdate(ExecutionHistory.class) .lambdaUpdate(ExecutionHistory.class)
.eq(ExecutionHistory::getJobId,currentTestExecute.getJobId()) .eq(ExecutionHistory::getJobId,currentTestExecute.getTestJobId())
.eq(ExecutionHistory::getCaseId,currentTestExecute.getTestCaseId()) .eq(ExecutionHistory::getCaseId,currentTestExecute.getTestCaseId())
.eq(ExecutionHistory::getDataId,currentTestExecute.getTestDataId()) .eq(ExecutionHistory::getDataId,currentTestExecute.getTestDataId())
.eq(ExecutionHistory::getUnionKey,currentTestExecute.getUnionKey()) .eq(ExecutionHistory::getUnionKey,currentTestExecute.getUnionKey())
); );
} }
}
/**
* 将所有还未完成的执行历史设置为ERROR
*/
public void endExecutionHistory() {
TestExecuteLog currentTestExecute = LogQueueRuntime.getCurrentTestExecute(ThreadUtil.currentThreadId());
if (currentTestExecute!=null){
ExecutionHistory executionHistory = new ExecutionHistory();
executionHistory.setStatus(ExecutionHistoryStatus.ERROR);
executionHistory.setEndTime(LocalDateTime.now());
executionHistoryService.update(executionHistory, Wrappers
.lambdaUpdate(ExecutionHistory.class)
.eq(ExecutionHistory::getJobId,currentTestExecute.getTestJobId())
.eq(ExecutionHistory::getCaseId,currentTestExecute.getTestCaseId())
.eq(ExecutionHistory::getUnionKey,currentTestExecute.getUnionKey())
.ne(ExecutionHistory::getStatus,ExecutionHistoryStatus.FINISH)
);
}
} }
......
package org.matrix.database.entity; package org.matrix.database.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.matrix.enums.ExecutionHistoryStatus; import org.matrix.enums.ExecutionHistoryStatus;
import java.time.LocalDateTime;
/** /**
* <p> * <p>
* *
...@@ -32,6 +38,21 @@ public class ExecutionHistory extends BaseEntity { ...@@ -32,6 +38,21 @@ public class ExecutionHistory extends BaseEntity {
private ExecutionHistoryStatus status = ExecutionHistoryStatus.READY; private ExecutionHistoryStatus status = ExecutionHistoryStatus.READY;
/**
* 创建时间
*/
@ApiModelProperty("开始执行时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
private LocalDateTime startTime;
/**
* 更新时间
*/
@ApiModelProperty("结束执行时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
private LocalDateTime endTime;
} }
...@@ -16,9 +16,9 @@ import lombok.NoArgsConstructor; ...@@ -16,9 +16,9 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName("kt_test_task") @TableName("kt_test_job")
@ApiModel(value = "TestTask对象", description = "测试任务") @ApiModel(value = "TestJob对象", description = "测试任务")
public class TestTask extends BaseEntity{ public class TestJob extends BaseEntity{
@ApiModelProperty("名称") @ApiModelProperty("名称")
private String name; private String name;
......
...@@ -35,9 +35,11 @@ public interface ExecutionHistoryMapper extends BaseMapper<ExecutionHistory> { ...@@ -35,9 +35,11 @@ public interface ExecutionHistoryMapper extends BaseMapper<ExecutionHistory> {
"\tkeh.case_id caseId,\n" + "\tkeh.case_id caseId,\n" +
"\tkeh.data_id dataId,\n" + "\tkeh.data_id dataId,\n" +
"\tkeh.job_id jobId,\n" + "\tkeh.job_id jobId,\n" +
"\tkeh.`status` `status`,\n" + "\tIF(MIN(keh.`status`)=0,0,MAX(keh.`status`)) `status`,\n" +
"\tktc.`name` caseName,\n" + "\tktc.`name` caseName,\n" +
"\tktd.`name` dataName \n" + "\tktd.`name` dataName," +
"\tMIN(keh.create_time) startTime,\n" +
"\tMAX(keh.update_time) endTime " +
"FROM\n" + "FROM\n" +
"\tkt_execution_history keh\n" + "\tkt_execution_history keh\n" +
"\tLEFT JOIN kt_test_case ktc ON ktc.id = keh.case_id\n" + "\tLEFT JOIN kt_test_case ktc ON ktc.id = keh.case_id\n" +
...@@ -50,6 +52,7 @@ public interface ExecutionHistoryMapper extends BaseMapper<ExecutionHistory> { ...@@ -50,6 +52,7 @@ public interface ExecutionHistoryMapper extends BaseMapper<ExecutionHistory> {
"and keh.job_id= #{jobId} \n" + "and keh.job_id= #{jobId} \n" +
" </if>" + " </if>" +
"</where>" + "</where>" +
"GROUP BY keh.union_key " +
"</script>") "</script>")
IPage<ExecutionHistoryVo> pageByCaseIdAndJobId(IPage<ExecutionHistoryVo> page, Long caseId, Long jobId); IPage<ExecutionHistoryVo> pageByCaseIdAndJobId(IPage<ExecutionHistoryVo> page, Long caseId, Long jobId);
......
package org.matrix.database.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Select;
import org.matrix.database.entity.TestJob;
import org.matrix.database.vo.TestJobVo;
/**
* @author mry
*/
public interface TestJobMapper extends BaseMapper<TestJob> {
/**
* 分页查询TestJob
* @param page 分页信息
* @return 带有分页的测试任务列表
*/
@Select("SELECT\n" +
"\tktj.id,\n" +
"\tktj.`name`,\n" +
"\tktj.sql_statement,\n" +
"\tktj.remark,\n" +
"\t`status` \n" +
"FROM\n" +
"\t`kt_test_job` ktj\n" +
"\tLEFT JOIN ( SELECT job_id, union_key FROM kt_execution_history WHERE id IN ( SELECT max( id ) FROM kt_execution_history WHERE job_id != - 1 GROUP BY job_id ) ) keh ON ktj.id = keh.job_id\n" +
"\tLEFT JOIN ( SELECT union_key, IF ( MIN( `status` )= 0, 0, MAX( `status` )) `status` FROM kt_execution_history GROUP BY union_key ) us ON us.union_key = keh.union_key")
IPage<TestJobVo> pageTestJob(IPage<TestJob> page);
}
package org.matrix.database.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.matrix.database.entity.TestTask;
/**
* @author mry
*/
public interface TestTaskMapper extends BaseMapper<TestTask> {
}
package org.matrix.database.service; package org.matrix.database.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.matrix.database.entity.TestTask; import org.matrix.database.entity.TestJob;
/** /**
* @author mry * @author mry
*/ */
public interface ITestTaskService extends IService<TestTask> { public interface ITestJobService extends IService<TestJob> {
} }
package org.matrix.database.service.impl; package org.matrix.database.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.matrix.database.entity.TestTask; import org.matrix.database.entity.TestJob;
import org.matrix.database.mapper.TestTaskMapper; import org.matrix.database.mapper.TestJobMapper;
import org.matrix.database.service.ITestTaskService; import org.matrix.database.service.ITestJobService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* @author mry * @author mry
*/ */
@Service @Service
public class TestTaskServiceImpl extends ServiceImpl<TestTaskMapper, TestTask> implements ITestTaskService { public class TestJobServiceImpl extends ServiceImpl<TestJobMapper, TestJob> implements ITestJobService {
} }
...@@ -3,6 +3,8 @@ package org.matrix.database.vo; ...@@ -3,6 +3,8 @@ package org.matrix.database.vo;
import lombok.Data; import lombok.Data;
import org.matrix.database.entity.ExecutionHistory; import org.matrix.database.entity.ExecutionHistory;
import java.time.LocalDateTime;
/** /**
* ExecutionHistory 给前端用于展示的VO * ExecutionHistory 给前端用于展示的VO
* @author huangxiahao * @author huangxiahao
...@@ -14,4 +16,8 @@ public class ExecutionHistoryVo extends ExecutionHistory { ...@@ -14,4 +16,8 @@ public class ExecutionHistoryVo extends ExecutionHistory {
private String dataName; private String dataName;
private LocalDateTime startTime;
private LocalDateTime endTime;
} }
package org.matrix.database.vo;
import org.matrix.database.entity.TestJob;
/**
* testJob给前端展示用的Vo
* @author huangxiahao
*/
public class TestJobVo extends TestJob {
private Integer status;
}
...@@ -14,17 +14,21 @@ import lombok.Getter; ...@@ -14,17 +14,21 @@ import lombok.Getter;
public enum ExecutionHistoryStatus { public enum ExecutionHistoryStatus {
/** /**
* SQL类型动作,该动作执行SQL语句 * 准备阶段
*/ */
READY(0, "准备阶段"), READY(0, "准备阶段"),
/** /**
* HTTP类型动作,该动作执行HTTP接口 * 执行阶段
*/ */
RUN(1, "执行阶段"), RUN(1, "执行阶段"),
/** /**
* 用例类型动作,该动作执行另外的测试用例 * 完成阶段
*/ */
FINISH(2, "完成阶段"); FINISH(2, "完成阶段"),
/**
* 异常
*/
ERROR(3, "异常");
/** /**
* 数据库里记录的字段使用该字段来记录 * 数据库里记录的字段使用该字段来记录
......
...@@ -35,8 +35,6 @@ public class HttpAuthHandler extends TextWebSocketHandler { ...@@ -35,8 +35,6 @@ public class HttpAuthHandler extends TextWebSocketHandler {
@Override @Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
System.out.println("收到了: " + message.toString());
session.sendMessage(new TextMessage("message get success"));
String payload = message.getPayload(); String payload = message.getPayload();
//检验客户端是否进行测试用例调试 //检验客户端是否进行测试用例调试
try { try {
...@@ -56,7 +54,6 @@ public class HttpAuthHandler extends TextWebSocketHandler { ...@@ -56,7 +54,6 @@ public class HttpAuthHandler extends TextWebSocketHandler {
} catch (JSONException e) { } catch (JSONException e) {
session.sendMessage(new TextMessage("入参不符合规定")); session.sendMessage(new TextMessage("入参不符合规定"));
} }
session.sendMessage(new TextMessage("message execute success"));
} }
@Override @Override
......
...@@ -5,7 +5,6 @@ import cn.hutool.log.level.Level; ...@@ -5,7 +5,6 @@ import cn.hutool.log.level.Level;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.matrix.actuators.util.ThreadUtil; import org.matrix.actuators.util.ThreadUtil;
import org.matrix.database.service.IExecutionRecordService; import org.matrix.database.service.IExecutionRecordService;
import org.matrix.enums.ExecutionRecType;
import org.matrix.exception.GlobalException; import org.matrix.exception.GlobalException;
import org.matrix.util.SpringUtils; import org.matrix.util.SpringUtils;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
...@@ -79,7 +78,7 @@ public class LogQueueRuntime { ...@@ -79,7 +78,7 @@ public class LogQueueRuntime {
String logMessage = String logMessage =
String.format( String.format(
"%s.%s.%s.%s" "%s.%s.%s.%s"
,testExecuteLog.getJobId() ,testExecuteLog.getTestJobId()
,testExecuteLog.getTestCaseId() ,testExecuteLog.getTestCaseId()
,testExecuteLog.getTestDataId() ,testExecuteLog.getTestDataId()
,message.substring(1,message.length()-1) ,message.substring(1,message.length()-1)
...@@ -108,7 +107,7 @@ public class LogQueueRuntime { ...@@ -108,7 +107,7 @@ public class LogQueueRuntime {
public static void initTestCaseLog(Long jobId,Long userId, Long caseId,TestExecuteType type,String unionKey) { public static void initTestCaseLog(Long jobId,Long userId, Long caseId,TestExecuteType type,String unionKey) {
TestExecuteLog testExecuteLog = new TestExecuteLog(); TestExecuteLog testExecuteLog = new TestExecuteLog();
testExecuteLog.setJobId(jobId); testExecuteLog.setTestJobId(jobId);
testExecuteLog.setTestCaseId(caseId); testExecuteLog.setTestCaseId(caseId);
testExecuteLog.setUserId(userId); testExecuteLog.setUserId(userId);
testExecuteLog.setType(type); testExecuteLog.setType(type);
......
...@@ -14,7 +14,7 @@ import java.util.Objects; ...@@ -14,7 +14,7 @@ import java.util.Objects;
public class TestExecuteLog { public class TestExecuteLog {
private Long jobId = -1L; private Long testJobId = -1L;
/** /**
* 用于记录执行记录的唯一KEY,同一批次的执行记录应该具有相同的KEY。 * 用于记录执行记录的唯一KEY,同一批次的执行记录应该具有相同的KEY。
*/ */
......
...@@ -20,3 +20,6 @@ mybatis-plus: ...@@ -20,3 +20,6 @@ mybatis-plus:
type-enums-package: org.matrix.enums type-enums-package: org.matrix.enums
baseJsPath: syntaxCheck.js baseJsPath: syntaxCheck.js
...@@ -3,8 +3,7 @@ package org.matrix.autotest.controller; ...@@ -3,8 +3,7 @@ package org.matrix.autotest.controller;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api; import io.swagger.annotations.*;
import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.utils.PageTools; import org.matrix.autotest.utils.PageTools;
import org.matrix.database.entity.ExecutionRecord; import org.matrix.database.entity.ExecutionRecord;
import org.matrix.database.service.IExecutionHistoryService; import org.matrix.database.service.IExecutionHistoryService;
...@@ -35,7 +34,14 @@ public class ExecutionHistoryController { ...@@ -35,7 +34,14 @@ public class ExecutionHistoryController {
this.executionHistoryService = executionHistoryService; this.executionHistoryService = executionHistoryService;
} }
@ApiOperation(value = "分页查询执行历史",notes = "假如查询测试用例的执行历史,请入参caseId,假如查询测试任务的执行历史,请入参jobId")
@GetMapping("/findExecutionHistory") @GetMapping("/findExecutionHistory")
@ApiImplicitParams({
@ApiImplicitParam(name="pageSize",value="页码",required=true,paramType="query"),
@ApiImplicitParam(name="pageNum",value="当前页显示调试",required=true,paramType="query"),
@ApiImplicitParam(name="jobId",value="测试任务ID",paramType="query"),
@ApiImplicitParam(name="caseId",value="测试用例ID",paramType="query")
})
public ResponseEntity<CommonResultObj<IPage<ExecutionHistoryVo>>> findExecutionHistory( public ResponseEntity<CommonResultObj<IPage<ExecutionHistoryVo>>> findExecutionHistory(
@RequestParam(defaultValue = "10") int pageSize, @RequestParam(defaultValue = "10") int pageSize,
@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "1") int pageNum,
......
...@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; ...@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.utils.PageTools; import org.matrix.autotest.utils.PageTools;
import org.matrix.database.entity.TestTask; import org.matrix.database.entity.TestJob;
import org.matrix.database.service.ITestTaskService; import org.matrix.database.service.ITestJobService;
import org.matrix.database.vo.CommonResult; import org.matrix.database.vo.CommonResult;
import org.matrix.database.vo.CommonResultObj; import org.matrix.database.vo.CommonResultObj;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -22,14 +22,14 @@ import java.util.Optional; ...@@ -22,14 +22,14 @@ import java.util.Optional;
*/ */
@CrossOrigin @CrossOrigin
@RestController @RestController
@RequestMapping("/testTasks") @RequestMapping("/testJob")
@Api(tags = "对测试任务test_task的基本操作") @Api(tags = "对测试任务test_job的基本操作")
public class TestTaskController { public class TestJobController {
private final ITestTaskService testTaskService; private final ITestJobService testJobService;
public TestTaskController(ITestTaskService testTaskService) { public TestJobController(ITestJobService testJobService) {
this.testTaskService = testTaskService; this.testJobService = testJobService;
} }
/** /**
...@@ -39,8 +39,8 @@ public class TestTaskController { ...@@ -39,8 +39,8 @@ public class TestTaskController {
*/ */
@ApiOperation(value = "查询所有测试任务") @ApiOperation(value = "查询所有测试任务")
@GetMapping @GetMapping
public ResponseEntity<CommonResultObj<List<TestTask>>> findConnects() { public ResponseEntity<CommonResultObj<List<TestJob>>> findConnects() {
List<TestTask> results = Optional.ofNullable(testTaskService.list()).orElse(new ArrayList<>()); List<TestJob> results = Optional.ofNullable(testJobService.list()).orElse(new ArrayList<>());
return results.size() != 0 return results.size() != 0
? CommonResult.success(results, "查询成功") ? CommonResult.success(results, "查询成功")
: CommonResult.failed(results, "查询失败或无数据"); : CommonResult.failed(results, "查询失败或无数据");
...@@ -56,12 +56,12 @@ public class TestTaskController { ...@@ -56,12 +56,12 @@ public class TestTaskController {
*/ */
@ApiOperation(value = "分页查询测试任务") @ApiOperation(value = "分页查询测试任务")
@GetMapping("/page") @GetMapping("/page")
public ResponseEntity<CommonResultObj<Page<TestTask>>> findPageTestTasks( public ResponseEntity<CommonResultObj<Page<TestJob>>> findPageTestTasks(
@RequestParam(defaultValue = "10") int pageSize, @RequestParam(defaultValue = "10") int pageSize,
@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "1") int pageNum,
String name) { String name) {
Page<TestTask> results = Optional.of(testTaskService.page(Page.of(pageNum, pageSize), Wrappers.lambdaQuery(TestTask.class) Page<TestJob> results = Optional.of(testJobService.page(Page.of(pageNum, pageSize), Wrappers.lambdaQuery(TestJob.class)
.like(StringUtils.hasLength(name), TestTask::getName, name))) .like(StringUtils.hasLength(name), TestJob::getName, name)))
.orElse(new Page<>()); .orElse(new Page<>());
PageTools.pageTool(pageSize, pageNum, results); PageTools.pageTool(pageSize, pageNum, results);
return results.getRecords().size() != 0 return results.getRecords().size() != 0
...@@ -72,26 +72,26 @@ public class TestTaskController { ...@@ -72,26 +72,26 @@ public class TestTaskController {
/** /**
* 添加测试任务 * 添加测试任务
* *
* @param testTask 测试任务对象 * @param testJob 测试任务对象
* @return 添加的测试任务,以及是否添加成功的提示信息 * @return 添加的测试任务,以及是否添加成功的提示信息
*/ */
@ApiOperation(value = "添加测试任务") @ApiOperation(value = "添加测试任务")
@PostMapping @PostMapping
public ResponseEntity<CommonResultObj<TestTask>> insertTestTask(@RequestBody TestTask testTask) { public ResponseEntity<CommonResultObj<TestJob>> insertTestTask(@RequestBody TestJob testJob) {
return CommonResult.pred(testTaskService::save, testTask return CommonResult.pred(testJobService::save, testJob
, "添加成功", "添加失败"); , "添加成功", "添加失败");
} }
/** /**
* 修改测试任务 * 修改测试任务
* *
* @param testTask 测试任务对象 * @param testJob 测试任务对象
* @return 修改后的测试任务,以及是否修改成功的提示信息 * @return 修改后的测试任务,以及是否修改成功的提示信息
*/ */
@ApiOperation(value = "修改测试任务") @ApiOperation(value = "修改测试任务")
@PutMapping @PutMapping
public ResponseEntity<CommonResultObj<TestTask>> updateTestTask(@RequestBody TestTask testTask) { public ResponseEntity<CommonResultObj<TestJob>> updateTestTask(@RequestBody TestJob testJob) {
return CommonResult.pred(testTaskService::updateById, testTask return CommonResult.pred(testJobService::updateById, testJob
, "修改成功", "修改失败"); , "修改成功", "修改失败");
} }
...@@ -104,7 +104,7 @@ public class TestTaskController { ...@@ -104,7 +104,7 @@ public class TestTaskController {
@ApiOperation(value = "根据主键id删除测试任务") @ApiOperation(value = "根据主键id删除测试任务")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public ResponseEntity<CommonResultObj<Long>> deleteTestTask(@PathVariable Long id) { public ResponseEntity<CommonResultObj<Long>> deleteTestTask(@PathVariable Long id) {
return CommonResult.pred(testTaskService::removeById, id return CommonResult.pred(testJobService::removeById, id
, "删除成功", "删除失败或id不存在"); , "删除成功", "删除失败或id不存在");
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论