From 324f8b600def642cf9b9c1407213ce8dfa502b68 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 11 Aug 2023 10:51:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20API=E6=8F=92=E4=BB=B6=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E7=B1=BB=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/api/dto/BaseConfigDTO.java | 8 +++- .../plugin/api/dto/TestElementDTO.java | 38 ++++++++----------- .../api/controller/PluginSubTypeTests.java | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/backend/framework/plugin/metersphere-api-plugin-sdk/src/main/java/io/metersphere/plugin/api/dto/BaseConfigDTO.java b/backend/framework/plugin/metersphere-api-plugin-sdk/src/main/java/io/metersphere/plugin/api/dto/BaseConfigDTO.java index a63a22f742..e5a06ede99 100644 --- a/backend/framework/plugin/metersphere-api-plugin-sdk/src/main/java/io/metersphere/plugin/api/dto/BaseConfigDTO.java +++ b/backend/framework/plugin/metersphere-api-plugin-sdk/src/main/java/io/metersphere/plugin/api/dto/BaseConfigDTO.java @@ -1,7 +1,13 @@ package io.metersphere.plugin.api.dto; +import java.io.Serial; +import java.io.Serializable; + /** * 公共传递参数基类 */ -public class BaseConfigDTO { +public class BaseConfigDTO implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + } diff --git a/backend/framework/plugin/metersphere-api-plugin-sdk/src/main/java/io/metersphere/plugin/api/dto/TestElementDTO.java b/backend/framework/plugin/metersphere-api-plugin-sdk/src/main/java/io/metersphere/plugin/api/dto/TestElementDTO.java index f800467f4d..122cc4c5c2 100644 --- a/backend/framework/plugin/metersphere-api-plugin-sdk/src/main/java/io/metersphere/plugin/api/dto/TestElementDTO.java +++ b/backend/framework/plugin/metersphere-api-plugin-sdk/src/main/java/io/metersphere/plugin/api/dto/TestElementDTO.java @@ -5,9 +5,10 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import io.metersphere.plugin.sdk.util.PluginLogUtils; import lombok.Data; import org.apache.jmeter.save.SaveService; -import org.apache.jorphan.collections.ListedHashTree; +import org.apache.jorphan.collections.HashTree; import java.io.ByteArrayOutputStream; +import java.io.Serial; import java.io.Serializable; import java.util.LinkedList; import java.util.List; @@ -16,6 +17,9 @@ import java.util.List; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") @JsonIgnoreProperties(ignoreUnknown = true) public abstract class TestElementDTO implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + // 组件类型 private String type; @@ -35,51 +39,41 @@ public abstract class TestElementDTO implements Serializable { private boolean enable; // 子组件 - private LinkedList hashTree; + private LinkedList children; // 父类 private TestElementDTO parent; /** * 自组件重新这个方法 - * - * @param tree - * @param hashTree - * @param config */ - public void toHashTree(ListedHashTree tree, List hashTree, BaseConfigDTO config) { - if (hashTree != null && hashTree.size() > 0) { - for (TestElementDTO el : hashTree) { - el.toHashTree(tree, el.hashTree, config); + public void toHashTree(HashTree tree, List children, BaseConfigDTO config) { + if (children != null && !children.isEmpty()) { + for (TestElementDTO el : children) { + el.toHashTree(tree, el.children, config); } } } /** * 转换JMX - * - * @param hashTree - * @return */ - public String getJmx(ListedHashTree hashTree) { + public String getJmx(HashTree children) { try (ByteArrayOutputStream bas = new ByteArrayOutputStream()) { - SaveService.saveTree(hashTree, bas); + SaveService.saveTree(children, bas); return bas.toString(); } catch (Exception e) { - PluginLogUtils.error("ListedHashTree error, can't log jmx scenarioDefinition"); + PluginLogUtils.error("HashTree error, can't log jmx scenarioDefinition"); } return null; } /** * 生成hashTree - * - * @param config - * @return */ - public ListedHashTree generateHashTree(BaseConfigDTO config) { - ListedHashTree listedHashTree = new ListedHashTree(); - this.toHashTree(listedHashTree, this.hashTree, config); + public HashTree generateHashTree(BaseConfigDTO config) { + HashTree listedHashTree = new HashTree(); + this.toHashTree(listedHashTree, this.children, config); return listedHashTree; } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/PluginSubTypeTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/PluginSubTypeTests.java index e20423e5d2..533ec5daee 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/PluginSubTypeTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/PluginSubTypeTests.java @@ -28,7 +28,7 @@ public class PluginSubTypeTests { MSJSR223Processor msjsr223Processor = new MSJSR223Processor(); msjsr223Processor.setName("测试jsr223"); msjsr223Processor.setJsrEnable(true); - msjsr223Processor.setHashTree(hashTree); + msjsr223Processor.setChildren(hashTree); String json = JSONUtils.toJSONString(msjsr223Processor); Assertions.assertNotNull(json);