fix(接口测试): 修复多版本情况下场景引用复制问题
--bug=1009777 --user=赵勇 【接口自动化】-场景A中引用v1版本的场景B,删除场景B后场景A仍成功执行引用的场景B https://www.tapd.cn/55049933/s/1094931
This commit is contained in:
parent
3baef16d16
commit
4f6f06108f
|
@ -70,7 +70,7 @@ public class ApiAutomationController {
|
|||
|
||||
@PostMapping("/list/all")
|
||||
@RequiresPermissions("PROJECT_API_SCENARIO:READ")
|
||||
public List<ApiScenarioWithBLOBs> listAll(@RequestBody ApiScenarioBatchRequest request) {
|
||||
public List<ApiScenarioDTO> listAll(@RequestBody ApiScenarioBatchRequest request) {
|
||||
return apiAutomationService.listAll(request);
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ public class ApiAutomationController {
|
|||
}
|
||||
|
||||
@PostMapping("/getApiScenarios")
|
||||
public List<ApiScenarioWithBLOBs> getApiScenarios(@RequestBody List<String> ids) {
|
||||
public List<ApiScenarioDTO> getApiScenarios(@RequestBody List<String> ids) {
|
||||
return apiAutomationService.getApiScenarios(ids);
|
||||
}
|
||||
|
||||
|
|
|
@ -495,6 +495,75 @@ public class ElementUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static void mergeHashTree(JSONObject element, JSONArray targetHashTree) {
|
||||
try {
|
||||
JSONArray sourceHashTree = element.getJSONArray("hashTree");
|
||||
if (CollectionUtils.isNotEmpty(sourceHashTree) && CollectionUtils.isNotEmpty(targetHashTree) && sourceHashTree.size() < targetHashTree.size()) {
|
||||
element.put("hashTree", targetHashTree);
|
||||
return;
|
||||
}
|
||||
List<String> sourceIds = new ArrayList<>();
|
||||
List<String> delIds = new ArrayList<>();
|
||||
Map<String, JSONObject> updateMap = new HashMap<>();
|
||||
if (CollectionUtils.isEmpty(sourceHashTree)) {
|
||||
if (CollectionUtils.isNotEmpty(targetHashTree)) {
|
||||
element.put("hashTree", targetHashTree);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(targetHashTree)) {
|
||||
for (int i = 0; i < targetHashTree.size(); i++) {
|
||||
JSONObject item = targetHashTree.getJSONObject(i);
|
||||
if (StringUtils.isNotEmpty(item.getString("id"))) {
|
||||
updateMap.put(item.getString("id"), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 找出待更新内容和源已经被删除的内容
|
||||
if (CollectionUtils.isNotEmpty(sourceHashTree)) {
|
||||
for (int i = 0; i < sourceHashTree.size(); i++) {
|
||||
JSONObject source = sourceHashTree.getJSONObject(i);
|
||||
if (source != null) {
|
||||
sourceIds.add(source.getString("id"));
|
||||
if (!StringUtils.equals(source.getString("label"), "SCENARIO-REF-STEP") && StringUtils.isNotEmpty(source.getString("id"))) {
|
||||
if (updateMap.containsKey(source.getString("id"))) {
|
||||
sourceHashTree.set(i, updateMap.get(source.getString("id")));
|
||||
} else {
|
||||
delIds.add(source.getString("id"));
|
||||
}
|
||||
}
|
||||
// 历史数据兼容
|
||||
if (StringUtils.isEmpty(source.getString("id")) && !StringUtils.equals(source.getString("label"), "SCENARIO-REF-STEP") && i < targetHashTree.size()) {
|
||||
sourceHashTree.set(i, targetHashTree.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除多余的步骤
|
||||
for (int i = 0; i < sourceHashTree.size(); i++) {
|
||||
JSONObject source = sourceHashTree.getJSONObject(i);
|
||||
if (delIds.contains(source.getString("id"))) {
|
||||
sourceHashTree.remove(i);
|
||||
}
|
||||
}
|
||||
// 补充新增的源引用步骤
|
||||
if (CollectionUtils.isNotEmpty(targetHashTree)) {
|
||||
for (int i = 0; i < targetHashTree.size(); i++) {
|
||||
JSONObject item = sourceHashTree.getJSONObject(i);
|
||||
if (!sourceIds.contains(item.getString("id"))) {
|
||||
sourceHashTree.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(sourceHashTree)) {
|
||||
element.put("hashTree", sourceHashTree);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
element.put("hashTree", targetHashTree);
|
||||
}
|
||||
}
|
||||
|
||||
public static String hashTreeToString(HashTree hashTree) {
|
||||
try (ByteArrayOutputStream bas = new ByteArrayOutputStream()) {
|
||||
SaveService.saveTree(hashTree, bas);
|
||||
|
|
|
@ -123,6 +123,8 @@ public class MsScenario extends MsTestElement {
|
|||
}
|
||||
this.setHashTree(sourceHashTree);
|
||||
hashTree = sourceHashTree;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
|
|
@ -26,6 +26,7 @@ import io.metersphere.commons.utils.CommonBeanFactory;
|
|||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.plugin.core.MsParameter;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -88,7 +89,11 @@ public class MsDubboSampler extends MsTestElement {
|
|||
return;
|
||||
}
|
||||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||
this.setRefElement();
|
||||
boolean ref = this.setRefElement();
|
||||
if (!ref) {
|
||||
LoggerUtil.debug("引用对象已经被删除:" + this.getId());
|
||||
return;
|
||||
}
|
||||
hashTree = this.getHashTree();
|
||||
}
|
||||
|
||||
|
@ -100,7 +105,7 @@ public class MsDubboSampler extends MsTestElement {
|
|||
}
|
||||
}
|
||||
|
||||
private void setRefElement() {
|
||||
private boolean setRefElement() {
|
||||
try {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
@ -139,11 +144,12 @@ public class MsDubboSampler extends MsTestElement {
|
|||
this.setConsumerAndService(proxy.getConsumerAndService());
|
||||
this.setRegistryCenter(proxy.getRegistryCenter());
|
||||
this.setConfigCenter(proxy.getConfigCenter());
|
||||
return true;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogUtil.error(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private DubboSample dubboSample(ParameterConfig config) {
|
||||
|
|
|
@ -45,6 +45,7 @@ import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
|||
import io.metersphere.plugin.core.MsParameter;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.track.service.TestPlanApiCaseService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -133,7 +134,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
@JSONField(ordinal = 39)
|
||||
private boolean customizeReq;
|
||||
|
||||
private void setRefElement() {
|
||||
private boolean setRefElement() {
|
||||
try {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
@ -171,11 +172,12 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
this.setRest(proxy.getRest());
|
||||
this.setArguments(proxy.getArguments());
|
||||
this.setHeaders(proxy.getHeaders());
|
||||
return true;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogUtil.error(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -189,7 +191,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
return;
|
||||
}
|
||||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||
this.setRefElement();
|
||||
boolean ref = this.setRefElement();
|
||||
if (!ref) {
|
||||
LoggerUtil.debug("引用对象已经被删除:" + this.getId());
|
||||
return;
|
||||
}
|
||||
hashTree = this.getHashTree();
|
||||
}
|
||||
HTTPSamplerProxy sampler = new HTTPSamplerProxy();
|
||||
|
|
|
@ -29,6 +29,7 @@ import io.metersphere.commons.utils.LogUtil;
|
|||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.plugin.core.MsParameter;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -86,7 +87,11 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
return;
|
||||
}
|
||||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||
this.setRefElement();
|
||||
boolean ref = this.setRefElement();
|
||||
if (!ref) {
|
||||
LoggerUtil.debug("引用对象已经被删除:" + this.getId());
|
||||
return;
|
||||
}
|
||||
hashTree = this.getHashTree();
|
||||
}
|
||||
if (config != null && config.getConfig() == null) {
|
||||
|
@ -172,12 +177,12 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
}
|
||||
|
||||
//处理全局前后置脚本(步骤内)
|
||||
String enviromentId = this.getEnvironmentId();
|
||||
if (enviromentId == null) {
|
||||
enviromentId = this.useEnvironment;
|
||||
String environmentId = this.getEnvironmentId();
|
||||
if (environmentId == null) {
|
||||
environmentId = this.useEnvironment;
|
||||
}
|
||||
//根据配置将脚本放置在私有脚本之前
|
||||
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.JDBC.name(), enviromentId, config, false);
|
||||
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.JDBC.name(), environmentId, config, false);
|
||||
|
||||
HashTreeUtil hashTreeUtil = new HashTreeUtil();
|
||||
|
||||
|
@ -192,7 +197,7 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
});
|
||||
}
|
||||
//根据配置将脚本放置在私有脚本之后
|
||||
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.JDBC.name(), enviromentId, config, true);
|
||||
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.JDBC.name(), environmentId, config, true);
|
||||
|
||||
}
|
||||
|
||||
|
@ -239,7 +244,7 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
return "";
|
||||
}
|
||||
|
||||
private void setRefElement() {
|
||||
private boolean setRefElement() {
|
||||
try {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
@ -278,11 +283,12 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
this.setVariableNames(proxy.getVariableNames());
|
||||
this.setResultVariable(proxy.getResultVariable());
|
||||
this.setQueryTimeout(proxy.getQueryTimeout());
|
||||
return true;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogUtil.error(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private EnvironmentConfig initDataSource() {
|
||||
|
|
|
@ -28,6 +28,7 @@ import io.metersphere.commons.utils.LogUtil;
|
|||
import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
||||
import io.metersphere.plugin.core.MsParameter;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -123,7 +124,11 @@ public class MsTCPSampler extends MsTestElement {
|
|||
return;
|
||||
}
|
||||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||
this.setRefElement();
|
||||
boolean ref = this.setRefElement();
|
||||
if (!ref) {
|
||||
LoggerUtil.debug("引用对象已经被删除:" + this.getId());
|
||||
return;
|
||||
}
|
||||
hashTree = this.getHashTree();
|
||||
}
|
||||
if (config.getConfig() == null) {
|
||||
|
@ -167,12 +172,12 @@ public class MsTCPSampler extends MsTestElement {
|
|||
}
|
||||
|
||||
//处理全局前后置脚本(步骤内)
|
||||
String enviromentId = this.getEnvironmentId();
|
||||
if (enviromentId == null) {
|
||||
enviromentId = this.useEnvironment;
|
||||
String environmentId = this.getEnvironmentId();
|
||||
if (environmentId == null) {
|
||||
environmentId = this.useEnvironment;
|
||||
}
|
||||
//根据配置将脚本放置在私有脚本之前
|
||||
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.TCP.name(), enviromentId, config, false);
|
||||
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.TCP.name(), environmentId, config, false);
|
||||
|
||||
HashTreeUtil hashTreeUtil = new HashTreeUtil();
|
||||
|
||||
|
@ -187,23 +192,10 @@ public class MsTCPSampler extends MsTestElement {
|
|||
});
|
||||
}
|
||||
//根据配置将脚本放置在私有脚本之后
|
||||
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.TCP.name(), enviromentId, config, true);
|
||||
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.TCP.name(), environmentId, config, true);
|
||||
}
|
||||
|
||||
private void addItemHashTree(MsTestElement element, HashTree samplerHashTree, ParameterConfig config) {
|
||||
if (element != null) {
|
||||
if (element.getEnvironmentId() == null) {
|
||||
if (this.getEnvironmentId() == null) {
|
||||
element.setEnvironmentId(useEnvironment);
|
||||
} else {
|
||||
element.setEnvironmentId(this.getEnvironmentId());
|
||||
}
|
||||
}
|
||||
element.toHashTree(samplerHashTree, element.getHashTree(), config);
|
||||
}
|
||||
}
|
||||
|
||||
private void setRefElement() {
|
||||
private boolean setRefElement() {
|
||||
try {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
@ -239,11 +231,12 @@ public class MsTCPSampler extends MsTestElement {
|
|||
this.setServer(proxy.getServer());
|
||||
this.setPort(proxy.getPort());
|
||||
this.setRequest(proxy.getRequest());
|
||||
return true;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogUtil.error(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void parseEnvironment(EnvironmentConfig config) {
|
||||
|
|
|
@ -9,6 +9,8 @@ import io.metersphere.api.dto.automation.parse.ScenarioImport;
|
|||
import io.metersphere.api.dto.automation.parse.ScenarioImportParserFactory;
|
||||
import io.metersphere.api.dto.datacount.ApiDataCountResult;
|
||||
import io.metersphere.api.dto.datacount.ApiMethodUrlDTO;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseInfo;
|
||||
import io.metersphere.api.dto.definition.RunDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.request.*;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
|
@ -39,7 +41,10 @@ import io.metersphere.log.vo.DetailColumn;
|
|||
import io.metersphere.log.vo.OperatingLogDetails;
|
||||
import io.metersphere.log.vo.api.AutomationReference;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.service.*;
|
||||
import io.metersphere.service.EnvironmentGroupProjectService;
|
||||
import io.metersphere.service.QuotaService;
|
||||
import io.metersphere.service.RelationshipEdgeService;
|
||||
import io.metersphere.service.ScheduleService;
|
||||
import io.metersphere.track.dto.TestPlanDTO;
|
||||
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
||||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
||||
|
@ -166,10 +171,10 @@ public class ApiAutomationService {
|
|||
return list;
|
||||
}
|
||||
|
||||
public List<ApiScenarioWithBLOBs> listAll(ApiScenarioBatchRequest request) {
|
||||
public List<ApiScenarioDTO> listAll(ApiScenarioBatchRequest request) {
|
||||
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
||||
(query) -> extApiScenarioMapper.selectIdsByQuery(query));
|
||||
List<ApiScenarioWithBLOBs> list = extApiScenarioMapper.selectIds(request.getIds());
|
||||
List<ApiScenarioDTO> list = extApiScenarioMapper.selectIds(request.getIds());
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -675,25 +680,84 @@ public class ApiAutomationService {
|
|||
return scenarioWithBLOBs;
|
||||
}
|
||||
|
||||
public void dataFormatting(JSONArray hashTree) {
|
||||
for (int i = 0; i < hashTree.size(); i++) {
|
||||
JSONObject element = hashTree.getJSONObject(i);
|
||||
if (element != null && StringUtils.equalsIgnoreCase(element.getString("type"), "scenario")) {
|
||||
private final static List<String> requests = new ArrayList<String>() {{
|
||||
this.add("HTTPSamplerProxy");
|
||||
this.add("DubboSampler");
|
||||
this.add("JDBCSampler");
|
||||
this.add("TCPSampler");
|
||||
}};
|
||||
|
||||
private void setElement(JSONObject element, Integer num, boolean enable, String versionName, boolean versionEnable) {
|
||||
element.put("num", num);
|
||||
element.put("enable", enable);
|
||||
element.put("versionName", versionName);
|
||||
element.put("versionEnable", versionEnable);
|
||||
}
|
||||
|
||||
private JSONObject setRequest(JSONObject element) {
|
||||
boolean enable = element.getBoolean("enable");
|
||||
boolean isExist = false;
|
||||
if (StringUtils.equalsIgnoreCase(element.getString("refType"), "CASE")) {
|
||||
ApiTestCaseInfo apiTestCase = apiTestCaseService.get(element.getString("id"));
|
||||
if (apiTestCase != null) {
|
||||
JSONObject refElement = JSON.parseObject(apiTestCase.getRequest());
|
||||
ElementUtil.dataFormatting(refElement);
|
||||
if (refElement.get("hashTree") != null && StringUtils.equalsIgnoreCase(element.getString("referenced"), "REF")) {
|
||||
ElementUtil.mergeHashTree(element, refElement.getJSONArray("hashTree"));
|
||||
element.put("referenced", "REF");
|
||||
element.put("name", apiTestCase.getName());
|
||||
} else {
|
||||
element = refElement;
|
||||
}
|
||||
isExist = true;
|
||||
this.setElement(element, apiTestCase.getNum(), enable, apiTestCase.getVersionName(), apiTestCase.getVersionEnable());
|
||||
}
|
||||
} else {
|
||||
ApiDefinitionResult definitionWithBLOBs = apiDefinitionService.getById(element.getString("id"));
|
||||
if (definitionWithBLOBs != null) {
|
||||
this.setElement(element, definitionWithBLOBs.getNum(), enable, definitionWithBLOBs.getVersionName(), definitionWithBLOBs.getVersionEnable());
|
||||
isExist = true;
|
||||
}
|
||||
}
|
||||
if (!isExist) {
|
||||
if (StringUtils.equalsIgnoreCase(element.getString("referenced"), "REF")) {
|
||||
element.put("enable", false);
|
||||
}
|
||||
element.put("num", "");
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
private JSONObject setRefScenario(JSONObject element) {
|
||||
boolean enable = element.getBoolean("enable");
|
||||
ApiScenarioDTO scenarioWithBLOBs = extApiScenarioMapper.selectById(element.getString("id"));
|
||||
if (scenarioWithBLOBs != null && StringUtils.isNotEmpty(scenarioWithBLOBs.getScenarioDefinition())) {
|
||||
boolean enable = element.getBoolean("enable");
|
||||
boolean environmentEnable = element.getBoolean("environmentEnable");
|
||||
if (StringUtils.equalsIgnoreCase(element.getString("referenced"), "REF")) {
|
||||
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
|
||||
element.put("referenced", "REF");
|
||||
element.put("name", scenarioWithBLOBs.getName());
|
||||
}
|
||||
element.put("num", scenarioWithBLOBs.getNum());
|
||||
element.put("enable", enable);
|
||||
element.put("environmentEnable", environmentEnable);
|
||||
element.put("versionName", scenarioWithBLOBs.getVersionName());
|
||||
element.put("versionEnable", scenarioWithBLOBs.getVersionEnable());
|
||||
hashTree.set(i, element);
|
||||
this.setElement(element, scenarioWithBLOBs.getNum(), enable, scenarioWithBLOBs.getVersionName(), scenarioWithBLOBs.getVersionEnable());
|
||||
} else {
|
||||
if (StringUtils.equalsIgnoreCase(element.getString("referenced"), "REF")) {
|
||||
element.put("enable", false);
|
||||
}
|
||||
element.put("num", "");
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public void dataFormatting(JSONArray hashTree) {
|
||||
for (int i = 0; i < hashTree.size(); i++) {
|
||||
JSONObject element = hashTree.getJSONObject(i);
|
||||
if (element != null && StringUtils.equalsIgnoreCase(element.getString("type"), "scenario")) {
|
||||
element = this.setRefScenario(element);
|
||||
hashTree.set(i, element);
|
||||
} else if (element != null && requests.contains(element.getString("type"))) {
|
||||
element = this.setRequest(element);
|
||||
hashTree.set(i, element);
|
||||
}
|
||||
if (element.containsKey("hashTree")) {
|
||||
JSONArray elementJSONArray = element.getJSONArray("hashTree");
|
||||
|
@ -704,20 +768,9 @@ public class ApiAutomationService {
|
|||
|
||||
public void dataFormatting(JSONObject element) {
|
||||
if (element != null && StringUtils.equalsIgnoreCase(element.getString("type"), "scenario")) {
|
||||
ApiScenarioDTO scenarioWithBLOBs = extApiScenarioMapper.selectById(element.getString("id"));
|
||||
if (scenarioWithBLOBs != null && StringUtils.isNotEmpty(scenarioWithBLOBs.getScenarioDefinition())) {
|
||||
boolean enable = element.getBoolean("enable");
|
||||
boolean environmentEnable = element.getBoolean("environmentEnable");
|
||||
if (StringUtils.equalsIgnoreCase(element.getString("referenced"), "REF")) {
|
||||
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
|
||||
element.put("referenced", "REF");
|
||||
}
|
||||
element.put("enable", enable);
|
||||
element.put("environmentEnable", environmentEnable);
|
||||
element.put("num", scenarioWithBLOBs.getNum());
|
||||
element.put("versionName", scenarioWithBLOBs.getVersionName());
|
||||
element.put("versionEnable", scenarioWithBLOBs.getVersionEnable());
|
||||
}
|
||||
element = this.setRefScenario(element);
|
||||
} else if (element != null && requests.contains(element.getString("type"))) {
|
||||
element = this.setRequest(element);
|
||||
}
|
||||
if (element != null && element.containsKey("hashTree")) {
|
||||
JSONArray elementJSONArray = element.getJSONArray("hashTree");
|
||||
|
@ -761,7 +814,7 @@ public class ApiAutomationService {
|
|||
}
|
||||
|
||||
|
||||
public List<ApiScenarioWithBLOBs> getApiScenarios(List<String> ids) {
|
||||
public List<ApiScenarioDTO> getApiScenarios(List<String> ids) {
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
return extApiScenarioMapper.selectIds(ids);
|
||||
}
|
||||
|
@ -1050,9 +1103,8 @@ public class ApiAutomationService {
|
|||
}
|
||||
|
||||
public JmxInfoDTO genPerformanceTestJmx(GenScenarioRequest request) {
|
||||
List<ApiScenarioWithBLOBs> apiScenarios = null;
|
||||
List<String> ids = request.getIds();
|
||||
apiScenarios = extApiScenarioMapper.selectIds(ids);
|
||||
List<ApiScenarioDTO> apiScenarios = extApiScenarioMapper.selectIds(ids);
|
||||
String testName = "";
|
||||
String id = "";
|
||||
if (!apiScenarios.isEmpty()) {
|
||||
|
@ -1821,7 +1873,7 @@ public class ApiAutomationService {
|
|||
List<JmxInfoDTO> returnList = new ArrayList<>();
|
||||
|
||||
List<String> ids = request.getIds();
|
||||
List<ApiScenarioWithBLOBs> apiScenarioList = extApiScenarioMapper.selectIds(ids);
|
||||
List<ApiScenarioDTO> apiScenarioList = extApiScenarioMapper.selectIds(ids);
|
||||
if (CollectionUtils.isEmpty(apiScenarioList)) {
|
||||
return returnList;
|
||||
} else {
|
||||
|
@ -1845,7 +1897,7 @@ public class ApiAutomationService {
|
|||
(query) -> extApiScenarioMapper.selectIdsByQuery(query));
|
||||
List<String> ids = request.getIds();
|
||||
if (CollectionUtils.isEmpty(ids)) return;
|
||||
List<ApiScenarioWithBLOBs> apiScenarioList = extApiScenarioMapper.selectIds(ids);
|
||||
List<ApiScenarioDTO> apiScenarioList = extApiScenarioMapper.selectIds(ids);
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ApiScenarioMapper mapper = sqlSession.getMapper(ApiScenarioMapper.class);
|
||||
Long nextOrder = ServiceUtils.getNextOrder(request.getProjectId(), extApiScenarioMapper::getLastOrder);
|
||||
|
|
|
@ -297,10 +297,13 @@
|
|||
api_definition.description,api_definition.request,api_definition.response,api_definition.environment_id,
|
||||
api_definition.status, api_definition.user_id, api_definition.create_time, api_definition.update_time,
|
||||
project.name as
|
||||
project_name, user.name as user_name
|
||||
project_name, user.name as user_name,
|
||||
api_definition.version_id versionId,
|
||||
project_version.name versionName,project.version_enable
|
||||
from api_definition
|
||||
left join project on api_definition.project_id = project.id
|
||||
left join user on api_definition.user_id = user.id
|
||||
left join project_version on api_definition.project_id = project_version.project_id and api_definition.version_id = project_version.id
|
||||
WHERE api_definition.id IN
|
||||
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
||||
#{v}
|
||||
|
|
|
@ -23,7 +23,7 @@ public interface ExtApiScenarioMapper {
|
|||
|
||||
List<ApiScenarioWithBLOBs> selectByTagId(@Param("id") String id);
|
||||
|
||||
List<ApiScenarioWithBLOBs> selectIds(@Param("ids") List<String> ids);
|
||||
List<ApiScenarioDTO> selectIds(@Param("ids") List<String> ids);
|
||||
|
||||
int selectTrash(@Param("projectId") String projectId);
|
||||
|
||||
|
|
|
@ -351,8 +351,12 @@
|
|||
select * from api_scenario where tags like CONCAT('%', #{id},'%')
|
||||
</select>
|
||||
|
||||
<select id="selectIds" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
|
||||
select * from api_scenario where id in
|
||||
<select id="selectIds" resultType="io.metersphere.api.dto.automation.ApiScenarioDTO">
|
||||
select api_scenario.*, project_version.name as version_name, project.version_enable
|
||||
from api_scenario
|
||||
LEFT JOIN project_version on project_version.project_id = api_scenario.project_id and project_version.id = version_id
|
||||
LEFT JOIN project on api_scenario.project_id = project.id
|
||||
WHERE api_scenario.id in
|
||||
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
||||
#{v}
|
||||
</foreach>
|
||||
|
|
|
@ -600,9 +600,11 @@
|
|||
</if>
|
||||
</select>
|
||||
<select id="getCaseInfo" resultType="io.metersphere.api.dto.definition.ApiTestCaseInfo">
|
||||
select t1.*,a.method AS apiMethod
|
||||
select t1.*,a.method AS apiMethod,project_version.name as version_name, project.version_enable
|
||||
from api_test_case t1
|
||||
inner join api_definition a on t1.api_definition_id = a.id
|
||||
LEFT JOIN project ON t1.project_id = project.id
|
||||
LEFT JOIN project_version on a.project_id = project_version.project_id AND project_version.id = t1.version_id
|
||||
where 1
|
||||
<if test="request.id != null and request.id!=''">
|
||||
and t1.id = #{request.id}
|
||||
|
|
|
@ -1132,6 +1132,10 @@ export default {
|
|||
request.active = false;
|
||||
request.resourceId = getUUID();
|
||||
request.projectId = item.projectId;
|
||||
request.num = item.num;
|
||||
request.versionEnable = item.versionEnable;
|
||||
request.versionId = item.versionId;
|
||||
request.versionName = item.versionName;
|
||||
request.requestResult = [];
|
||||
if (!request.url) {
|
||||
request.url = "";
|
||||
|
|
|
@ -115,7 +115,10 @@ export default {
|
|||
referenced: referenced,
|
||||
resourceId: getUUID(),
|
||||
hashTree: scenarioDefinition.hashTree,
|
||||
projectId: item.projectId
|
||||
projectId: item.projectId,
|
||||
num: item.num,
|
||||
versionName: item.versionName,
|
||||
versionEnable: item.versionEnable
|
||||
};
|
||||
scenarios.push(obj);
|
||||
}
|
||||
|
|
|
@ -228,11 +228,13 @@ export default {
|
|||
this.request.projectId = getCurrentProjectID();
|
||||
}
|
||||
this.request.customizeReq = this.isCustomizeReq;
|
||||
|
||||
if (this.request.num) {
|
||||
this.isShowNum = true;
|
||||
this.getWorkspaceId(this.request.projectId);
|
||||
} else {
|
||||
this.isShowNum = false;
|
||||
}
|
||||
// 加载引用对象数据
|
||||
this.getApiInfo();
|
||||
if (this.request.protocol === 'HTTP') {
|
||||
this.setUrl(this.request.url);
|
||||
this.setUrl(this.request.path);
|
||||
|
|
|
@ -121,7 +121,7 @@ export default {
|
|||
this.isShowNum = true;
|
||||
this.getWorkspaceId(this.scenario.projectId);
|
||||
} else {
|
||||
this.isSameSpace = false;
|
||||
this.isShowNum = false;
|
||||
}
|
||||
if (!this.scenario.projectId) {
|
||||
this.scenario.projectId = getCurrentProjectID();
|
||||
|
|
Loading…
Reference in New Issue