refactor: 单接口调试处理mock数据

This commit is contained in:
Captain.B 2020-08-17 13:31:42 +08:00
parent 32ba381ac0
commit 1a9d1e1971
2 changed files with 8 additions and 5 deletions

View File

@ -30,11 +30,12 @@ public class JmeterDocumentParser {
private final static String ELEMENT_PROP = "elementProp";
public static byte[] parse(byte[] source) {
final InputSource inputSource = new InputSource(new ByteArrayInputStream(source));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
try (
ByteArrayInputStream byteStream = new ByteArrayInputStream(source)
) {
InputSource inputSource = new InputSource(byteStream);
DocumentBuilder docBuilder = factory.newDocumentBuilder();
final Document document = docBuilder.parse(inputSource);
final Element jmeterTestPlan = document.getDocumentElement();
@ -157,7 +158,6 @@ public class JmeterDocumentParser {
break;
case "Argument.value":
String textContent = ele.getTextContent();
System.out.println(textContent);
ele.setTextContent(ScriptEngineUtils.calculate(textContent));
break;
default:

View File

@ -344,7 +344,10 @@ public class APITestService {
InputStream is = null;
try {
is = new ByteArrayInputStream(file.getBytes());
byte[] bytes = file.getBytes();
// 解析 xml 处理 mock 数据
bytes = JmeterDocumentParser.parse(bytes);
is = new ByteArrayInputStream(bytes);
} catch (IOException e) {
LogUtil.error(e);
}