提交 e3717b47 authored 作者: Matrix's avatar Matrix

fix(base): 重新配置了映射路径

上级 e344839e
......@@ -13,10 +13,13 @@ import org.matrix.actuators.sql.SqlExpDetail;
import org.matrix.actuators.usecase.CaseActuator;
import org.matrix.actuators.util.CompleteExpressionUtil;
import org.matrix.database.entity.Action;
import org.matrix.database.entity.Move;
import org.matrix.database.entity.TestCaseBTO;
import org.matrix.database.service.IMoveService;
import org.matrix.database.service.ITestDataService;
import org.matrix.database.service.impl.ActionServiceImpl;
import org.matrix.enums.ActionType;
import org.matrix.enums.MoveType;
import org.matrix.exception.GlobalException;
import org.matrix.socket.queue.LogQueueRuntime;
import org.matrix.util.BeanFlattener;
......@@ -55,6 +58,7 @@ public class MoveActuator implements Actuator {
private final SqlExpActuator sqlExpActuator;
private final HttpClientActuator httpActuator;
private final ITestDataService dataService;
private final IMoveService moveService;
private final CaseActuator caseActuator;
private final CompleteExpressionUtil expressionUtil;
/**
......@@ -62,12 +66,13 @@ public class MoveActuator implements Actuator {
*/
private ThreadLocal<Map<String, List<Map<String, Object>>>> resSet = ThreadLocal.withInitial(HashMap::new);
public MoveActuator(CompleteExpressionUtil resultUtil, ActionServiceImpl actionService, SqlExpActuator sqlExpActuator, HttpClientActuator httpActuator, ITestDataService dataService, CaseActuator caseActuator, CompleteExpressionUtil expressionUtil) {
public MoveActuator(CompleteExpressionUtil resultUtil, ActionServiceImpl actionService, SqlExpActuator sqlExpActuator, HttpClientActuator httpActuator, ITestDataService dataService, IMoveService moveService, CaseActuator caseActuator, CompleteExpressionUtil expressionUtil) {
this.resultUtil = resultUtil;
this.actionService = actionService;
this.sqlExpActuator = sqlExpActuator;
this.httpActuator = httpActuator;
this.dataService = dataService;
this.moveService = moveService;
this.caseActuator = caseActuator;
this.expressionUtil = expressionUtil;
}
......@@ -135,7 +140,7 @@ public class MoveActuator implements Actuator {
if (pathResolution) {
finalValue = expressionUtil.completeJsonPathExpression(jsonPath, finalValue);
}
LogQueueRuntime.addNewLog(this.getClass(),SYNTAX_PARSE, String.format("初始语法 = %s ,解析结果 = %s",dynamicString,finalValue));
LogQueueRuntime.addNewLog(this.getClass(), SYNTAX_PARSE, String.format("初始语法 = %s ,解析结果 = %s", dynamicString, finalValue));
return finalValue;
}
......@@ -152,7 +157,11 @@ public class MoveActuator implements Actuator {
* @param caseResultData 测试用例执行后保留下的结果集,该参数在前置策略中可以为null,在中间/后置策略中必须要提供合理的结果集对象
* @param strategy 动作的策略,即是前置/中间/后置,具体查看{@link MoveStrategy}
*/
@SuppressWarnings("DuplicatedCode")
public void runMove(Long moveId, Long envId, Long projectId, String caseResultData, MoveStrategy strategy) {
Move move = Optional.ofNullable(moveService.getById(moveId))
.orElseThrow(() -> new GlobalException(String.format("没有找到指定的action动作对象,提供查询的moveId = %d,envId = %d", moveId, envId)));
Action action = actionService.findByMoveAndEnv(moveId, envId)
.orElseThrow(() -> new GlobalException(String.format("没有找到指定的action动作对象,提供查询的moveId = %d,envId = %d", moveId, envId)));
LogQueueRuntime.addNewLog(this.getClass(), MOVE_ACTUATOR, String.format("准备执行行为动作,动作策略: %s,行为Id =%d ,动作id = %d", strategy, moveId, action.getId()));
......@@ -176,26 +185,49 @@ public class MoveActuator implements Actuator {
Map<String, List<Map<String, Object>>> res = resSet.get();
// 分类处理 + 结果集处理(如果不存在则put数据,如果存在则替换数据)
LogQueueRuntime.addNewLog(this.getClass(),MOVE_ACTUATOR, String.format("正在执行动作 actionId = %d,动作类型 = %s,动作策略 = %s,动作参数 = %s", action.getId(), action, strategy, runtimeDetail));
LogQueueRuntime.addNewLog(this.getClass(), MOVE_ACTUATOR, String.format("正在执行动作 actionId = %d,动作类型 = %s,动作策略 = %s,动作参数 = %s", action.getId(), action, strategy, runtimeDetail));
if (actionType == SQL_ACTION) {
List<Map<String, Object>> resultMap = sqlActionHandler(envId, projectId, runtimeDetail);
res.put(key, resultMap);
} else if (actionType == HTTP_ACTION) {
res.put(key, Lists.newArrayList(detail2Map(httpActionHandler(envId, projectId, runtimeDetail))));
HttpResponseDetail detail = httpActionHandler(envId, projectId, runtimeDetail);
Map<String, Object> detailMap = detail2Map(detail);
moveTypeHandler(strategy, move, detail, detailMap);
res.put(key, Lists.newArrayList(detailMap));
} else if (actionType == CASE_ACTION) {
res.put(key, Lists.newArrayList(detail2Map(caseActionHandler(envId, projectId, runtimeDetail))));
HttpResponseDetail detail = caseActionHandler(envId, projectId, runtimeDetail);
Map<String, Object> detailMap = detail2Map(detail);
moveTypeHandler(strategy, move, detail, detailMap);
res.put(key, Lists.newArrayList(detailMap));
} else if (actionType == WAIT_ACTION) {
waitActionHandler(runtimeDetail);
} else {
throw new GlobalException("[行为执行器]不支持的行为类型: " + actionType);
}
// 如果动作类型时登录且是前置动作,设置COOKIE到变量池中
LogQueueRuntime.addNewLog(getClass(),MOVE_ACTUATOR, String.format(
"当前执行的行为策略 = %s, 行为名 = %s, 动作名 = %s , 动作id = %d , 动作池里的变量 = %s",
strategy.getDes(),move.getName(),action.getName(),action.getId(),res));
log.info("[动作执行器] 动作执行完毕");
}
/**
* 依据行为的动作类型来决定操作逻辑
*
* @param strategy 行为策略
* @param move 行为
* @param detail 动作执行后的返回值对象
* @param detailMap 用于存放到动作结果池里的Map
*/
private void moveTypeHandler(MoveStrategy strategy, Move move, HttpResponseDetail detail, Map<String, Object> detailMap) {
if (strategy == PRE_MOVE && move.getMoveType() == MoveType.LOGIN) {
Arrays.stream(detail.getResponse().getHeaders("SET_COOKIE"))
.filter(header -> header.getValue().contains("JSESSIONID"))
.findFirst()
.ifPresent(session -> detailMap.put("SESSION_ID", session));
}
}
/**
* 清理结果集
*/
......@@ -242,7 +274,7 @@ public class MoveActuator implements Actuator {
throw new GlobalException("[行为执行器]行为语法里定位部分的语法没有提供合适的actionId!例如需要提供pre1,pre2,您提供的部分是: " + col);
}
String key = strategy + "_" + actionId;
LogQueueRuntime.addNewLog(this.getClass(),MOVE_ACTUATOR, "KEY值拼接完成,KEY值 = " + key);
LogQueueRuntime.addNewLog(this.getClass(), MOVE_ACTUATOR, "KEY值拼接完成,KEY值 = " + key);
return new MoveRegularObject(key, colArray[1]);
}
......
package org.matrix.actuators.move;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* MoveStrategy.
*
......@@ -7,18 +10,22 @@ package org.matrix.actuators.move;
* @since 2022/3/7 at 3:11 PM
* Suffering is the most powerful teacher of life.
*/
@AllArgsConstructor
@Getter
public enum MoveStrategy {
/**
* 前置动作
*/
PRE_MOVE,
PRE_MOVE("前置动作"),
/**
* 中间动作
*/
MID_MOVE,
MID_MOVE("中间动作"),
/**
* 后置动作
*/
AFT_MOVE;
AFT_MOVE("后置动作");
private final String des;
}
......@@ -15,7 +15,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
public class ResourcesConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//localhost:8765/res/css/bootstrap.css
String fileUrl = "file:" + System.getProperty("user.dir") + "/htmls/";
registry.addResourceHandler("/**").addResourceLocations(fileUrl);
registry.addResourceHandler("/res/**").addResourceLocations(fileUrl);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论