feat(接口测试): Mock期望设置中key-value参数增加判断范围选项
Mock期望设置中key-value参数增加判断范围选项
This commit is contained in:
parent
0cf3f100d3
commit
3e2f492e83
|
@ -692,25 +692,52 @@ public class MockApiUtils {
|
|||
return returnCondition;
|
||||
}
|
||||
|
||||
public static boolean checkParamsCompliance(JSONObject queryParamsObj, List<MockConfigRequestParams> mockConfigRequestParamList) {
|
||||
if (CollectionUtils.isNotEmpty(mockConfigRequestParamList)) {
|
||||
for (MockConfigRequestParams params : mockConfigRequestParamList) {
|
||||
String key = params.getKey();
|
||||
if (queryParamsObj.containsKey(key)) {
|
||||
boolean isMatch = MockApiUtils.isValueMatch(String.valueOf(queryParamsObj.get(key)), params);
|
||||
if (!isMatch) {
|
||||
public static boolean checkParamsCompliance(JSONObject queryParamsObj, List<MockConfigRequestParams> mockConfigRequestParamList, boolean isAllMatch) {
|
||||
if (isAllMatch) {
|
||||
if (CollectionUtils.isNotEmpty(mockConfigRequestParamList)) {
|
||||
for (MockConfigRequestParams params : mockConfigRequestParamList) {
|
||||
String key = params.getKey();
|
||||
if (queryParamsObj.containsKey(key)) {
|
||||
boolean isMatch = MockApiUtils.isValueMatch(String.valueOf(queryParamsObj.get(key)), params);
|
||||
if (!isMatch) {
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (CollectionUtils.isNotEmpty(mockConfigRequestParamList)) {
|
||||
for (MockConfigRequestParams params : mockConfigRequestParamList) {
|
||||
String key = params.getKey();
|
||||
if (queryParamsObj.containsKey(key)) {
|
||||
boolean isMatch = MockApiUtils.isValueMatch(String.valueOf(queryParamsObj.get(key)), params);
|
||||
if (isMatch) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkParamsCompliance(JSONObject queryParamsObj, MockConfigRequestParams mockConfigRequestParams) {
|
||||
if (mockConfigRequestParams != null) {
|
||||
String key = mockConfigRequestParams.getKey();
|
||||
if (queryParamsObj.containsKey(key)) {
|
||||
return MockApiUtils.isValueMatch(String.valueOf(queryParamsObj.get(key)), mockConfigRequestParams);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean checkParamsCompliance(JSONArray jsonArray, List<MockConfigRequestParams> mockConfigRequestParamList) {
|
||||
public static boolean checkParamsCompliance(JSONArray jsonArray, List<MockConfigRequestParams> mockConfigRequestParamList, boolean isAllMatch) {
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject obj = jsonArray.getJSONObject(i);
|
||||
boolean isMatch = checkParamsCompliance(obj, mockConfigRequestParamList);
|
||||
boolean isMatch = checkParamsCompliance(obj, mockConfigRequestParamList, isAllMatch);
|
||||
if (isMatch) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -381,19 +381,23 @@ public class MockConfigService {
|
|||
JSONObject expectBodyObject = expectParamsObj.getJSONObject("body");
|
||||
JSONArray jsonArray = requestMockParams.getBodyParams();
|
||||
String type = expectBodyObject.getString("type");
|
||||
String paramsFilterType = "And";
|
||||
if (expectBodyObject.containsKey("paramsFilterType")) {
|
||||
paramsFilterType = expectBodyObject.getString("paramsFilterType");
|
||||
}
|
||||
if (StringUtils.equalsAnyIgnoreCase(type, "Form Data", "WWW_FORM") && expectBodyObject.containsKey("kvs")) {
|
||||
JSONArray kvsArr = expectBodyObject.getJSONArray("kvs");
|
||||
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(kvsArr);
|
||||
if (!MockApiUtils.checkParamsCompliance(jsonArray, mockConfigRequestParams)) {
|
||||
if (!MockApiUtils.checkParamsCompliance(jsonArray, mockConfigRequestParams, StringUtils.equals(paramsFilterType, "And"))) {
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
JSON mockExpectJsonArray = MockApiUtils.getExpectBodyParams(expectBodyObject);
|
||||
if (mockExpectJsonArray instanceof JSONObject) {
|
||||
if (!JsonStructUtils.checkJsonArrayCompliance(jsonArray, (JSONObject) mockExpectJsonArray)) {
|
||||
return false;
|
||||
}
|
||||
} else if (mockExpectJsonArray instanceof JSONArray) {
|
||||
} else if (mockExpectJsonArray instanceof JSONArray && ((JSONArray) mockExpectJsonArray).size() > 0) {
|
||||
if (!JsonStructUtils.checkJsonArrayCompliance(jsonArray, (JSONArray) mockExpectJsonArray)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -401,10 +405,15 @@ public class MockConfigService {
|
|||
}
|
||||
}
|
||||
|
||||
String paramsFilterType = "And";
|
||||
if (expectParamsObj.containsKey("paramsFilterType")) {
|
||||
paramsFilterType = expectParamsObj.getString("paramsFilterType");
|
||||
}
|
||||
|
||||
if (expectParamsObj.containsKey("arguments")) {
|
||||
JSONArray argumentsArray = expectParamsObj.getJSONArray("arguments");
|
||||
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(argumentsArray);
|
||||
if (!MockApiUtils.checkParamsCompliance(requestMockParams.getQueryParamsObj(), mockConfigRequestParams)) {
|
||||
if (!MockApiUtils.checkParamsCompliance(requestMockParams.getQueryParamsObj(), mockConfigRequestParams, StringUtils.equals(paramsFilterType, "And"))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -412,7 +421,7 @@ public class MockConfigService {
|
|||
if (expectParamsObj.containsKey("rest")) {
|
||||
JSONArray restArray = expectParamsObj.getJSONArray("rest");
|
||||
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(restArray);
|
||||
if (!MockApiUtils.checkParamsCompliance(requestMockParams.getRestParamsObj(), mockConfigRequestParams)) {
|
||||
if (!MockApiUtils.checkParamsCompliance(requestMockParams.getRestParamsObj(), mockConfigRequestParams, StringUtils.equals(paramsFilterType, "And"))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1350,7 +1359,7 @@ public class MockConfigService {
|
|||
if (mockConfig == null) {
|
||||
this.insertMockExpectConfigs(apiId, request.getProjectId(), list, sqlSession);
|
||||
} else {
|
||||
this.updateMockExpectConfigs(mockConfig, list ,sqlSession);
|
||||
this.updateMockExpectConfigs(mockConfig, list, sqlSession);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1360,15 +1369,15 @@ public class MockConfigService {
|
|||
private void updateMockExpectConfigs(MockConfig mockConfig, List<MockExpectConfigWithBLOBs> list, SqlSession sqlSession) {
|
||||
int batchCount = 0;
|
||||
for (MockExpectConfigWithBLOBs mockExpect : list) {
|
||||
MockExpectConfig expectInDb = this.findMockExpectConfigByMockConfigIdAndExpectNum(mockConfig.getId(),mockExpect.getExpectNum());
|
||||
if(expectInDb == null){
|
||||
MockExpectConfig expectInDb = this.findMockExpectConfigByMockConfigIdAndExpectNum(mockConfig.getId(), mockExpect.getExpectNum());
|
||||
if (expectInDb == null) {
|
||||
mockExpect.setId(UUID.randomUUID().toString());
|
||||
mockExpect.setMockConfigId(mockConfig.getId());
|
||||
mockExpect.setCreateTime(System.currentTimeMillis());
|
||||
mockExpect.setUpdateTime(System.currentTimeMillis());
|
||||
mockExpect.setCreateUserId(SessionUtils.getUserId());
|
||||
mockExpectConfigMapper.insert(mockExpect);
|
||||
}else {
|
||||
} else {
|
||||
mockExpect.setMockConfigId(mockConfig.getId());
|
||||
mockExpect.setId(expectInDb.getId());
|
||||
mockExpect.setUpdateTime(System.currentTimeMillis());
|
||||
|
@ -1385,9 +1394,9 @@ public class MockConfigService {
|
|||
MockExpectConfigExample example = new MockExpectConfigExample();
|
||||
example.createCriteria().andMockConfigIdEqualTo(mockConfigId).andExpectNumEqualTo(expectNum);
|
||||
List<MockExpectConfig> bloBs = this.mockExpectConfigMapper.selectByExample(example);
|
||||
if(CollectionUtils.isNotEmpty(bloBs)){
|
||||
if (CollectionUtils.isNotEmpty(bloBs)) {
|
||||
return bloBs.get(0);
|
||||
}else {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,14 +25,11 @@
|
|||
<el-row v-if="body.type == 'Form Data' || body.type == 'WWW_FORM'">
|
||||
<el-link class="ms-el-link" @click="batchAdd"> {{ $t("commons.batch_add") }}</el-link>
|
||||
</el-row>
|
||||
<mock-api-variable
|
||||
:with-mor-setting="true"
|
||||
:suggestions="suggestions"
|
||||
:is-read-only="isReadOnly"
|
||||
:parameters="body.kvs"
|
||||
:isShowEnable="isShowEnable"
|
||||
:append-dialog-to-body="true"
|
||||
type="body"/>
|
||||
<mock-combination-condition :filter-type-object="body"
|
||||
:is-read-only="isReadOnly"
|
||||
:is-show-enable="isShowEnable"
|
||||
:suggestions="suggestions"
|
||||
:parameters="body.kvs"/>
|
||||
</div>
|
||||
<div v-if="body.type == 'JSON'">
|
||||
<div style="padding: 10px">
|
||||
|
@ -78,22 +75,22 @@ import {BODY_TYPE, KeyValue} from "@/business/components/api/definition/model/Ap
|
|||
import MsCodeEdit from "@/business/components/common/components/MsCodeEdit";
|
||||
import MsJsonCodeEdit from "@/business/components/common/json-schema/JsonSchemaEditor";
|
||||
import MsDropdown from "@/business/components/common/components/MsDropdown";
|
||||
import MockApiVariable from "@/business/components/api/definition/components/mock/Components/MockApiVariable";
|
||||
import MsApiFromUrlVariable from "@/business/components/api/definition/components/body/ApiFromUrlVariable";
|
||||
import BatchAddParameter from "@/business/components/api/definition/components/basis/BatchAddParameter";
|
||||
import Convert from "@/business/components/common/json-schema/convert/convert";
|
||||
|
||||
import MockCombinationCondition
|
||||
from "@/business/components/api/definition/components/mock/Components/MockCombinationCondition";
|
||||
|
||||
export default {
|
||||
name: "MockApiBody",
|
||||
components: {
|
||||
MockApiVariable,
|
||||
MsDropdown,
|
||||
MsCodeEdit,
|
||||
MsApiKeyValue,
|
||||
MsApiFromUrlVariable,
|
||||
MsJsonCodeEdit,
|
||||
BatchAddParameter
|
||||
BatchAddParameter,
|
||||
MockCombinationCondition
|
||||
},
|
||||
props: {
|
||||
body: {},
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-container>
|
||||
<el-aside width="110px" style="overflow: hidden">
|
||||
<div v-if="parameters && parameters.length > 1" style="height: 100%" id="moreOptionTypeDiv">
|
||||
<div class="top-line-box" :style="{ height:lineDivTopHeight+'px',marginTop:lineDivMarginTopHeight+'px'}">
|
||||
</div>
|
||||
<div>
|
||||
<el-select class="ms-http-select" size="small" v-model="filterTypeObject.paramsFilterType"
|
||||
style="width: 100px">
|
||||
<el-option v-for="item in filterTypes" :key="item.id" :label="item.label" :value="item.id"/>
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="bottom-line-box" :style="{ height:lineDivBottomHeight+'px'}">
|
||||
</div>
|
||||
</div>
|
||||
</el-aside>
|
||||
<el-main style="padding: 0px">
|
||||
<mock-api-variable ref="mockApiVariableComp" :append-dialog-to-body="true"
|
||||
:suggestions="suggestions"
|
||||
:with-mor-setting="true"
|
||||
:is-read-only="isReadOnly" :isShowEnable="isShowEnable" :parameters="parameters"/>
|
||||
</el-main>
|
||||
</el-container>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import MockApiVariable from "@/business/components/api/definition/components/mock/Components/MockApiVariable";
|
||||
|
||||
export default {
|
||||
name: "CombinationCondition",
|
||||
components: {MockApiVariable},
|
||||
data() {
|
||||
return {
|
||||
lineDivTopHeight: 0,
|
||||
lineDivMarginTopHeight: 0,
|
||||
lineDivBottomHeight: 0,
|
||||
filterTypes: [
|
||||
{id: 'And', label: 'And'},
|
||||
{id: 'Or', label: 'Or'},
|
||||
],
|
||||
}
|
||||
},
|
||||
props: {
|
||||
suggestions: Array,
|
||||
parameters: Array,
|
||||
filterTypeObject: Object,
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
isShowEnable: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
},
|
||||
created() {
|
||||
},
|
||||
mounted() {
|
||||
this.initFilterDiv();
|
||||
},
|
||||
watch: {
|
||||
parameters: {
|
||||
handler: function () {
|
||||
this.$nextTick(() => {
|
||||
setTimeout(() => {
|
||||
this.initFilterDiv();
|
||||
}, 100);
|
||||
});
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
initFilterDiv() {
|
||||
if (this.parameters && this.parameters.length > 1) {
|
||||
this.lineDivHeight = 0;
|
||||
let itemHeigh = 32 + 10;
|
||||
|
||||
let optionTypeHeight = this.parameters.length * itemHeigh;
|
||||
let firstHeight = 32;
|
||||
let endHeight = 32;
|
||||
|
||||
let marginTopHeight = ((firstHeight - 32) / 2 + 21);
|
||||
let topHeightLine = ((optionTypeHeight / 2 - marginTopHeight - 16));
|
||||
let divMarginBottom = ((endHeight - 32) / 2 + 16);
|
||||
let bottomHeight = optionTypeHeight - 32 - (topHeightLine + marginTopHeight + divMarginBottom);
|
||||
|
||||
this.lineDivTopHeight = topHeightLine;
|
||||
this.lineDivMarginTopHeight = marginTopHeight;
|
||||
this.lineDivBottomHeight = (bottomHeight > 0 ? bottomHeight : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.top-line-box {
|
||||
border-top: 1px solid;
|
||||
border-left: 1px solid;
|
||||
margin-left: 32px;
|
||||
border-top-left-radius: 10px;
|
||||
}
|
||||
|
||||
.bottom-line-box {
|
||||
border-bottom: 1px solid;
|
||||
border-left: 1px solid;
|
||||
margin-left: 32px;
|
||||
border-bottom-left-radius: 10px;
|
||||
}
|
||||
</style>
|
|
@ -32,10 +32,7 @@
|
|||
<el-row>
|
||||
<el-link class="ms-el-link" @click="batchAdd" style="color: #783887"> {{ $t("commons.batch_add") }}</el-link>
|
||||
</el-row>
|
||||
<mock-api-variable :append-dialog-to-body="true"
|
||||
:suggestions="apiParams.query"
|
||||
:with-mor-setting="true"
|
||||
:is-read-only="isReadOnly" :isShowEnable="isShowEnable" :parameters="request.arguments"/>
|
||||
<mock-combination-condition :filter-type-object="request" :is-read-only="isReadOnly" :is-show-enable="isShowEnable" :suggestions="apiParams.query" :parameters="request.arguments"/>
|
||||
</el-tab-pane>
|
||||
|
||||
<!--REST 参数-->
|
||||
|
@ -51,9 +48,7 @@
|
|||
<el-row>
|
||||
<el-link class="ms-el-link" @click="batchAdd" style="color: #783887"> {{ $t("commons.batch_add") }}</el-link>
|
||||
</el-row>
|
||||
<mock-api-variable :append-dialog-to-body="true"
|
||||
:suggestions="apiParams.rest"
|
||||
:with-mor-setting="true" :is-read-only="isReadOnly" :isShowEnable="isShowEnable" :parameters="request.rest"/>
|
||||
<mock-combination-condition :filter-type-object="request" :is-read-only="isReadOnly" :is-show-enable="isShowEnable" :suggestions="apiParams.rest" :parameters="request.rest"/>
|
||||
</el-tab-pane>
|
||||
|
||||
<!--请求体-->
|
||||
|
@ -82,7 +77,6 @@ import MsApiKeyValue from "@/business/components/api/definition/components/ApiKe
|
|||
import MsApiAuthConfig from "@/business/components/api/definition/components/auth/ApiAuthConfig";
|
||||
import ApiRequestMethodSelect from "@/business/components/api/definition/components/collapse/ApiRequestMethodSelect";
|
||||
import {REQUEST_HEADERS} from "@/common/js/constants";
|
||||
import MockApiVariable from "@/business/components/api/definition/components/mock/Components/MockApiVariable";
|
||||
import MsApiAssertions from "@/business/components/api/definition/components/assertion/ApiAssertions";
|
||||
import MsApiExtract from "@/business/components/api/definition/components/extract/ApiExtract";
|
||||
import {Body, KeyValue} from "@/business/components/api/definition/model/ApiTestModel";
|
||||
|
@ -94,6 +88,8 @@ import ApiDefinitionStepButton from "@/business/components/api/definition/compon
|
|||
import {hasPermission} from '@/common/js/utils';
|
||||
import Convert from "@/business/components/common/json-schema/convert/convert";
|
||||
import MockApiBody from "@/business/components/api/definition/components/mock/Components/MockApiBody";
|
||||
import MockCombinationCondition
|
||||
from "@/business/components/api/definition/components/mock/Components/MockCombinationCondition";
|
||||
|
||||
export default {
|
||||
name: "MockRequestParam",
|
||||
|
@ -102,13 +98,13 @@ export default {
|
|||
MsJsr233Processor,
|
||||
MsApiAdvancedConfig,
|
||||
BatchAddParameter,
|
||||
MockApiVariable,
|
||||
ApiRequestMethodSelect,
|
||||
MsApiExtract,
|
||||
MsApiAuthConfig,
|
||||
MockApiBody,
|
||||
MsApiKeyValue,
|
||||
MsApiAssertions
|
||||
MsApiAssertions,
|
||||
MockCombinationCondition,
|
||||
},
|
||||
props: {
|
||||
method: String,
|
||||
|
|
|
@ -1,26 +1,29 @@
|
|||
<template>
|
||||
<el-header style="width: 100% ;padding: 0px">
|
||||
<el-card>
|
||||
<el-row>
|
||||
<el-col :span="1">
|
||||
{{$t('commons.name')}}
|
||||
</el-col>
|
||||
<el-col :span="10">
|
||||
<el-input class="ms-http-input" style="width: 80%" size="small" v-model="mockExpectConfig.name"/>
|
||||
</el-col>
|
||||
<el-col :span="1">
|
||||
{{$t('commons.tag')}}
|
||||
</el-col>
|
||||
<el-col :span="10">
|
||||
<ms-input-tag :currentScenario="mockExpectConfig" style="width: 80%;height: 100%;white-space: nowrap;overflow: hidden" v-if="showHeadTable" ref="tag"/>
|
||||
</el-col>
|
||||
<el-col :span="2">
|
||||
<el-button type="primary" size="small" @click="saveMockExpectConfig" title="ctrl + s">{{
|
||||
$t('commons.save')
|
||||
}}
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="1">
|
||||
{{ $t('commons.name') }}
|
||||
</el-col>
|
||||
<el-col :span="9">
|
||||
<el-input class="ms-http-input" style="width: 80%" size="small" v-model="mockExpectConfig.name"/>
|
||||
</el-col>
|
||||
<el-col :span="1">
|
||||
{{ $t('commons.tag') }}
|
||||
</el-col>
|
||||
<el-col :span="9">
|
||||
<ms-input-tag :currentScenario="mockExpectConfig"
|
||||
style="width: 80%;height: 100%;white-space: nowrap;overflow: hidden" v-if="showHeadTable"
|
||||
ref="tag"/>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-button type="primary" size="small" style="float: right;margin-right: 50px;" @click="saveMockExpectConfig"
|
||||
title="ctrl + s">{{
|
||||
$t('commons.save')
|
||||
}}
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-card>
|
||||
</el-header>
|
||||
</template>
|
||||
|
@ -33,19 +36,17 @@ export default {
|
|||
name: "MockConfigHeader",
|
||||
components: {MsInputTag},
|
||||
data() {
|
||||
return {
|
||||
}
|
||||
return {}
|
||||
},
|
||||
props: {
|
||||
mockExpectConfig: Object,
|
||||
showHeadTable:Boolean,
|
||||
showHeadTable: Boolean,
|
||||
},
|
||||
created() {
|
||||
},
|
||||
watch: {
|
||||
},
|
||||
watch: {},
|
||||
methods: {
|
||||
saveMockExpectConfig(){
|
||||
saveMockExpectConfig() {
|
||||
this.$emit("saveMockExpectConfig");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue