refactor: 单接口调试处理mock数据
This commit is contained in:
parent
32ba381ac0
commit
1a9d1e1971
|
@ -30,11 +30,12 @@ public class JmeterDocumentParser {
|
||||||
private final static String ELEMENT_PROP = "elementProp";
|
private final static String ELEMENT_PROP = "elementProp";
|
||||||
|
|
||||||
public static byte[] parse(byte[] source) {
|
public static byte[] parse(byte[] source) {
|
||||||
final InputSource inputSource = new InputSource(new ByteArrayInputStream(source));
|
|
||||||
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
try {
|
try (
|
||||||
|
ByteArrayInputStream byteStream = new ByteArrayInputStream(source)
|
||||||
|
) {
|
||||||
|
InputSource inputSource = new InputSource(byteStream);
|
||||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||||
final Document document = docBuilder.parse(inputSource);
|
final Document document = docBuilder.parse(inputSource);
|
||||||
final Element jmeterTestPlan = document.getDocumentElement();
|
final Element jmeterTestPlan = document.getDocumentElement();
|
||||||
|
@ -157,7 +158,6 @@ public class JmeterDocumentParser {
|
||||||
break;
|
break;
|
||||||
case "Argument.value":
|
case "Argument.value":
|
||||||
String textContent = ele.getTextContent();
|
String textContent = ele.getTextContent();
|
||||||
System.out.println(textContent);
|
|
||||||
ele.setTextContent(ScriptEngineUtils.calculate(textContent));
|
ele.setTextContent(ScriptEngineUtils.calculate(textContent));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -344,7 +344,10 @@ public class APITestService {
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
is = new ByteArrayInputStream(file.getBytes());
|
byte[] bytes = file.getBytes();
|
||||||
|
// 解析 xml 处理 mock 数据
|
||||||
|
bytes = JmeterDocumentParser.parse(bytes);
|
||||||
|
is = new ByteArrayInputStream(bytes);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue