diff --git a/.github/stale.yml b/.github/stale.yml index 7525aae70b..a7e5a09541 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -7,6 +7,7 @@ exemptLabels: - lifecycle/frozen - pinned - security + - plan staleLabel: stale # Comment to post when marking an issue as stale. Set to `false` to disable markComment: > diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index c77efb653b..175345cb1b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -78,11 +78,28 @@ public class MsScenario extends MsTestElement { JSONObject element = JSON.parseObject(scenario.getScenarioDefinition()); hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference>() { }); + // 场景变量 + if (StringUtils.isNotEmpty(element.getString("variables"))) { + LinkedList variables = mapper.readValue(element.getString("variables"), + new TypeReference>() { + }); + this.setVariables(variables); + } + // 场景请求头 + if (StringUtils.isNotEmpty(element.getString("headers"))) { + LinkedList headers = mapper.readValue(element.getString("headers"), + new TypeReference>() { + }); + this.setHeaders(headers); + } + } + } catch (Exception ex) { ex.printStackTrace(); } } + // 设置共享cookie config.setEnableCookieShare(enableCookieShare); if (StringUtils.isNotEmpty(environmentId)) { ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java index e287a189ed..cfcbe910bb 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java @@ -151,7 +151,7 @@ public abstract class MsTestElement { ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId()); + ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(element.getId()); if (apiDefinition != null) { element = mapper.readValue(apiDefinition.getRequest(), new TypeReference() { }); @@ -159,6 +159,7 @@ public abstract class MsTestElement { } } catch (Exception ex) { ex.printStackTrace(); + LogUtil.error(ex.getMessage()); } } diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index 7e30d8b9c7..44504fbe8a 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -35,7 +35,6 @@ import org.aspectj.util.FileUtil; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; -import org.dom4j.QName; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -582,9 +581,11 @@ public class APITestService { for (Element itemElement : sampleProxyElementList) { if (isFromScenario) { testName = itemElement.attributeValue(attribute_testName); - String[] testNameArr = testName.split(scenarioCaseNameSplit); - if (testNameArr.length > 0) { - testName = testNameArr[0]; + if (StringUtils.isNotBlank(testName)) { + String[] testNameArr = testName.split(scenarioCaseNameSplit); + if (testNameArr.length > 0) { + testName = testNameArr[0]; + } } } itemElement.attribute(attribute_testName).setText(testName); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index edbfe428a0..1328607458 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -457,12 +457,15 @@ public class ApiAutomationService { }); scenario.setHashTree(elements); } - if (StringUtils.isNotEmpty(element.getString("variables"))) { + if (element != null && StringUtils.isNotEmpty(element.getString("variables"))) { LinkedList variables = mapper.readValue(element.getString("variables"), new TypeReference>() { }); scenario.setVariables(variables); } + if (scenario == null) { + return null; + } // 针对导入的jmx 处理 if (CollectionUtils.isNotEmpty(scenario.getHashTree()) && (scenario.getHashTree().get(0) instanceof MsJmeterElement)) { scenario.toHashTree(jmeterHashTree, scenario.getHashTree(), config); @@ -879,9 +882,13 @@ public class ApiAutomationService { // 生成jmx List resList = new ArrayList<>(); apiScenarioWithBLOBs.forEach(item -> { - String jmx = generateJmx(item); - ApiScenrioExportJmx scenrioExportJmx = new ApiScenrioExportJmx(item.getName(), apiTestService.updateJmxString(jmx, null, true)); - resList.add(scenrioExportJmx); + if (StringUtils.isNotEmpty(item.getScenarioDefinition())) { + String jmx = generateJmx(item); + if (StringUtils.isNotEmpty(jmx)) { + ApiScenrioExportJmx scenrioExportJmx = new ApiScenrioExportJmx(item.getName(), apiTestService.updateJmxString(jmx, null, true)); + resList.add(scenrioExportJmx); + } + } }); return resList; } diff --git a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java index 349563c8f2..8c956b18f5 100644 --- a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java +++ b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java @@ -89,7 +89,6 @@ public class JmeterDocumentParser implements DocumentParser { if (nodeNameEquals(ele, HASH_TREE_ELEMENT)) { parseHashTree(ele); } else if (nodeNameEquals(ele, TEST_PLAN)) { - processSetupTestPlan(ele); processCheckoutConfigTestElement(ele); processCheckoutDnsCacheManager(ele); processCheckoutArguments(ele); @@ -483,88 +482,6 @@ public class JmeterDocumentParser implements DocumentParser { } } - private void processSetupTestPlan(Element ele) { - Document document = ele.getOwnerDocument(); - Node hashTree = ele.getNextSibling(); - while (!(hashTree instanceof Element)) { - hashTree = hashTree.getNextSibling(); - } - - KafkaProperties kafkaProperties = CommonBeanFactory.getBean(KafkaProperties.class); - String bootstrapServers = kafkaProperties.getBootstrapServers(); - String[] servers = StringUtils.split(bootstrapServers, ","); - for (String s : servers) { - String[] ipAndPort = StringUtils.split(s, ":"); - Element setupElement = document.createElement("SetupThreadGroup"); - setupElement.setAttribute("guiclass", "SetupThreadGroupGui"); - setupElement.setAttribute("testclass", "SetupThreadGroup"); - setupElement.setAttribute("testname", "setUp Thread Group"); - setupElement.setAttribute("enabled", "true"); - setupElement.appendChild(createStringProp(document, "ThreadGroup.on_sample_error", "stoptestnow")); - Element elementProp = document.createElement("elementProp"); - elementProp.setAttribute("name", "ThreadGroup.main_controller"); - elementProp.setAttribute("elementType", "LoopController"); - elementProp.setAttribute("guiclass", "LoopControlPanel"); - elementProp.setAttribute("testclass", "LoopController"); - elementProp.setAttribute("testname", "Loop Controller"); - elementProp.setAttribute("enabled", "true"); - elementProp.appendChild(createBoolProp(document, "LoopController.continue_forever", false)); - elementProp.appendChild(createIntProp(document, "LoopController.loops", 1)); - setupElement.appendChild(elementProp); - setupElement.appendChild(createStringProp(document, "ThreadGroup.num_threads", "1")); - setupElement.appendChild(createStringProp(document, "ThreadGroup.ramp_time", "1")); - setupElement.appendChild(createStringProp(document, "ThreadGroup.duration", "")); - setupElement.appendChild(createStringProp(document, "ThreadGroup.delay", "")); - setupElement.appendChild(createBoolProp(document, "ThreadGroup.scheduler", false)); - setupElement.appendChild(createBoolProp(document, "ThreadGroup.same_user_on_next_iteration", true)); - hashTree.appendChild(setupElement); - - Element setupHashTree = document.createElement(HASH_TREE_ELEMENT); - - Element tcpSampler = document.createElement("TCPSampler"); - tcpSampler.setAttribute("guiclass", "TCPSamplerGui"); - tcpSampler.setAttribute("testclass", "TCPSampler"); - tcpSampler.setAttribute("testname", "TCP Sampler"); - tcpSampler.setAttribute("enabled", "true"); - tcpSampler.appendChild(createStringProp(document, "TCPSampler.classname", "TCPClientImpl")); - tcpSampler.appendChild(createStringProp(document, "TCPSampler.server", ipAndPort[0])); - tcpSampler.appendChild(createBoolProp(document, "TCPSampler.reUseConnection", true)); - tcpSampler.appendChild(createStringProp(document, "TCPSampler.port", ipAndPort[1])); - tcpSampler.appendChild(createBoolProp(document, "TCPSampler.nodelay", false)); - tcpSampler.appendChild(createStringProp(document, "TCPSampler.timeout", "100")); - tcpSampler.appendChild(createStringProp(document, "TCPSampler.ctimeout", "100")); - tcpSampler.appendChild(createStringProp(document, "TCPSampler.request", "1010")); - tcpSampler.appendChild(createBoolProp(document, "TCPSampler.closeConnection", false)); - tcpSampler.appendChild(createStringProp(document, "TCPSampler.EolByte", "0")); - tcpSampler.appendChild(createStringProp(document, "ConfigTestElement.username", "")); - tcpSampler.appendChild(createStringProp(document, "ConfigTestElement.password", "")); - - Element tcpSamplerHashTree = document.createElement(HASH_TREE_ELEMENT); - - Element responseAssertion = document.createElement("ResponseAssertion"); - responseAssertion.setAttribute("guiclass", "AssertionGui"); - responseAssertion.setAttribute("testclass", "ResponseAssertion"); - responseAssertion.setAttribute("testname", "Response Assertion"); - responseAssertion.setAttribute("enabled", "true"); - Element collectionProp = document.createElement("collectionProp"); - collectionProp.setAttribute("name", "Asserion.test_strings"); - collectionProp.appendChild(createStringProp(document, "49586", "200")); - responseAssertion.appendChild(collectionProp); - responseAssertion.appendChild(createStringProp(document, "Assertion.custom_message", "")); - responseAssertion.appendChild(createStringProp(document, "Assertion.test_field", "Assertion.response_code")); - responseAssertion.appendChild(createBoolProp(document, "Assertion.assume_success", false)); - responseAssertion.appendChild(createIntProp(document, "Assertion.test_type", 8)); - tcpSamplerHashTree.appendChild(responseAssertion); - // 添加空的hashtree - tcpSamplerHashTree.appendChild(document.createElement(HASH_TREE_ELEMENT)); - - setupHashTree.appendChild(tcpSampler); - setupHashTree.appendChild(tcpSamplerHashTree); - - hashTree.appendChild(setupHashTree); - } - } - private Element createBoolProp(Document document, String name, boolean value) { Element boolProp = document.createElement("boolProp"); boolProp.setAttribute("name", name); diff --git a/frontend/src/business/components/api/automation/scenario/common/ApiBaseComponent.vue b/frontend/src/business/components/api/automation/scenario/common/ApiBaseComponent.vue index d6b4ebb9fd..624aeef9b4 100644 --- a/frontend/src/business/components/api/automation/scenario/common/ApiBaseComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/common/ApiBaseComponent.vue @@ -31,10 +31,10 @@ - + - + diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue index cba4d8dd89..bd54431588 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue @@ -35,13 +35,13 @@
- - {{ apiCase.createTime | timestampFormatDate }} - {{ apiCase.createUser }} {{ $t('api_test.definition.request.create_info') }} - - {{ apiCase.updateTime | timestampFormatDate }} - {{ apiCase.updateUser }} {{ $t('api_test.definition.request.update_info') }} + {{ apiCase.createTime | timestampFormatDate }} + {{ apiCase.createUser }} {{ $t('api_test.definition.request.create_info') }} + + + {{ apiCase.updateTime | timestampFormatDate }} + {{ apiCase.updateUser }} {{ $t('api_test.definition.request.update_info') }}