mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-04 04:59:48 +08:00
refactor: API插件基础类调整
This commit is contained in:
parent
30794f628f
commit
324f8b600d
@ -1,7 +1,13 @@
|
|||||||
package io.metersphere.plugin.api.dto;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,10 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|||||||
import io.metersphere.plugin.sdk.util.PluginLogUtils;
|
import io.metersphere.plugin.sdk.util.PluginLogUtils;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.jmeter.save.SaveService;
|
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.ByteArrayOutputStream;
|
||||||
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -16,6 +17,9 @@ import java.util.List;
|
|||||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public abstract class TestElementDTO implements Serializable {
|
public abstract class TestElementDTO implements Serializable {
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
// 组件类型
|
// 组件类型
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@ -35,51 +39,41 @@ public abstract class TestElementDTO implements Serializable {
|
|||||||
private boolean enable;
|
private boolean enable;
|
||||||
|
|
||||||
// 子组件
|
// 子组件
|
||||||
private LinkedList<TestElementDTO> hashTree;
|
private LinkedList<TestElementDTO> children;
|
||||||
|
|
||||||
// 父类
|
// 父类
|
||||||
private TestElementDTO parent;
|
private TestElementDTO parent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自组件重新这个方法
|
* 自组件重新这个方法
|
||||||
*
|
|
||||||
* @param tree
|
|
||||||
* @param hashTree
|
|
||||||
* @param config
|
|
||||||
*/
|
*/
|
||||||
public void toHashTree(ListedHashTree tree, List<TestElementDTO> hashTree, BaseConfigDTO config) {
|
public void toHashTree(HashTree tree, List<TestElementDTO> children, BaseConfigDTO config) {
|
||||||
if (hashTree != null && hashTree.size() > 0) {
|
if (children != null && !children.isEmpty()) {
|
||||||
for (TestElementDTO el : hashTree) {
|
for (TestElementDTO el : children) {
|
||||||
el.toHashTree(tree, el.hashTree, config);
|
el.toHashTree(tree, el.children, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换JMX
|
* 转换JMX
|
||||||
*
|
|
||||||
* @param hashTree
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public String getJmx(ListedHashTree hashTree) {
|
public String getJmx(HashTree children) {
|
||||||
try (ByteArrayOutputStream bas = new ByteArrayOutputStream()) {
|
try (ByteArrayOutputStream bas = new ByteArrayOutputStream()) {
|
||||||
SaveService.saveTree(hashTree, bas);
|
SaveService.saveTree(children, bas);
|
||||||
return bas.toString();
|
return bas.toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PluginLogUtils.error("ListedHashTree error, can't log jmx scenarioDefinition");
|
PluginLogUtils.error("HashTree error, can't log jmx scenarioDefinition");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成hashTree
|
* 生成hashTree
|
||||||
*
|
|
||||||
* @param config
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public ListedHashTree generateHashTree(BaseConfigDTO config) {
|
public HashTree generateHashTree(BaseConfigDTO config) {
|
||||||
ListedHashTree listedHashTree = new ListedHashTree();
|
HashTree listedHashTree = new HashTree();
|
||||||
this.toHashTree(listedHashTree, this.hashTree, config);
|
this.toHashTree(listedHashTree, this.children, config);
|
||||||
return listedHashTree;
|
return listedHashTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public class PluginSubTypeTests {
|
|||||||
MSJSR223Processor msjsr223Processor = new MSJSR223Processor();
|
MSJSR223Processor msjsr223Processor = new MSJSR223Processor();
|
||||||
msjsr223Processor.setName("测试jsr223");
|
msjsr223Processor.setName("测试jsr223");
|
||||||
msjsr223Processor.setJsrEnable(true);
|
msjsr223Processor.setJsrEnable(true);
|
||||||
msjsr223Processor.setHashTree(hashTree);
|
msjsr223Processor.setChildren(hashTree);
|
||||||
|
|
||||||
String json = JSONUtils.toJSONString(msjsr223Processor);
|
String json = JSONUtils.toJSONString(msjsr223Processor);
|
||||||
Assertions.assertNotNull(json);
|
Assertions.assertNotNull(json);
|
||||||
|
Loading…
Reference in New Issue
Block a user