refactor(接口测试): 执行步骤重新排序
This commit is contained in:
parent
bf6a0a1900
commit
8e2ddf0e5b
|
@ -76,7 +76,7 @@ public class ElementUtil {
|
|||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
||||
ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId);
|
||||
if (environment != null && environment.getConfig() != null) {
|
||||
if(StringUtils.isEmpty(projectId)){
|
||||
if (StringUtils.isEmpty(projectId)) {
|
||||
projectId = environment.getProjectId();
|
||||
}
|
||||
if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) {
|
||||
|
@ -631,4 +631,55 @@ public class ElementUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final List<String> preOperates = new ArrayList<String>() {{
|
||||
this.add("JSR223PreProcessor");
|
||||
this.add("JDBCPreProcessor");
|
||||
this.add("ConstantTimer");
|
||||
}};
|
||||
private static final List<String> postOperates = new ArrayList<String>() {{
|
||||
this.add("JSR223PostProcessor");
|
||||
this.add("JDBCPostProcessor");
|
||||
this.add("Extract");
|
||||
}};
|
||||
|
||||
public static List<MsTestElement> order(List<MsTestElement> elements) {
|
||||
List<MsTestElement> elementList = new LinkedList<>();
|
||||
if (CollectionUtils.isNotEmpty(elements)) {
|
||||
Map<String, List<MsTestElement>> groupMap = new LinkedHashMap<>();
|
||||
elements.forEach(item -> {
|
||||
if ("Assertions".equals(item.getType())) {
|
||||
if (groupMap.containsKey("Assertions")) {
|
||||
groupMap.get("Assertions").add(item);
|
||||
} else {
|
||||
groupMap.put("Assertions", new LinkedList<MsTestElement>() {{
|
||||
this.add(item);
|
||||
}});
|
||||
}
|
||||
} else if (preOperates.contains(item.getType())) {
|
||||
if (groupMap.containsKey("PreOperate")) {
|
||||
groupMap.get("PreOperate").add(item);
|
||||
} else {
|
||||
groupMap.put("PreOperate", new LinkedList<MsTestElement>() {{
|
||||
this.add(item);
|
||||
}});
|
||||
}
|
||||
} else if (postOperates.contains(item.getType())) {
|
||||
if (groupMap.containsKey("PostOperate")) {
|
||||
groupMap.get("PostOperate").add(item);
|
||||
} else {
|
||||
groupMap.put("PostOperate", new LinkedList<MsTestElement>() {{
|
||||
this.add(item);
|
||||
}});
|
||||
}
|
||||
} else {
|
||||
elementList.add(item);
|
||||
}
|
||||
});
|
||||
elementList.addAll(groupMap.get("PreOperate").stream().sorted(Comparator.comparing(MsTestElement::getIndex)).collect(Collectors.toList()));
|
||||
elementList.addAll(groupMap.get("PostOperate").stream().sorted(Comparator.comparing(MsTestElement::getIndex)).collect(Collectors.toList()));
|
||||
elementList.addAll(groupMap.get("Assertions").stream().sorted(Comparator.comparing(MsTestElement::getIndex)).collect(Collectors.toList()));
|
||||
}
|
||||
return elementList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class MsJSR223Processor extends MsTestElement {
|
|||
script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID, "\"" + RunningParamKeys.RUNNING_PARAMS_PREFIX + this.getEnvironmentId() + ".\"");
|
||||
|
||||
if (config.isOperating()) {
|
||||
if (script.startsWith("io.metersphere.utils.JMeterVars.addVars")) {
|
||||
if (StringUtils.isNotEmpty(script) && script.startsWith("io.metersphere.utils.JMeterVars.addVars")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class MsJSR223PostProcessor extends MsTestElement {
|
|||
script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID, "\"" + RunningParamKeys.RUNNING_PARAMS_PREFIX + this.getEnvironmentId() + ".\"");
|
||||
|
||||
if(config.isOperating()){
|
||||
if (script.startsWith("io.metersphere.utils.JMeterVars.addVars")) {
|
||||
if (StringUtils.isNotEmpty(script) && script.startsWith("io.metersphere.utils.JMeterVars.addVars")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class MsJSR223PreProcessor extends MsTestElement {
|
|||
script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID, "\"" + RunningParamKeys.RUNNING_PARAMS_PREFIX + this.getEnvironmentId() + ".\"");
|
||||
}
|
||||
if (config.isOperating()) {
|
||||
if (script.startsWith(JMeterVars.class.getCanonicalName())) {
|
||||
if (StringUtils.isNotEmpty(script) && script.startsWith(JMeterVars.class.getCanonicalName())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ public class MsDubboSampler extends MsTestElement {
|
|||
|
||||
final HashTree testPlanTree = tree.add(dubboSample(config));
|
||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||
hashTree = ElementUtil.order(hashTree);
|
||||
hashTree.forEach(el -> {
|
||||
el.toHashTree(testPlanTree, el.getHashTree(), config);
|
||||
});
|
||||
|
|
|
@ -255,6 +255,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||
hashTree = ElementUtil.order(hashTree);
|
||||
for (MsTestElement el : hashTree) {
|
||||
if (el.getEnvironmentId() == null) {
|
||||
if (this.getEnvironmentId() == null) {
|
||||
|
@ -683,22 +684,22 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
list.stream().
|
||||
filter(KeyValue::isValid).
|
||||
filter(KeyValue::isEnable).forEach(keyValue -> {
|
||||
try {
|
||||
String value = StringUtils.isNotEmpty(keyValue.getValue()) && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue();
|
||||
HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), value);
|
||||
if (keyValue.getValue() == null) {
|
||||
httpArgument.setValue("");
|
||||
}
|
||||
httpArgument.setAlwaysEncoded(keyValue.isUrlEncode());
|
||||
if (StringUtils.isNotBlank(keyValue.getContentType())) {
|
||||
httpArgument.setContentType(keyValue.getContentType());
|
||||
}
|
||||
arguments.addArgument(httpArgument);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
try {
|
||||
String value = StringUtils.isNotEmpty(keyValue.getValue()) && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue();
|
||||
HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), value);
|
||||
if (keyValue.getValue() == null) {
|
||||
httpArgument.setValue("");
|
||||
}
|
||||
);
|
||||
httpArgument.setAlwaysEncoded(keyValue.isUrlEncode());
|
||||
if (StringUtils.isNotBlank(keyValue.getContentType())) {
|
||||
httpArgument.setContentType(keyValue.getContentType());
|
||||
}
|
||||
arguments.addArgument(httpArgument);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
return arguments;
|
||||
}
|
||||
|
||||
|
|
|
@ -172,6 +172,7 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
JMeterScriptUtil.setScriptByEnvironmentConfig(envConfig, samplerHashTree, GlobalScriptFilterRequest.JDBC.name(), environmentId, config, false);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||
hashTree = ElementUtil.order(hashTree);
|
||||
hashTree.forEach(el -> {
|
||||
el.toHashTree(samplerHashTree, el.getHashTree(), config);
|
||||
});
|
||||
|
|
|
@ -169,6 +169,7 @@ public class MsTCPSampler extends MsTestElement {
|
|||
HashTreeUtil hashTreeUtil = new HashTreeUtil();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||
hashTree = ElementUtil.order(hashTree);
|
||||
EnvironmentConfig finalEnvConfig = envConfig;
|
||||
hashTree.forEach(el -> {
|
||||
if (el instanceof MsAssertions) {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
:value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-button size="mini" @click="add" type="primary" v-if="tabType !== 'assertionsRule'">
|
||||
<el-button size="mini" @click="add" type="primary" v-if="tabType !== 'assertionsRule'" :disabled="request.disabled">
|
||||
{{ $t('api_test.request.assertions.add') }}
|
||||
</el-button>
|
||||
</p>
|
||||
|
@ -340,6 +340,7 @@ export default {
|
|||
copyRow(row) {
|
||||
let obj = JSON.parse(JSON.stringify(row));
|
||||
obj.id = getUUID();
|
||||
obj.resourceId = getUUID();
|
||||
const index = this.request.hashTree.findIndex(d => d.id === row.id);
|
||||
if (index !== -1) {
|
||||
this.request.hashTree.splice(index, 0, obj);
|
||||
|
|
Loading…
Reference in New Issue