fix(接口测试): 修复Mock匹配不到的问题
--bug=1011558 --user=宋天阳 【接口测试】接口-新建mock-运行返回错误 https://www.tapd.cn/55049933/s/1123528
This commit is contained in:
parent
8527b24911
commit
17f1296319
|
@ -57,6 +57,7 @@ import java.net.URLEncoder;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -189,12 +190,19 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
if (this.body != null) {
|
||||
List<KeyValue> bodyParams = this.body.getBodyParams(sampler, this.getId());
|
||||
if (StringUtils.isNotEmpty(this.body.getType()) && "Form Data".equals(this.body.getType())) {
|
||||
sampler.setDoMultipart(true);
|
||||
AtomicBoolean kvIsEmpty = new AtomicBoolean(true);
|
||||
this.body.getKvs().forEach(files -> {
|
||||
if (StringUtils.isNotEmpty(files.getName()) && "file".equals(files.getType()) && CollectionUtils.isNotEmpty(files.getFiles())) {
|
||||
sampler.setDoBrowserCompatibleMultipart(true);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(files.getName())) {
|
||||
kvIsEmpty.set(false);
|
||||
}
|
||||
});
|
||||
//值不为空时才会设置doMultiPart
|
||||
if (!kvIsEmpty.get()) {
|
||||
sampler.setDoMultipart(true);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(bodyParams)) {
|
||||
Arguments arguments = httpArguments(bodyParams);
|
||||
|
@ -694,11 +702,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
if (StringUtils.isNotBlank(keyValue.getContentType())) {
|
||||
httpArgument.setContentType(keyValue.getContentType());
|
||||
}
|
||||
if(StringUtils.equalsIgnoreCase(this.method,"get")){
|
||||
if(StringUtils.isNotEmpty(httpArgument.getValue())){
|
||||
if (StringUtils.equalsIgnoreCase(this.method, "get")) {
|
||||
if (StringUtils.isNotEmpty(httpArgument.getValue())) {
|
||||
arguments.addArgument(httpArgument);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
arguments.addArgument(httpArgument);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1645,18 +1645,9 @@ public class ApiDefinitionService {
|
|||
return extApiDefinitionMapper.selectEffectiveIdByProjectId(projectId);
|
||||
}
|
||||
|
||||
// public List<ApiDefinition> selectByProjectIdAndMethodAndUrl(String projectId, String method,String url) {
|
||||
// ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
// ApiDefinitionExample.Criteria criteria = example.createCriteria().andMethodEqualTo(method).andProjectIdEqualTo(projectId);
|
||||
// if(StringUtils.isNotEmpty(url)){
|
||||
// criteria.andPathEqualTo(url);
|
||||
// }
|
||||
// return apiDefinitionMapper.selectByExample(example);
|
||||
// }
|
||||
public List<ApiDefinitionWithBLOBs> preparedUrl(String projectId, String method, String baseUrlSuffix) {
|
||||
|
||||
public List<ApiDefinitionWithBLOBs> preparedUrl(String projectId, String method, String urlSuffix) {
|
||||
|
||||
if (StringUtils.isEmpty(urlSuffix)) {
|
||||
if (StringUtils.isEmpty(baseUrlSuffix)) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
|
@ -1665,6 +1656,7 @@ public class ApiDefinitionService {
|
|||
|
||||
List<String> apiIdList = new ArrayList<>();
|
||||
boolean urlSuffixEndEmpty = false;
|
||||
String urlSuffix = baseUrlSuffix;
|
||||
if (urlSuffix.endsWith("/")) {
|
||||
urlSuffixEndEmpty = true;
|
||||
urlSuffix = urlSuffix + "testMock";
|
||||
|
@ -1674,6 +1666,9 @@ public class ApiDefinitionService {
|
|||
urlParams[urlParams.length - 1] = "";
|
||||
}
|
||||
for (ApiDefinition api : apiList) {
|
||||
if(StringUtils.equalsAny(api.getPath(),baseUrlSuffix,"/"+baseUrlSuffix)){
|
||||
apiIdList.add(api.getId());
|
||||
}else {
|
||||
String path = api.getPath();
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
continue;
|
||||
|
@ -1701,6 +1696,7 @@ public class ApiDefinitionService {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (apiIdList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
|
|
|
@ -393,9 +393,11 @@ public class MockConfigService {
|
|||
if (StringUtils.equalsAnyIgnoreCase(type, "Form Data", "WWW_FORM") && expectBodyObject.containsKey("kvs")) {
|
||||
JSONArray kvsArr = expectBodyObject.getJSONArray("kvs");
|
||||
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(kvsArr);
|
||||
if(CollectionUtils.isNotEmpty(mockConfigRequestParams)){
|
||||
if (!MockApiUtils.checkParamsCompliance(jsonArray, mockConfigRequestParams, StringUtils.equals(paramsFilterType, "And"))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
JSON mockExpectJsonArray = MockApiUtils.getExpectBodyParams(expectBodyObject);
|
||||
if (mockExpectJsonArray instanceof JSONObject) {
|
||||
|
|
Loading…
Reference in New Issue