fix(接口测试): 修复接口案例全屏优化遗漏的部分

--bug=1010475 --user=宋天阳 【接口测试】case全屏优化遗漏部分
https://www.tapd.cn/55049933/s/1107408
This commit is contained in:
song-tianyang 2022-02-22 14:06:33 +08:00 committed by xiaomeinvG
parent 69b57856cc
commit 89f9c2603e
5 changed files with 106 additions and 74 deletions

View File

@ -235,94 +235,96 @@ public class MockApiUtils {
if (StringUtils.isNotEmpty(response)) {
try {
JSONObject respObj = JSONObject.parseObject(response);
if (respObj.containsKey("body")) {
String returnStr = "";
JSONObject bodyObj = respObj.getJSONObject("body");
if (bodyObj.containsKey("type")) {
String type = bodyObj.getString("type");
if (StringUtils.equals(type, "JSON")) {
//判断是否是JsonSchema
boolean isJsonSchema = false;
if (bodyObj.containsKey("format")) {
String foramtValue = String.valueOf(bodyObj.get("format"));
if (StringUtils.equals("JSON-SCHEMA", foramtValue)) {
isJsonSchema = true;
if(respObj != null){
if (respObj.containsKey("body")) {
String returnStr = "";
JSONObject bodyObj = respObj.getJSONObject("body");
if (bodyObj.containsKey("type")) {
String type = bodyObj.getString("type");
if (StringUtils.equals(type, "JSON")) {
//判断是否是JsonSchema
boolean isJsonSchema = false;
if (bodyObj.containsKey("format")) {
String foramtValue = String.valueOf(bodyObj.get("format"));
if (StringUtils.equals("JSON-SCHEMA", foramtValue)) {
isJsonSchema = true;
}
}
}
if (isJsonSchema) {
if (bodyObj.containsKey("jsonSchema") && bodyObj.getJSONObject("jsonSchema").containsKey("properties")) {
String bodyRetunStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString();
JSONObject bodyReturnObj = JSONObject.parseObject(bodyRetunStr);
JSONObject returnObj = MockApiUtils.parseJsonSchema(bodyReturnObj);
returnStr = returnObj.toJSONString();
if (isJsonSchema) {
if (bodyObj.containsKey("jsonSchema") && bodyObj.getJSONObject("jsonSchema").containsKey("properties")) {
String bodyRetunStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString();
JSONObject bodyReturnObj = JSONObject.parseObject(bodyRetunStr);
JSONObject returnObj = MockApiUtils.parseJsonSchema(bodyReturnObj);
returnStr = returnObj.toJSONString();
}
} else {
if (bodyObj.containsKey("raw")) {
returnStr = bodyObj.getString("raw");
}
}
} else {
} else if (StringUtils.equalsAny(type, "XML", "Raw")) {
if (bodyObj.containsKey("raw")) {
returnStr = bodyObj.getString("raw");
String raw = bodyObj.getString("raw");
returnStr = raw;
}
}
} else if (StringUtils.equalsAny(type, "XML", "Raw")) {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
returnStr = raw;
}
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
Map<String, String> paramMap = new LinkedHashMap<>();
if (bodyObj.containsKey("kvs")) {
JSONArray bodyParamArr = new JSONArray();
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
for (int i = 0; i < kvsArr.size(); i++) {
JSONObject kv = kvsArr.getJSONObject(i);
if (kv.containsKey("name")) {
String values = kv.getString("value");
if (StringUtils.isEmpty(values)) {
values = "";
} else {
try {
values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values;
} catch (Exception e) {
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
Map<String, String> paramMap = new LinkedHashMap<>();
if (bodyObj.containsKey("kvs")) {
JSONArray bodyParamArr = new JSONArray();
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
for (int i = 0; i < kvsArr.size(); i++) {
JSONObject kv = kvsArr.getJSONObject(i);
if (kv.containsKey("name")) {
String values = kv.getString("value");
if (StringUtils.isEmpty(values)) {
values = "";
} else {
try {
values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values;
} catch (Exception e) {
}
}
paramMap.put(kv.getString("name"), values);
}
paramMap.put(kv.getString("name"), values);
}
}
returnStr = JSONObject.toJSONString(paramMap);
}
}
responseDTO.setReturnData(returnStr);
}
if (respObj.containsKey("statusCode")) {
JSONArray statusCodeArray = respObj.getJSONArray("statusCode");
int code = 200;
if (statusCodeArray != null) {
for (int i = 0; i < statusCodeArray.size(); i++) {
JSONObject object = statusCodeArray.getJSONObject(i);
if (object.containsKey("name")) {
try {
code = Integer.parseInt(object.getString("name"));
break;
} catch (Exception e) {
LogUtil.error(e);
}
}
}
returnStr = JSONObject.toJSONString(paramMap);
}
responseDTO.setReturnCode(code);
}
responseDTO.setReturnData(returnStr);
}
if (respObj.containsKey("statusCode")) {
JSONArray statusCodeArray = respObj.getJSONArray("statusCode");
int code = 200;
if (statusCodeArray != null) {
for (int i = 0; i < statusCodeArray.size(); i++) {
JSONObject object = statusCodeArray.getJSONObject(i);
if (object.containsKey("name")) {
try {
code = Integer.parseInt(object.getString("name"));
break;
} catch (Exception e) {
LogUtil.error(e);
if(respObj.containsKey("headers")){
JSONArray jsonArray = respObj.getJSONArray("headers");
Map<String,String> headMap = new HashMap<>();
for(int i = 0; i < jsonArray.size(); i ++){
JSONObject headObj = jsonArray.getJSONObject(i);
if(headObj.containsKey("name") && headObj.containsKey("value") && headObj.containsKey("enable")){
boolean enable = headObj.getBoolean("enable");
if(enable){
headMap.put(headObj.getString("name"),headObj.getString("value"));
}
}
}
responseDTO.setHeaders(headMap);
}
responseDTO.setReturnCode(code);
}
if(respObj.containsKey("headers")){
JSONArray jsonArray = respObj.getJSONArray("headers");
Map<String,String> headMap = new HashMap<>();
for(int i = 0; i < jsonArray.size(); i ++){
JSONObject headObj = jsonArray.getJSONObject(i);
if(headObj.containsKey("name") && headObj.containsKey("value") && headObj.containsKey("enable")){
boolean enable = headObj.getBoolean("enable");
if(enable){
headMap.put(headObj.getString("name"),headObj.getString("value"));
}
}
}
responseDTO.setHeaders(headMap);
}
} catch (Exception e) {
MSException.throwException(e);

View File

@ -140,6 +140,11 @@ export default {
this.getApiTest(true);
this.visible = true;
this.$store.state.currentApiCase = undefined;
//
this.$nextTick(() => {
this.$refs.testCaseDrawer.setfullScreen();
});
},
add(api) {
this.api = api;
@ -169,6 +174,11 @@ export default {
this.condition = {components: API_CASE_CONFIGS};
this.sysAddition(apiCase);
this.visible = true;
//
this.$nextTick(() => {
this.$refs.testCaseDrawer.setfullScreen();
});
},
runTestCase(api, testCaseId) {
if (api && testCaseId) {
@ -195,6 +205,11 @@ export default {
this.api = api;
this.currentApi = api;
this.addCase();
//
this.$nextTick(() => {
this.$refs.testCaseDrawer.setfullScreen();
});
},
setEnvironment(environment) {
this.environment = environment;

View File

@ -34,6 +34,7 @@ import MsDropdown from "@/business/components/common/components/MsDropdown";
import CustomFunctionRelate from "@/business/components/project/menu/function/CustomFunctionRelate";
import ApiFuncRelevance from "@/business/components/project/menu/function/ApiFuncRelevance";
import MockScriptNavMenu from "@/business/components/api/definition/components/mock/Components/MockScriptNavMenu";
import i18n from "@/i18n/i18n";
export default {
name: "MockApiScriptEditor",
@ -112,6 +113,19 @@ export default {
]
},
{
title: i18n.t('project.code_segment.custom_value'),
children: [
{
title: i18n.t('api_test.request.processor.code_template_get_variable'),
value: 'vars.get("variable_name");',
},
{
title: i18n.t('api_test.request.processor.code_template_set_variable'),
value: 'vars.put("variable_name", "variable_value");',
},
]
},
{
title: this.$t('project.code_segment.code_segment'),
children: [

View File

@ -3,6 +3,7 @@
<el-card>
<el-row>
<el-col :span="1">
<span style="color: #f56c6c">*</span>
{{ $t('commons.name') }}
</el-col>
<el-col :span="9">

View File

@ -20,7 +20,7 @@
:screen-height="screenHeight"
@row-click="clickRow"
row-key="id"
operator-width="120px"
operator-width="170px"
ref="table"
>