diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java b/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java index 64ec5780c1..45ab26da49 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java @@ -16,16 +16,19 @@ public class KeyValue { private boolean enable; public KeyValue() { + this.enable = true; } public KeyValue(String name, String value) { this.name = name; this.value = value; + this.enable = true; } public KeyValue(String name, String value, String description) { this.name = name; this.value = value; + this.enable = true; this.description = description; } } diff --git a/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java index a982f5798a..0cd0d62e18 100644 --- a/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java +++ b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java @@ -137,8 +137,10 @@ public class Swagger2Parser extends ApiImportAbstractParser { Model model = definitions.get(simpleRef); HashSet refSet = new HashSet<>(); refSet.add(simpleRef); - JSONObject bodyParameters = getBodyJSONObjectParameters(model.getProperties(), definitions, refSet); - body.setRaw(bodyParameters.toJSONString()); + if (model != null ) { + JSONObject bodyParameters = getBodyJSONObjectParameters(model.getProperties(), definitions, refSet); + body.setRaw(bodyParameters.toJSONString()); + } } else if (schema instanceof ArrayModel) { ArrayModel arrayModel = (ArrayModel) bodyParameter.getSchema(); Property items = arrayModel.getItems(); diff --git a/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java b/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java index 77ce4d66f4..85f6dc31f6 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java @@ -29,12 +29,7 @@ public abstract class EasyExcelListener extends AnalysisEventListener { */ protected static final int BATCH_COUNT = 2000; - protected Class clazz; - - public EasyExcelListener() { - Type type = getClass().getGenericSuperclass(); - this.clazz = (Class) ((ParameterizedType) type).getActualTypeArguments()[0]; - } + protected Class clazz; /** * 每条数据解析都会调用 diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java index d4d590586d..1dff285527 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.utils.BeanUtils; +import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.excel.domain.TestCaseExcelData; import io.metersphere.i18n.Translator; import io.metersphere.track.service.TestCaseService; @@ -25,8 +26,9 @@ public class TestCaseDataListener extends EasyExcelListener { Set userIds; - public TestCaseDataListener(TestCaseService testCaseService, String projectId, Set testCaseNames, Set userIds) { - this.testCaseService = testCaseService; + public TestCaseDataListener(Class clazz, String projectId, Set testCaseNames, Set userIds) { + this.clazz = clazz; + this.testCaseService = (TestCaseService) CommonBeanFactory.getBean("testCaseService"); this.projectId = projectId; this.testCaseNames = testCaseNames; this.userIds = userIds; diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index a6c484d804..eb477a2740 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -41,7 +41,9 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; import java.net.URLEncoder; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -317,8 +319,9 @@ public class TestCaseService { Set userIds = userRoleMapper.selectByExample(userRoleExample).stream().map(UserRole::getUserId).collect(Collectors.toSet()); try { - EasyExcelListener easyExcelListener = new TestCaseDataListener(this, projectId, testCaseNames, userIds); - EasyExcelFactory.read(multipartFile.getInputStream(), new TestCaseExcelDataFactory().getExcelDataByLocal(), easyExcelListener).sheet().doRead(); + Class clazz = new TestCaseExcelDataFactory().getExcelDataByLocal(); + EasyExcelListener easyExcelListener = new TestCaseDataListener(clazz, projectId, testCaseNames, userIds); + EasyExcelFactory.read(multipartFile.getInputStream(), clazz, easyExcelListener).sheet().doRead(); errList = easyExcelListener.getErrList(); } catch (Exception e) { LogUtil.error(e.getMessage(), e); @@ -492,7 +495,7 @@ public class TestCaseService { if (t.getTestId() != null && t.getTestId().equals("other")) { data.setRemark(t.getOtherTestName()); } else { - data.setRemark(t.getApiName()); + data.setRemark("[" + t.getApiName() + "]" + "\n" + t.getRemark()); } } else if (t.getMethod().equals("auto") && t.getType().equals("performance")) { diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index c2dacf960c..cf6b065263 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit c2dacf960cdb1ed35664bdd3432120b1203b73d8 +Subproject commit cf6b06526324326a563d933e07118fac014a63b4 diff --git a/frontend/src/business/components/api/test/components/ApiKeyValue.vue b/frontend/src/business/components/api/test/components/ApiKeyValue.vue index 5cd862e449..f1362e6322 100644 --- a/frontend/src/business/components/api/test/components/ApiKeyValue.vue +++ b/frontend/src/business/components/api/test/components/ApiKeyValue.vue @@ -103,7 +103,7 @@ }, }, created() { - if (this.items.length === 0) { + if (this.items.length === 0 || this.items[this.items.length - 1].name) { this.items.push(new KeyValue({enable: true})); } } diff --git a/frontend/src/business/components/api/test/components/ApiScenarioSelect.vue b/frontend/src/business/components/api/test/components/ApiScenarioSelect.vue index 434341fac4..7c90de1762 100644 --- a/frontend/src/business/components/api/test/components/ApiScenarioSelect.vue +++ b/frontend/src/business/components/api/test/components/ApiScenarioSelect.vue @@ -99,6 +99,8 @@ export default { clone(row) { let scenarios = []; row.selected.forEach(options => { + // 去掉ID,创建新的ID + options.id = undefined; scenarios.push(new Scenario(options)); }) this.$emit('select', scenarios); diff --git a/frontend/src/business/components/api/test/components/ApiVariable.vue b/frontend/src/business/components/api/test/components/ApiVariable.vue index 68d02ab625..cd36f59bf1 100644 --- a/frontend/src/business/components/api/test/components/ApiVariable.vue +++ b/frontend/src/business/components/api/test/components/ApiVariable.vue @@ -168,7 +168,7 @@ } }, created() { - if (this.parameters.length === 0) { + if (this.parameters.length === 0 || this.parameters[this.parameters.length - 1].name) { this.parameters.push(new KeyValue( {type: 'text', enable: true, uuid: this.uuid(), contentType: 'text/plain'})); } } diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index 12b651ed66..f8200c2933 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -1249,21 +1249,22 @@ class JMXGenerator { if (request.controller.isValid() && request.controller.enable) { if (request.controller instanceof IfController) { let name = request.controller.label(); - let variable = request.controller.variable; + let variable = "\"" + request.controller.variable + "\""; let operator = request.controller.operator; - let value = request.controller.value; + let value = "\"" + request.controller.value + "\""; + if (operator === "=~" || operator === "!~") { - value = "\".*" + value + ".*\""; + value = "\".*" + request.controller.value + ".*\""; } if (operator === "is empty") { - variable = "empty(\"" + variable + "\")"; + variable = "empty(" + variable + ")"; operator = ""; value = ""; } if (operator === "is not empty") { - variable = "!empty(\"" + variable + "\")"; + variable = "!empty(" + variable + ")"; operator = ""; value = ""; } diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index cc38137a69..06d935cd1d 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit cc38137a69a0f20fadece9c0f9f50a9468c4ace9 +Subproject commit 06d935cd1d22ab36f09763745c2aff8ad3fb08c1