feat(接口测试): TCP-Mock期望添加后置脚本功能

TCP-Mock期望添加后置脚本功能
This commit is contained in:
song-tianyang 2022-02-16 16:33:58 +08:00 committed by CountryBuilder
parent 47fb30ad1d
commit 3fc8708c51
3 changed files with 102 additions and 98 deletions

View File

@ -64,12 +64,16 @@ public class MockScriptEngineUtils {
preScriptBuffer.append("Map vars = new HashMap();\n"); preScriptBuffer.append("Map vars = new HashMap();\n");
preScriptBuffer.append("vars.put(\"address\",\"" + url + "\");\n"); preScriptBuffer.append("vars.put(\"address\",\"" + url + "\");\n");
//写入请求头 //写入请求头
if (headerMap != null) {
for (Map.Entry<String, String> headEntry : headerMap.entrySet()) { for (Map.Entry<String, String> headEntry : headerMap.entrySet()) {
String headerKey = headEntry.getKey(); String headerKey = headEntry.getKey();
String headerValue = headEntry.getValue(); String headerValue = headEntry.getValue();
preScriptBuffer.append("vars.put(\"header." + headerKey + "\",\"" + headerValue + "\");\n"); preScriptBuffer.append("vars.put(\"header." + headerKey + "\",\"" + headerValue + "\");\n");
} }
}
//写入body参数 //写入body参数
if (requestMockParams != null) {
if (requestMockParams.getBodyParams() != null) { if (requestMockParams.getBodyParams() != null) {
if (requestMockParams.getBodyParams().size() == 1) { if (requestMockParams.getBodyParams().size() == 1) {
//参数是jsonObject //参数是jsonObject
@ -110,6 +114,7 @@ public class MockScriptEngineUtils {
preScriptBuffer.append("vars.put(\"rest." + key + "\",\"" + value + "\");\n"); preScriptBuffer.append("vars.put(\"rest." + key + "\",\"" + value + "\");\n");
} }
} }
}
return preScriptBuffer.toString(); return preScriptBuffer.toString();
} }

View File

@ -60,7 +60,7 @@ public class TCPServicer {
MockApiUtils mockApiUtils = new MockApiUtils(); MockApiUtils mockApiUtils = new MockApiUtils();
boolean useScript = false; boolean useScript = false;
if(respResultObj.containsKey("usePostScript")){ if(respResultObj.containsKey("usePostScript")){
useScript = responseObj.getBoolean("usePostScript"); useScript = respResultObj.getBoolean("usePostScript");
} }
returnMsg = mockApiUtils.getResultByResponseResult(respResultObj.getJSONObject("body"),"",null,null,useScript); returnMsg = mockApiUtils.getResultByResponseResult(respResultObj.getJSONObject("body"),"",null,null,useScript);
} }

View File

@ -150,7 +150,6 @@ export default {
} else { } else {
this.baseCodeTemplates = this.tcpCodeTemplates; this.baseCodeTemplates = this.tcpCodeTemplates;
} }
alert(JSON.stringify(this.baseCodeTemplates));
} }
} }
, ,