Merge remote-tracking branch 'origin/v1.8' into v1.8
This commit is contained in:
commit
d7113c4c0c
|
@ -29,6 +29,7 @@ public class EsbDataStruct {
|
|||
private boolean required;
|
||||
private String description;
|
||||
private List<EsbDataStruct> children;
|
||||
private String status = "";
|
||||
|
||||
public void init(){
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
|
@ -127,6 +128,9 @@ public class EsbDataStruct {
|
|||
|
||||
if (element != null) {
|
||||
if (this.children == null || this.children.isEmpty()) {
|
||||
if(this.value == null ){
|
||||
this.value = "";
|
||||
}
|
||||
element.addText(this.value);
|
||||
} else {
|
||||
for (EsbDataStruct child : children) {
|
||||
|
|
|
@ -114,23 +114,26 @@ public class MsScenario extends MsTestElement {
|
|||
// 设置共享cookie
|
||||
config.setEnableCookieShare(enableCookieShare);
|
||||
Map<String, EnvironmentConfig> envConfig = new HashMap<>(16);
|
||||
// 兼容历史数据
|
||||
if (environmentMap == null || environmentMap.isEmpty()) {
|
||||
environmentMap = new HashMap<>(16);
|
||||
if (StringUtils.isNotBlank(environmentId)) {
|
||||
environmentMap.put(SessionUtils.getCurrentProjectId(), environmentId);
|
||||
}
|
||||
}
|
||||
if (environmentMap != null && !environmentMap.isEmpty()) {
|
||||
environmentMap.keySet().forEach(projectId -> {
|
||||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
||||
ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentMap.get(projectId));
|
||||
if (environment != null && environment.getConfig() != null) {
|
||||
EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
||||
envConfig.put(projectId, env);
|
||||
if (config.getConfig() == null) {
|
||||
// 兼容历史数据
|
||||
if (this.environmentMap == null || this.environmentMap.isEmpty()) {
|
||||
this.environmentMap = new HashMap<>(16);
|
||||
if (StringUtils.isNotBlank(environmentId)) {
|
||||
// 兼容1.8之前 没有environmentMap但有environmentId的数据
|
||||
this.environmentMap.put("historyProjectID", environmentId);
|
||||
}
|
||||
});
|
||||
config.setConfig(envConfig);
|
||||
}
|
||||
if (this.environmentMap != null && !this.environmentMap.isEmpty()) {
|
||||
this.environmentMap.keySet().forEach(projectId -> {
|
||||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
||||
ApiTestEnvironmentWithBLOBs environment = environmentService.get(this.environmentMap.get(projectId));
|
||||
if (environment != null && environment.getConfig() != null) {
|
||||
EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
||||
envConfig.put(projectId, env);
|
||||
}
|
||||
});
|
||||
config.setConfig(envConfig);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(this.getVariables())) {
|
||||
config.setVariables(this.variables);
|
||||
|
|
|
@ -129,6 +129,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
config.setConfig(getEnvironmentConfig(useEnvironment));
|
||||
}
|
||||
|
||||
// 1.8 之前历史数据
|
||||
if(StringUtils.isEmpty(this.getProjectId()) && config.getConfig()!= null && !config.getConfig().isEmpty()){
|
||||
this.setProjectId("historyProjectID");
|
||||
}
|
||||
|
||||
// 添加环境中的公共变量
|
||||
Arguments arguments = this.addArguments(config);
|
||||
if (arguments != null) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.api.dto.definition.request.sampler;
|
|||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
|
||||
|
@ -70,6 +71,12 @@ public class MsTCPSampler extends MsTestElement {
|
|||
@JSONField(ordinal = 39)
|
||||
private String projectId;
|
||||
|
||||
/**
|
||||
* 新加两个参数,场景保存/修改时需要的参数。不会传递JMeter,只是用于最后的保留。
|
||||
*/
|
||||
private List<EsbDataStruct> esbDataStruct;
|
||||
private List<EsbDataStruct> backEsbDataStruct;
|
||||
|
||||
@Override
|
||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
|
||||
// 非导出操作,且不是启用状态则跳过执行
|
||||
|
|
|
@ -90,6 +90,8 @@ public class ApiAutomationService {
|
|||
@Resource
|
||||
@Lazy
|
||||
private TestPlanScenarioCaseService testPlanScenarioCaseService;
|
||||
@Resource
|
||||
private EsbApiParamService esbApiParamService;
|
||||
|
||||
public List<ApiScenarioDTO> list(ApiScenarioRequest request) {
|
||||
request = this.initRequest(request, true, true);
|
||||
|
@ -184,6 +186,9 @@ public class ApiAutomationService {
|
|||
scenario.setCreateTime(System.currentTimeMillis());
|
||||
scenario.setNum(getNextNum(request.getProjectId()));
|
||||
|
||||
//检查场景的请求步骤。如果含有ESB请求步骤的话,要做参数计算处理。
|
||||
esbApiParamService.checkScenarioRequests(request);
|
||||
|
||||
apiScenarioMapper.insert(scenario);
|
||||
|
||||
List<String> bodyUploadIds = request.getBodyUploadIds();
|
||||
|
@ -205,6 +210,9 @@ public class ApiAutomationService {
|
|||
List<String> bodyUploadIds = request.getBodyUploadIds();
|
||||
FileUtils.createBodyFiles(bodyUploadIds, bodyFiles);
|
||||
|
||||
//检查场景的请求步骤。如果含有ESB请求步骤的话,要做参数计算处理。
|
||||
esbApiParamService.checkScenarioRequests(request);
|
||||
|
||||
final ApiScenarioWithBLOBs scenario = buildSaveScenario(request);
|
||||
apiScenarioMapper.updateByPrimaryKeySelective(scenario);
|
||||
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务
|
||||
|
|
|
@ -3,11 +3,13 @@ package io.metersphere.api.service;
|
|||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||
import io.metersphere.api.dto.automation.SaveApiScenarioRequest;
|
||||
import io.metersphere.api.dto.automation.parse.EsbDataParser;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseResult;
|
||||
import io.metersphere.api.dto.definition.SaveApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.SaveApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
|
@ -313,6 +315,35 @@ public class EsbApiParamService {
|
|||
return keyValueList;
|
||||
}
|
||||
|
||||
private List<KeyValue> genKeyValueListByDataStruct(MsTCPSampler tcpSampler, List<EsbDataStruct> dataStructRequestList) {
|
||||
List<KeyValue> keyValueList = new ArrayList<>();
|
||||
String sendRequest = tcpSampler.getRequest();
|
||||
String paramRegexStr = "\\$\\{([^}]*)\\}";
|
||||
try {
|
||||
if (StringUtils.isNotEmpty(sendRequest)) {
|
||||
List<String> paramList = new ArrayList<>();
|
||||
Pattern regex = Pattern.compile(paramRegexStr);
|
||||
Matcher matcher = regex.matcher(sendRequest);
|
||||
while (matcher.find()) {
|
||||
paramList.add(matcher.group(1));
|
||||
}
|
||||
for (String param : paramList) {
|
||||
String value = this.genValueFromEsbDataStructByParam(dataStructRequestList, param);
|
||||
if (StringUtils.isNotEmpty(value)) {
|
||||
KeyValue kv = new KeyValue();
|
||||
kv.setName(param);
|
||||
kv.setValue(value);
|
||||
kv.setRequired(true);
|
||||
keyValueList.add(kv);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return keyValueList;
|
||||
}
|
||||
|
||||
//通过报文模版中的变量参数,解析报文数据结构,生成对应的xml数据
|
||||
private String genValueFromEsbDataStructByParam(List<EsbDataStruct> dataStructRequestList, String param) {
|
||||
String returnValue = "";
|
||||
|
@ -341,10 +372,32 @@ public class EsbApiParamService {
|
|||
return request;
|
||||
}
|
||||
|
||||
public void handleEsbRequest(MsTCPSampler tcpSampler) {
|
||||
try {
|
||||
//修改reqeust.parameters, 将树结构类型数据转化为表格类型数据,供执行时参数的提取
|
||||
if (tcpSampler.getEsbDataStruct() != null ) {
|
||||
List<KeyValue> keyValueList = this.genKeyValueListByDataStruct(tcpSampler, tcpSampler.getEsbDataStruct());
|
||||
tcpSampler.setParameters(keyValueList);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteByResourceIdIn(List<String> apiIds) {
|
||||
EsbApiParamsExample example = new EsbApiParamsExample();
|
||||
example.createCriteria().andResourceIdIn(apiIds);
|
||||
esbApiParamsMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void checkScenarioRequests(SaveApiScenarioRequest request) {
|
||||
if(request.getScenarioDefinition() != null ){
|
||||
List<MsTestElement> hashTreeList = request.getScenarioDefinition().getHashTree();
|
||||
for (MsTestElement testElement :hashTreeList) {
|
||||
if(testElement instanceof MsTCPSampler){
|
||||
this.handleEsbRequest((MsTCPSampler)testElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,12 +76,17 @@ public class HistoricalDataUpgradeService {
|
|||
return scenario;
|
||||
}
|
||||
|
||||
private MsScenario createScenario(Scenario oldScenario) {
|
||||
private MsScenario createScenario(Scenario oldScenario, String projectId) {
|
||||
MsScenario scenario = new MsScenario();
|
||||
scenario.setOldVariables(oldScenario.getVariables());
|
||||
scenario.setName(oldScenario.getName());
|
||||
scenario.setEnableCookieShare(oldScenario.isEnableCookieShare());
|
||||
scenario.setEnvironmentId(oldScenario.getEnvironmentId());
|
||||
if (StringUtils.isNotEmpty(oldScenario.getEnvironmentId())) {
|
||||
HashMap<String, String> envMap = new HashMap<>();
|
||||
envMap.put(projectId, oldScenario.getEnvironmentId());
|
||||
scenario.setEnvironmentMap(envMap);
|
||||
}
|
||||
scenario.setReferenced("Upgrade");
|
||||
scenario.setId(oldScenario.getId());
|
||||
scenario.setResourceId(UUID.randomUUID().toString());
|
||||
|
@ -397,6 +402,7 @@ public class HistoricalDataUpgradeService {
|
|||
MsScenario scenarioTest = createScenarioByTest(test);
|
||||
LinkedList<MsTestElement> listSteps = new LinkedList<>();
|
||||
List<Scenario> scenarios = JSON.parseArray(test.getScenarioDefinition(), Scenario.class);
|
||||
String envId = null;
|
||||
if (CollectionUtils.isNotEmpty(scenarios)) {
|
||||
// 批量处理
|
||||
for (Scenario scenario : scenarios) {
|
||||
|
@ -405,7 +411,7 @@ public class HistoricalDataUpgradeService {
|
|||
}
|
||||
scenario.setId(test.getId() + "=" + scenario.getId());
|
||||
scenario.setName(test.getName() + "_" + scenario.getName());
|
||||
MsScenario scenario1 = createScenario(scenario);
|
||||
MsScenario scenario1 = createScenario(scenario, saveHistoricalDataUpgrade.getProjectId());
|
||||
String scenarioDefinition = JSON.toJSONString(scenario1);
|
||||
num++;
|
||||
createApiScenarioWithBLOBs(saveHistoricalDataUpgrade, scenario.getId(), scenario.getName(), scenario.getRequests().size(), scenarioDefinition, mapper, num);
|
||||
|
@ -417,10 +423,20 @@ public class HistoricalDataUpgradeService {
|
|||
step.setResourceId(UUID.randomUUID().toString());
|
||||
step.setReferenced("REF");
|
||||
listSteps.add(step);
|
||||
if (StringUtils.isNotEmpty(scenario.getEnvironmentId())) {
|
||||
envId = scenario.getEnvironmentId();
|
||||
}
|
||||
}
|
||||
}
|
||||
num++;
|
||||
scenarioTest.setHashTree(listSteps);
|
||||
if (StringUtils.isNotEmpty(envId)) {
|
||||
HashMap<String, String> envMap = new HashMap<>();
|
||||
envMap.put(saveHistoricalDataUpgrade.getProjectId(), envId);
|
||||
scenarioTest.setEnvironmentMap(envMap);
|
||||
scenarioTest.setEnvironmentId(envId);
|
||||
}
|
||||
|
||||
String scenarioDefinition = JSON.toJSONString(scenarioTest);
|
||||
createApiScenarioWithBLOBs(saveHistoricalDataUpgrade, scenarioTest.getId(), scenarioTest.getName(), listSteps.size(), scenarioDefinition, mapper, num);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
import MsAsideContainer from "@/business/components/common/components/MsAsideContainer";
|
||||
import MsMainContainer from "@/business/components/common/components/MsMainContainer";
|
||||
import MsApiScenarioList from "@/business/components/api/automation/scenario/ApiScenarioList";
|
||||
import {getUUID, downloadFile, checkoutTestManagerOrTestUser} from "@/common/js/utils";
|
||||
import {getUUID, downloadFile, checkoutTestManagerOrTestUser,getCurrentUser} from "@/common/js/utils";
|
||||
import MsApiScenarioModule from "@/business/components/api/automation/scenario/ApiScenarioModule";
|
||||
import MsEditApiScenario from "./scenario/EditApiScenario";
|
||||
|
||||
|
@ -189,6 +189,7 @@
|
|||
let name = getUUID().substring(0, 8);
|
||||
this.activeName = name;
|
||||
let currentScenario = {
|
||||
status: "Underway", principal: getCurrentUser().id,
|
||||
apiScenarioModuleId: "root", id: getUUID(),
|
||||
modulePath: "/" + this.$t("commons.module_title")
|
||||
};
|
||||
|
|
|
@ -101,25 +101,25 @@ export default {
|
|||
|
||||
let requestObj = JSON.parse(item.request);
|
||||
if(requestObj.esbDataStruct != null ){
|
||||
//ESB接口
|
||||
let param = {};
|
||||
param.request = requestObj;
|
||||
param.method = "ESB";
|
||||
param.esbDataStruct = JSON.stringify(requestObj.esbDataStruct);
|
||||
if(requestObj.backEsbDataStruct != null){
|
||||
param.backEsbDataStruct = JSON.stringify(requestObj.backEsbDataStruct);
|
||||
}else{
|
||||
param.backEsbDataStruct = "";
|
||||
}
|
||||
// //ESB接口
|
||||
// let param = {};
|
||||
// param.request = requestObj;
|
||||
// param.method = "ESB";
|
||||
// param.esbDataStruct = JSON.stringify(requestObj.esbDataStruct);
|
||||
// if(requestObj.backEsbDataStruct != null){
|
||||
// param.backEsbDataStruct = JSON.stringify(requestObj.backEsbDataStruct);
|
||||
// }else{
|
||||
// param.backEsbDataStruct = "";
|
||||
// }
|
||||
|
||||
this.$post("/api/definition/updateEsbRequest", param, response => {
|
||||
if(response.data!=null){
|
||||
if(response.data.request!=null){
|
||||
item.request = JSON.stringify(response.data.request);
|
||||
param.method = "TCP";
|
||||
}
|
||||
}
|
||||
})
|
||||
// this.$post("/api/definition/updateEsbRequest", param, response => {
|
||||
// if(response.data!=null){
|
||||
// if(response.data.request!=null){
|
||||
// item.request = JSON.stringify(response.data.request);
|
||||
// param.method = "TCP";
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
}
|
||||
});
|
||||
this.$emit('save', apiCases, 'CASE', reference);
|
||||
|
|
|
@ -28,9 +28,12 @@
|
|||
<div class="header-right" @click.stop>
|
||||
<slot name="message"></slot>
|
||||
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top" v-if="showBtn">
|
||||
<el-switch v-model="data.enable" class="enable-switch" size="mini" :disabled="data.disabled && !data.root"/>
|
||||
<el-switch v-model="data.enable" class="enable-switch" size="mini" :disabled="data.disabled && !data.root" style="width: 30px"/>
|
||||
</el-tooltip>
|
||||
<slot name="button"></slot>
|
||||
<el-tooltip content="Copy" placement="top">
|
||||
<el-button size="mini" icon="el-icon-copy-document" circle @click="copyRow" style="padding: 5px"/>
|
||||
</el-tooltip>
|
||||
<step-extend-btns style="display: contents" :data="data" @copy="copyRow" @remove="remove" @openScenario="openScenario" v-if="showBtn && (!data.disabled || data.root)"/>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
<template v-slot:button>
|
||||
<el-tooltip :content="$t('api_test.run')" placement="top">
|
||||
<el-button @click="run" icon="el-icon-video-play" class="ms-btn" size="mini" circle/>
|
||||
<el-button @click="run" icon="el-icon-video-play" style="padding: 5px" class="ms-btn" size="mini" circle/>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
|
||||
|
@ -289,6 +289,9 @@
|
|||
},
|
||||
active(item) {
|
||||
this.request.active = !this.request.active;
|
||||
if (this.node) {
|
||||
this.node.expanded = this.request.active;
|
||||
}
|
||||
this.reload();
|
||||
},
|
||||
run() {
|
||||
|
|
|
@ -105,11 +105,11 @@
|
|||
remove() {
|
||||
this.$emit('remove', this.scenario, this.node);
|
||||
},
|
||||
active(item) {
|
||||
if (item && item.active) {
|
||||
item.active = !item.active;
|
||||
active() {
|
||||
if (this.node) {
|
||||
this.node.expanded = !this.node.expanded;
|
||||
}
|
||||
this.reload();
|
||||
}
|
||||
},
|
||||
copyRow() {
|
||||
this.$emit('copyRow', this.scenario, this.node);
|
||||
|
|
|
@ -61,6 +61,9 @@
|
|||
},
|
||||
active() {
|
||||
this.request.active = !this.request.active;
|
||||
if (this.node) {
|
||||
this.node.expanded = this.request.active;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
</template>
|
||||
|
||||
<template v-slot:button>
|
||||
<el-button @click="runDebug" :tip="$t('api_test.run')" icon="el-icon-video-play" style="background-color: #409EFF;color: white;" size="mini" circle/>
|
||||
<el-button @click="runDebug" :tip="$t('api_test.run')" icon="el-icon-video-play" style="background-color: #409EFF;color: white;padding: 5px" size="mini" circle/>
|
||||
</template>
|
||||
<div v-if="controller.loopType==='LOOP_COUNT'" draggable>
|
||||
<el-row>
|
||||
|
@ -246,6 +246,9 @@
|
|||
},
|
||||
active(item) {
|
||||
item.active = !item.active;
|
||||
if (this.node) {
|
||||
this.node.expanded = item.active;
|
||||
}
|
||||
this.reload();
|
||||
},
|
||||
changeRadio() {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<el-icon class="el-icon-more"></el-icon>
|
||||
</el-link>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="copy">复制步骤</el-dropdown-item>
|
||||
<!--<el-dropdown-item command="copy">复制步骤</el-dropdown-item>-->
|
||||
<el-dropdown-item command="remove" v-tester>删除步骤</el-dropdown-item>
|
||||
<el-dropdown-item command="scenarioVar" v-tester v-if="data.type==='scenario'">查看场景变量</el-dropdown-item>
|
||||
<el-dropdown-item command="openScenario" v-tester v-if="data.type==='scenario' && data.referenced==='REF'">打开场景</el-dropdown-item>
|
||||
|
|
|
@ -68,8 +68,8 @@
|
|||
|
||||
let projectId = "";
|
||||
// 如果envMap不存在,是单接口调用
|
||||
if (!this.envMap) {
|
||||
projectId = getCurrentProjectID();
|
||||
if (!this.envMap || this.envMap.size === 0) {
|
||||
projectId = this.$store.state.projectId;
|
||||
} else {
|
||||
// 场景步骤下接口调用
|
||||
projectId = this.runData.projectId;
|
||||
|
|
|
@ -178,6 +178,10 @@
|
|||
<div v-else-if="apiInfo.requestBodyParamType == 'JSON-SCHEMA'" style="margin-left: 10px">
|
||||
<ms-json-code-edit :body="apiInfo.jsonSchemaBody" ref="jsonCodeEdit"/>
|
||||
</div>
|
||||
<!-- <div v-else-if="apiInfo.requestBodyParamType == 'XML'" style="margin-left: 10px">-->
|
||||
<!-- <ms-json-code-edit :body="apiInfo.jsonSchemaBody" ref="jsonCodeEdit"/>-->
|
||||
<!-- <editor v-model="formatData" :lang="mode" @init="editorInit" :theme="theme" :height="height"/>-->
|
||||
<!-- </div>-->
|
||||
<div v-else class="showDataDiv">
|
||||
<br/>
|
||||
<p style="margin: 0px 20px;"
|
||||
|
@ -423,7 +427,12 @@ export default {
|
|||
formatRowData(dataType, data) {
|
||||
var returnData = data;
|
||||
if (data) {
|
||||
returnData = data.replace(/\n/g, '<br>');
|
||||
|
||||
if(dataType === 'XML'){
|
||||
returnData = "<xmp>"+returnData+"</xmp>";
|
||||
}else{
|
||||
returnData = data.replace(/\n/g, '<br>');
|
||||
}
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue