--bug=1007385 --user=宋天阳 [接口定义]-编辑get接口-添加MOCK期望-修改rest参数-执行test测试mock期望结果未生效 https://www.tapd.cn/55049933/s/1058299;--bug=1007387 --user=宋天阳 [接口定义]-编辑接口-添加mock期望-响应体是自定义脚本,test执行结果返回格式错误 https://www.tapd.cn/55049933/s/1058224;--bug=1007366 --user=宋天阳 【接口定义】-PATCH请求使用MOCK环境测试期望结果失败 https://www.tapd.cn/55049933/s/1058406
This commit is contained in:
parent
0772a1c4c2
commit
31527b3c18
|
@ -123,7 +123,6 @@ public class EsbDataStruct {
|
||||||
element.addAttribute("attr", attrString);
|
element.addAttribute("attr", attrString);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(this.name);
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +162,6 @@ public class EsbDataStruct {
|
||||||
element.addAttribute("attr", attrString);
|
element.addAttribute("attr", attrString);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(this.name);
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,6 @@ public class TcpTreeTableDataStruct {
|
||||||
element.addAttribute("attr", attrString);
|
element.addAttribute("attr", attrString);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(this.name);
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +162,6 @@ public class TcpTreeTableDataStruct {
|
||||||
element.addAttribute("attr", attrString);
|
element.addAttribute("attr", attrString);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(this.name);
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -424,6 +424,9 @@ public class MockApiUtils {
|
||||||
if(StringUtils.isNotEmpty(newScript)){
|
if(StringUtils.isNotEmpty(newScript)){
|
||||||
newScript += "\n";
|
newScript += "\n";
|
||||||
}
|
}
|
||||||
|
if(StringUtils.isNotEmpty(returnMsg)){
|
||||||
|
returnMsg += "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
returnMap.put("script",newScript);
|
returnMap.put("script",newScript);
|
||||||
|
@ -435,8 +438,8 @@ public class MockApiUtils {
|
||||||
JSR223Sampler jmeterScriptSampler = new JSR223Sampler();
|
JSR223Sampler jmeterScriptSampler = new JSR223Sampler();
|
||||||
jmeterScriptSampler.setScriptLanguage(scriptLanguage);
|
jmeterScriptSampler.setScriptLanguage(scriptLanguage);
|
||||||
jmeterScriptSampler.setScript(script);
|
jmeterScriptSampler.setScript(script);
|
||||||
SampleResult result = jmeterScriptSampler.sample(null);
|
jmeterScriptSampler.sample(null);
|
||||||
System.out.println(result.getResponseData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RequestMockParams getParams(String urlParams, String apiPath, JSONObject queryParamsObject,JSON paramJson){
|
public static RequestMockParams getParams(String urlParams, String apiPath, JSONObject queryParamsObject,JSON paramJson){
|
||||||
|
@ -492,7 +495,6 @@ public class MockApiUtils {
|
||||||
return returnJson;
|
return returnJson;
|
||||||
} else if (StringUtils.equalsIgnoreCase("text/xml", request.getContentType())) {
|
} else if (StringUtils.equalsIgnoreCase("text/xml", request.getContentType())) {
|
||||||
String xmlString = readXml(request);
|
String xmlString = readXml(request);
|
||||||
System.out.println(xmlString);
|
|
||||||
|
|
||||||
org.json.JSONObject xmlJSONObj = XML.toJSONObject(xmlString);
|
org.json.JSONObject xmlJSONObj = XML.toJSONObject(xmlString);
|
||||||
String jsonStr = xmlJSONObj.toString();
|
String jsonStr = xmlJSONObj.toString();
|
||||||
|
@ -511,6 +513,14 @@ public class MockApiUtils {
|
||||||
object.put(key, value);
|
object.put(key, value);
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
|
} else if (StringUtils.equalsIgnoreCase("text/plain", request.getContentType())) {
|
||||||
|
JSONObject object = new JSONObject();
|
||||||
|
String bodyParam = readBody(request);
|
||||||
|
if(StringUtils.isNotEmpty(bodyParam)){
|
||||||
|
object.put("raw",bodyParam);
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
String bodyParam = readBody(request);
|
String bodyParam = readBody(request);
|
||||||
|
|
|
@ -1443,17 +1443,13 @@ public class ApiDefinitionService {
|
||||||
// return apiDefinitionMapper.selectByExample(example);
|
// return apiDefinitionMapper.selectByExample(example);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public List<ApiDefinitionWithBLOBs> preparedUrl(String projectId, String method, String url, String urlSuffix) {
|
public List<ApiDefinitionWithBLOBs> preparedUrl(String projectId, String method, String urlSuffix) {
|
||||||
|
|
||||||
if (StringUtils.isEmpty(urlSuffix)) {
|
if (StringUtils.isEmpty(urlSuffix)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
} else {
|
} else {
|
||||||
if (StringUtils.equalsAnyIgnoreCase(method, "GET", "DELETE")) {
|
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
ApiDefinitionExample.Criteria criteria = example.createCriteria().andMethodEqualTo(method).andProjectIdEqualTo(projectId);
|
example.createCriteria().andMethodEqualTo(method).andProjectIdEqualTo(projectId);
|
||||||
if (StringUtils.isNotEmpty(url)) {
|
|
||||||
criteria.andPathEqualTo(url);
|
|
||||||
}
|
|
||||||
List<ApiDefinition> apiList = apiDefinitionMapper.selectByExample(example);
|
List<ApiDefinition> apiList = apiDefinitionMapper.selectByExample(example);
|
||||||
|
|
||||||
List<String> apiIdList = new ArrayList<>();
|
List<String> apiIdList = new ArrayList<>();
|
||||||
|
@ -1498,14 +1494,6 @@ public class ApiDefinitionService {
|
||||||
example.createCriteria().andIdIn(apiIdList);
|
example.createCriteria().andIdIn(apiIdList);
|
||||||
return apiDefinitionMapper.selectByExampleWithBLOBs(example);
|
return apiDefinitionMapper.selectByExampleWithBLOBs(example);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (!url.startsWith("/")) {
|
|
||||||
url = "/" + url;
|
|
||||||
}
|
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
|
||||||
ApiDefinitionExample.Criteria criteria = example.createCriteria().andMethodEqualTo(method).andProjectIdEqualTo(projectId).andPathEqualTo(url);
|
|
||||||
return apiDefinitionMapper.selectByExampleWithBLOBs(example);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -605,7 +605,6 @@ public class ApiScenarioReportService {
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
ReportCounter counter = (ReportCounter) obj;
|
ReportCounter counter = (ReportCounter) obj;
|
||||||
counter.setNumber(counter.getNumber() + 1);
|
counter.setNumber(counter.getNumber() + 1);
|
||||||
System.out.println("得到统计数量:" + counter.getNumber());
|
|
||||||
MessageCache.cache.put(report.getScenarioId(), counter);
|
MessageCache.cache.put(report.getScenarioId(), counter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1032,7 +1032,7 @@ public class MockConfigService {
|
||||||
List<ApiDefinitionWithBLOBs> aualifiedApiList = new ArrayList<>();
|
List<ApiDefinitionWithBLOBs> aualifiedApiList = new ArrayList<>();
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
|
String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
|
||||||
aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix, urlSuffix);
|
aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix);
|
||||||
|
|
||||||
JSON paramJson = MockApiUtils.getPostParamMap(request);
|
JSON paramJson = MockApiUtils.getPostParamMap(request);
|
||||||
JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request);
|
JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request);
|
||||||
|
@ -1094,7 +1094,7 @@ public class MockConfigService {
|
||||||
List<ApiDefinitionWithBLOBs> aualifiedApiList = new ArrayList<>();
|
List<ApiDefinitionWithBLOBs> aualifiedApiList = new ArrayList<>();
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
|
String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
|
||||||
aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, null, urlSuffix);
|
aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET/DELETE 这种通过url穿参数的接口,在接口路径相同的情况下可能会出现这样的情况:
|
* GET/DELETE 这种通过url穿参数的接口,在接口路径相同的情况下可能会出现这样的情况:
|
||||||
|
|
|
@ -59,9 +59,15 @@ public class JsonStructUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkJsonArrayCompliance(JSONArray sourceArray, JSONArray matchArray) {
|
public static boolean checkJsonArrayCompliance(JSONArray sourceArray, JSONArray matchArray) {
|
||||||
if (sourceArray == null && matchArray == null) {
|
if(sourceArray == null){
|
||||||
|
sourceArray = new JSONArray();
|
||||||
|
}
|
||||||
|
if(matchArray == null){
|
||||||
|
matchArray = new JSONArray();
|
||||||
|
}
|
||||||
|
if (sourceArray.isEmpty() && matchArray.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (sourceArray != null && matchArray != null && sourceArray.size() >= matchArray.size()) {
|
} else if (!sourceArray.isEmpty() && !matchArray.isEmpty() && sourceArray.size() >= matchArray.size()) {
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < matchArray.size(); i++) {
|
for (int i = 0; i < matchArray.size(); i++) {
|
||||||
Object obj = matchArray.get(i);
|
Object obj = matchArray.get(i);
|
||||||
|
|
Loading…
Reference in New Issue