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

fix(base): 改了一些BUG

上级 2e8e1b19
...@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; ...@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils; 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.datasource.DataSourceDTO;
import org.matrix.actuators.datasource.IDataSourceService;
import org.matrix.actuators.httpclient.HttpClientActuator; import org.matrix.actuators.httpclient.HttpClientActuator;
import org.matrix.actuators.move.MoveActuator; import org.matrix.actuators.move.MoveActuator;
import org.matrix.actuators.move.MoveStrategy; import org.matrix.actuators.move.MoveStrategy;
...@@ -27,11 +29,11 @@ import org.matrix.socket.queue.LogQueueRuntime; ...@@ -27,11 +29,11 @@ import org.matrix.socket.queue.LogQueueRuntime;
import org.matrix.socket.vo.CaseExecuteVo; import org.matrix.socket.vo.CaseExecuteVo;
import org.matrix.socket.vo.TestExecuteLog; import org.matrix.socket.vo.TestExecuteLog;
import org.matrix.util.SpringUtils; import org.matrix.util.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.WebSocketSession;
import javax.management.StringValueExp;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
...@@ -46,6 +48,9 @@ import static org.matrix.enums.ModuleType.CASE_ACTUATOR; ...@@ -46,6 +48,9 @@ import static org.matrix.enums.ModuleType.CASE_ACTUATOR;
@Component @Component
public class CaseActuator implements Actuator { public class CaseActuator implements Actuator {
final
IDataSourceService dataSourceService;
private final CheckPointActuator checkPointActuator; private final CheckPointActuator checkPointActuator;
private final HttpClientActuator httpClientActuator; private final HttpClientActuator httpClientActuator;
...@@ -56,11 +61,12 @@ public class CaseActuator implements Actuator { ...@@ -56,11 +61,12 @@ public class CaseActuator implements Actuator {
private final ExecutionStatusMonitorSocketHandler executionStatusMonitorSocketHandler; private final ExecutionStatusMonitorSocketHandler executionStatusMonitorSocketHandler;
public CaseActuator(CheckPointActuator checkPointActuator, HttpClientActuator httpClientActuator, IExecutionHistoryService executionHistoryService, ExecutionStatusMonitorSocketHandler executionStatusMonitorSocketHandler) { public CaseActuator(CheckPointActuator checkPointActuator, HttpClientActuator httpClientActuator, IExecutionHistoryService executionHistoryService, ExecutionStatusMonitorSocketHandler executionStatusMonitorSocketHandler, IDataSourceService dataSourceService) {
this.checkPointActuator = checkPointActuator; this.checkPointActuator = checkPointActuator;
this.httpClientActuator = httpClientActuator; this.httpClientActuator = httpClientActuator;
this.executionHistoryService = executionHistoryService; this.executionHistoryService = executionHistoryService;
this.executionStatusMonitorSocketHandler = executionStatusMonitorSocketHandler; this.executionStatusMonitorSocketHandler = executionStatusMonitorSocketHandler;
this.dataSourceService = dataSourceService;
} }
...@@ -134,10 +140,6 @@ public class CaseActuator implements Actuator { ...@@ -134,10 +140,6 @@ public class CaseActuator implements Actuator {
LogQueueRuntime.setTestData(testData.getId()); LogQueueRuntime.setTestData(testData.getId());
//try catch 一下避免发生错误后导致循环进行不下去 //try catch 一下避免发生错误后导致循环进行不下去
try { try {
for (int i = 0; i < 20 ; i++) {
LogQueueRuntime.addNewLog(getClass(),CASE_ACTUATOR, String.valueOf(i));
Thread.sleep(1000L);
}
changeExecutionHistoryStatus(ExecutionHistoryStatus.RUN); changeExecutionHistoryStatus(ExecutionHistoryStatus.RUN);
LogQueueRuntime.addNewLog(this.getClass(), CASE_ACTUATOR, "[用例执行器] 开始执行数据组ID:" + testData.getId()); LogQueueRuntime.addNewLog(this.getClass(), CASE_ACTUATOR, "[用例执行器] 开始执行数据组ID:" + testData.getId());
HttpResponseDetail baseTestCaseResponseDetail = getHttpResponseDetail( HttpResponseDetail baseTestCaseResponseDetail = getHttpResponseDetail(
...@@ -170,6 +172,7 @@ public class CaseActuator implements Actuator { ...@@ -170,6 +172,7 @@ public class CaseActuator implements Actuator {
, envId, projectId, baseTestCaseResponseDetail.getResponseBody(), MoveStrategy.AFT_MOVE); , envId, projectId, baseTestCaseResponseDetail.getResponseBody(), MoveStrategy.AFT_MOVE);
changeExecutionHistoryStatus(ExecutionHistoryStatus.FINISH); changeExecutionHistoryStatus(ExecutionHistoryStatus.FINISH);
} catch (Exception e) { } catch (Exception e) {
dataSourceService.switchMainDataSource();
e.printStackTrace(); e.printStackTrace();
TestDataExecuteResult testDataExecuteResult = new TestDataExecuteResult( TestDataExecuteResult testDataExecuteResult = new TestDataExecuteResult(
dataStartTime, dataStartTime,
...@@ -305,13 +308,7 @@ public class CaseActuator implements Actuator { ...@@ -305,13 +308,7 @@ public class CaseActuator implements Actuator {
); );
if (!hasInit){ if (!hasInit){
//建立执行历史(ExecutionHistory) //建立执行历史(ExecutionHistory)
if (caseExecuteVo.getJobId() != -1L) { insertExecutionHistory(uniqueKey, caseExecuteVo);
if (!LogQueueRuntime.checkJobIsInRun(caseExecuteVo.getJobId(), caseExecuteVo.getUserId(), caseExecuteVo.getType())) {
insertExecutionHistory(uniqueKey, caseExecuteVo);
}
} else {
insertExecutionHistory(uniqueKey, caseExecuteVo);
}
hasInit = true; hasInit = true;
} }
//执行测试用例 //执行测试用例
......
...@@ -41,7 +41,7 @@ public class ReporterDataJob { ...@@ -41,7 +41,7 @@ public class ReporterDataJob {
* @return 报告中细节部分的信息 * @return 报告中细节部分的信息
*/ */
public List<DataBeans> testDataBeans() { public List<DataBeans> testDataBeans() {
List<DataBeans> dataBeansList = null; List<DataBeans> dataBeansList = new ArrayList<>();
List<DataBeansMoveVo> dataBeansMoveVos = ReporterUtils.jobMap.get("job").getDataBeansMove(); List<DataBeansMoveVo> dataBeansMoveVos = ReporterUtils.jobMap.get("job").getDataBeansMove();
for (DataBeansMoveVo dataBeansMoveVo : dataBeansMoveVos) { for (DataBeansMoveVo dataBeansMoveVo : dataBeansMoveVos) {
dataBeansList = dataBeansMoveVo.getDataBeansList(); dataBeansList = dataBeansMoveVo.getDataBeansList();
......
package org.matrix.actuators.http; package org.matrix.actuators.http;
import cn.hutool.script.ScriptUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jayway.jsonpath.JsonPath;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -17,6 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,6 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
class CaseActuatorTest { class CaseActuatorTest {
...@@ -57,19 +62,172 @@ class CaseActuatorTest { ...@@ -57,19 +62,172 @@ class CaseActuatorTest {
} }
void t(JSON json, String str){ @Test
JSON newJson ; void jsonPathTest() throws ScriptException {
//判断str中有没有. 如果没有点则证明为最后一个参数,由于最后一个参数的实际类型为jsonArray并且为递归退出条件所以需要特殊处理 String json = "{ \"store\": {\n" +
if (str.contains(".")){ " \"book\": [ \n" +
//切割获取点前面的字符 " { \"category\": \"reference\",\n" +
" \"author\": \"Nigel Rees\",\n" +
}else { " \"title\": \"Sayings of the Century\",\n" +
" \"price\": 8.95\n" +
" },\n" +
" { \"category\": \"fiction\",\n" +
" \"author\": \"Evelyn Waugh\",\n" +
" \"title\": \"Sword of Honour\",\n" +
" \"price\": 12.99\n" +
" },\n" +
" { \"category\": \"fiction\",\n" +
" \"author\": \"Herman Melville\",\n" +
" \"title\": \"Moby Dick\",\n" +
" \"isbn\": \"0-553-21311-3\",\n" +
" \"price\": 8.99\n" +
" },\n" +
" { \"category\": \"fiction\",\n" +
" \"author\": \"J. R. R. Tolkien\",\n" +
" \"title\": \"The Lord of the Rings\",\n" +
" \"isbn\": \"0-395-19395-8\",\n" +
" \"price\": 22.99\n" +
" }\n" +
" ],\n" +
" \"bicycle\": {\n" +
" \"color\": \"red\",\n" +
" \"price\": 19.95\n" +
" }\n" +
" }\n" +
"}";
ScriptEngine jsEngine = ScriptUtil.createJsEngine();
jsEngine.eval("//a跟b进行比较,对象类型分为以下几种:基础类型、数组、普通对象\n" +
"function equal(a, b) {\n" +
" var aType = Object.prototype.toString.call(a);\n" +
" var bType = Object.prototype.toString.call(b);\n" +
" switch (aType) {\n" +
" case \"[object Array]\":\n" +
" //数组类型\n" +
" switch (bType) {\n" +
" case \"[object Array]\":\n" +
" return JSON.stringify(a) === JSON.stringify(b);\n" +
" default:\n" +
" for (var i = 0; i < a.length; i++) {\n" +
" if (JSON.stringify(a[i]) !== JSON.stringify(b)) {\n" +
" return false;\n" +
" }\n" +
" }\n" +
" return true;\n" +
" }\n" +
" break\n" +
" default:\n" +
" //基础类型和对象类型\n" +
" switch (bType) {\n" +
" case \"[object Array]\":\n" +
" return equal(b, a);\n" +
" default:\n" +
" return JSON.stringify(a) === JSON.stringify(b)\n" +
" }\n" +
" }\n" +
" return JSON.stringify(a) === JSON.stringify(b)\n" +
"}\n" +
"\n" +
"\n" +
"function contains(sourceValue, compareValue) {\n" +
" var sourceValueType = Object.prototype.toString.call(sourceValue);\n" +
" var compareValueType = Object.prototype.toString.call(compareValue);\n" +
" if (sourceValueType === \"[object Object]\") {\n" +
" for (var i = 0; i < Object.keys(sourceValue).length; i++) {\n" +
" var souceKey = Object.keys(sourceValue)[i];\n" +
" if (equal(sourceValue[souceKey], compareValue)) {\n" +
" return true;\n" +
" };\n" +
" }\n" +
" return false;\n" +
" } else if (sourceValueType == \"[object Array]\") {\n" +
" switch (compareValueType) {\n" +
" //如果数组包含的话,需要a种全包含b种的参数,例如: [1,2,3]比[1,2]为true , [1,2,3]比[1,2,3,4]为false\n" +
" case \"[object Array]\":\n" +
" //如果compareValue的长度 大于 sourceValue 则一定不包含\n" +
" if (sourceValue.length < compareValue.length) {\n" +
" return false;\n" +
" }\n" +
" for (var i = 0; i < compareValue.length; i++) {\n" +
" var innerFlag = false;\n" +
" for (var j = 0; j < sourceValue.length; j++) {\n" +
" if (JSON.stringify(compareValue[i]) == JSON.stringify(sourceValue[j])) {\n" +
" innerFlag = true;\n" +
" break;\n" +
" }\n" +
" }\n" +
" if (!innerFlag) {\n" +
" return false;\n" +
" }\n" +
" }\n" +
" return true;\n" +
" case \"[object Object]\":\n" +
" for (var i = 0; i < sourceValue.length; i++) {\n" +
" if (JSON.stringify(sourceValue[i]) == JSON.stringify(compareValue) ) {\n" +
" return true;\n" +
" }\n" +
" }\n" +
" return false;\n" +
" default:\n" +
" return sourceValue.indexOf(compareValue)> -1 ? true : false;\n" +
" }\n" +
" return false;\n" +
" } else {\n" +
" return JSON.stringify(sourceValue).indexOf(JSON.stringify(compareValue)) > -1 ? true : false\n" +
" }\n" +
"\n" +
"}\n" +
"\n" +
"\n" +
"function BaseEntity(value) {\n" +
" this.type = Object.prototype.toString.call(value);\n" +
" if (this.type != '[object Object]' && this.type != '[object Array]') {\n" +
" try {\n" +
" this.value = JSON.parse(value);\n" +
" this.type = Object.prototype.toString.call(this.value);\n" +
" } catch (error) {\n" +
" this.value = value;\n" +
" }\n" +
" } else {\n" +
" this.value = value;\n" +
" }\n" +
"}\n" +
"\n" +
"BaseEntity.prototype.get = function (key) {\n" +
" return this.value[key]\n" +
"}\n" +
"\n" +
"BaseEntity.prototype.length = function (key) {\n" +
" return this.value.length\n" +
"}\n" +
"\n" +
"BaseEntity.prototype.contains = function (key) {\n" +
" if(key instanceof BaseEntity){\n" +
" return contains(this.value,key.value)\n" +
" }else{\n" +
" return contains(this.value,key)\n" +
" }\n" +
"}\n" +
"\n" +
"BaseEntity.prototype.equal = function (key) {\n" +
" if(key instanceof BaseEntity){\n" +
" return equal(this.value,key.value)\n" +
" }else{\n" +
" return equal(this.value,key)\n" +
" }\n" +
"}\n" +
"\n" +
"var a = new BaseEntity('{\"name\":1,\"age\":2}');\n" +
"var b = new BaseEntity('{\"name\":1,\"age\":3}');\n" +
"\n");
Object read = JsonPath.parse(json).read("$.store.book[0].price");
Object eval = jsEngine.eval(JSON.toJSONString(read) + ".length()");
} System.out.println("1");
} }
@Test @Test
void test(){ void test(){
String json = "{\n" + String json = "{\n" +
......
...@@ -37,21 +37,27 @@ class HttpClientActuatorTest { ...@@ -37,21 +37,27 @@ class HttpClientActuatorTest {
@Test @Test
void test(){ void test(){
JSONObject jsonObject = new JSONObject();
JSONObject stringValue = new JSONObject();
stringValue.put("account","hxh");
stringValue.put("password","hxh1234567");
jsonObject.put("url","http://127.0.0.1:8765/user/login");
jsonObject.put("method","POST");
jsonObject.put("requestType","JSON");
jsonObject.put("stringValue",JSONObject.toJSON(stringValue));
String json = "{\n" +
" \"url\": \"http://127.0.0.1:8080/test/tableName\",\n" + // String json = "{\n" +
" \"method\": \"GET\",\n" + // " \"url\": \"\",\n" +
" \"requestType\": \"QUERY\",\n" + // " \"method\": \"POST\",\n" +
" \"requestBodies\": [\n" + // " \"requestType\": \"JSON\",\n" +
" {\n" + // " \"stringValue\": \"{\n" +
" \"key\": \"tableName\",\n" + // " \"account\": \"string\",\n" +
" \"type\": \"TEXT\",\n" + // " \"password\": \"string\"\n" +
" \"value\": \"example\"\n" + // "}\""+
" }\n" + // "}";
" ]\n" + HttpRequestDetail httpRequestDetail1 = JSON.parseObject(JSONObject.toJSONString(jsonObject), HttpRequestDetail.class);
"}"; HttpRequestDetail httpRequestDetail = JSON.parseObject(JSONObject.toJSONString(jsonObject), HttpRequestDetail.class);
HttpRequestDetail httpRequestDetail1 = JSON.parseObject(json, HttpRequestDetail.class);
HttpRequestDetail httpRequestDetail = JSON.parseObject(json, HttpRequestDetail.class);
HttpResponseDetail httpResponseDetail = httpClientActuator.sendHttpRequest(httpRequestDetail,1l,1l); HttpResponseDetail httpResponseDetail = httpClientActuator.sendHttpRequest(httpRequestDetail,1l,1l);
System.out.println(httpResponseDetail); System.out.println(httpResponseDetail);
} }
......
...@@ -127,7 +127,7 @@ public class TestCaseController { ...@@ -127,7 +127,7 @@ public class TestCaseController {
for (TestData testData : testCaseData.getTestData()) { for (TestData testData : testCaseData.getTestData()) {
testData.setTestCaseId(id); testData.setTestCaseId(id);
} }
testDataBoolean = testDataService.saveBatch(testCaseData.getTestData()); testDataBoolean = testDataService.saveOrUpdateBatch(testCaseData.getTestData());
} }
if (testCaseData.getTestData().size() == 0) { if (testCaseData.getTestData().size() == 0) {
testDataBoolean = true; testDataBoolean = true;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论