feat (接口自动化): 完成优化需求10

--story=1002982 --user=赵勇 10.调整步骤顺序后 会... https://www.tapd.cn/55049933/s/1045288
This commit is contained in:
fit2-zhao 2021-09-10 14:27:24 +08:00 committed by fit2-zhao
parent a15a66194e
commit faa608003c
7 changed files with 48 additions and 17 deletions

View File

@ -353,7 +353,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId, this.getEnvironmentId())) { if (StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId, this.getEnvironmentId())) {
this.setEnvironmentId(useEvnId); this.setEnvironmentId(useEvnId);
} }
HttpConfig httpConfig = getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig()); HttpConfig httpConfig = matchConfig(config);
httpConfig.setPreProcessor(environmentConfig.getPreProcessor()); httpConfig.setPreProcessor(environmentConfig.getPreProcessor());
httpConfig.setPostProcessor(environmentConfig.getPostProcessor()); httpConfig.setPostProcessor(environmentConfig.getPostProcessor());
return httpConfig; return httpConfig;
@ -725,10 +725,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
/** /**
* 按照环境规则匹配环境 * 按照环境规则匹配环境
* *
* @param httpConfig * @param parameterConfig
* @return * @return
*/ */
private HttpConfig getHttpConfig(HttpConfig httpConfig) { private HttpConfig matchConfig(ParameterConfig parameterConfig) {
HttpConfig httpConfig = parameterConfig.getConfig().get(this.getProjectId()).getHttpConfig();
boolean isNext = true; boolean isNext = true;
if (CollectionUtils.isNotEmpty(httpConfig.getConditions())) { if (CollectionUtils.isNotEmpty(httpConfig.getConditions())) {
for (HttpConfigCondition item : httpConfig.getConditions()) { for (HttpConfigCondition item : httpConfig.getConditions()) {

View File

@ -2,11 +2,16 @@ package io.metersphere.api.dto.scenario;
import io.metersphere.api.dto.definition.request.processors.post.MsJSR223PostProcessor; import io.metersphere.api.dto.definition.request.processors.post.MsJSR223PostProcessor;
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor; import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
import io.metersphere.base.domain.ApiModule;
import io.metersphere.base.domain.ApiModuleExample;
import io.metersphere.base.mapper.ApiModuleMapper;
import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.CommonBeanFactory;
import lombok.Data; import lombok.Data;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -24,6 +29,8 @@ public class HttpConfig {
private MsJSR223PreProcessor preProcessor; private MsJSR223PreProcessor preProcessor;
private MsJSR223PostProcessor postProcessor; private MsJSR223PostProcessor postProcessor;
private ApiModuleMapper apiModuleMapper;
public HttpConfig initHttpConfig(HttpConfigCondition configCondition) { public HttpConfig initHttpConfig(HttpConfigCondition configCondition) {
HttpConfig config = new HttpConfig(); HttpConfig config = new HttpConfig();
config.isMock = this.isMock; config.isMock = this.isMock;
@ -42,10 +49,33 @@ public class HttpConfig {
return null; return null;
} }
private void getAllChild(String moduleId, List<String> allChild) {
// 找出所有子模块
if (apiModuleMapper == null) {
apiModuleMapper = CommonBeanFactory.getBean(ApiModuleMapper.class);
}
allChild.add(moduleId);
ApiModuleExample example = new ApiModuleExample();
example.createCriteria().andParentIdEqualTo(moduleId);
List<ApiModule> modules = apiModuleMapper.selectByExample(example);
for (ApiModule module : modules) {
getAllChild(module.getId(), allChild);
}
}
public HttpConfig getModuleCondition(String moduleId, HttpConfigCondition configCondition) { public HttpConfig getModuleCondition(String moduleId, HttpConfigCondition configCondition) {
List<String> moduleIds = new ArrayList<>();
if (CollectionUtils.isNotEmpty(configCondition.getDetails())) { if (CollectionUtils.isNotEmpty(configCondition.getDetails())) {
List<KeyValue> details = configCondition.getDetails().stream().filter(detail -> StringUtils.contains(detail.getValue(), moduleId)).collect(Collectors.toList()); if (CollectionUtils.isEmpty(configCondition.getModuleIds())) {
if (CollectionUtils.isNotEmpty(details)) { for (KeyValue keyValue : configCondition.getDetails()) {
getAllChild(keyValue.getValue(), moduleIds);
}
configCondition.setModuleIds(moduleIds);
} else {
moduleIds = configCondition.getModuleIds();
}
if (moduleIds.contains(moduleId)) {
return initHttpConfig(configCondition); return initHttpConfig(configCondition);
} }
} }

View File

@ -13,4 +13,6 @@ public class HttpConfigCondition {
private String domain; private String domain;
private int port; private int port;
private List<KeyValue> headers; private List<KeyValue> headers;
private List<String> moduleIds;
} }

View File

@ -196,7 +196,7 @@
highlight-current highlight-current
@node-expand="nodeExpand" @node-expand="nodeExpand"
@node-collapse="nodeCollapse" @node-collapse="nodeCollapse"
:allow-drop="allowDrop" @node-drag-end="allowDrag" @node-click="nodeClick" v-if="!loading" draggable ref="stepTree"> :allow-drop="allowDrop" @node-drag-end="allowDrag" @node-click="nodeClick" draggable ref="stepTree">
<span class="custom-tree-node father" slot-scope="{ node, data}" style="width: 96%"> <span class="custom-tree-node father" slot-scope="{ node, data}" style="width: 96%">
<!-- 步骤组件--> <!-- 步骤组件-->
<ms-component-config <ms-component-config
@ -1028,7 +1028,6 @@ export default {
const index = hashTree.findIndex(d => d.resourceId !== undefined && row.resourceId !== undefined && d.resourceId === row.resourceId) const index = hashTree.findIndex(d => d.resourceId !== undefined && row.resourceId !== undefined && d.resourceId === row.resourceId)
hashTree.splice(index, 1); hashTree.splice(index, 1);
this.sort(); this.sort();
this.reload();
} }
} }
}); });
@ -1060,7 +1059,6 @@ export default {
hashTree.push(obj); hashTree.push(obj);
} }
this.sort(); this.sort();
this.reload();
}, },
reload() { reload() {
this.loading = true this.loading = true

View File

@ -5,9 +5,6 @@
<el-button v-if="scenario" style="float: right;margin-right: 20px" size="small" type="primary" <el-button v-if="scenario" style="float: right;margin-right: 20px" size="small" type="primary"
@click="handleCommand"> {{ $t('commons.test') }} @click="handleCommand"> {{ $t('commons.test') }}
</el-button> </el-button>
<el-button size="small" type="primary" class="ms-api-buttion" style="float: right;margin-right: 20px" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
<el-dropdown v-else split-button type="primary" class="ms-api-buttion" @click="handleCommand" <el-dropdown v-else split-button type="primary" class="ms-api-buttion" @click="handleCommand"
@command="handleCommand" size="small" style="float: right;margin-right: 20px"> @command="handleCommand" size="small" style="float: right;margin-right: 20px">
{{ $t('commons.test') }} {{ $t('commons.test') }}
@ -15,6 +12,9 @@
<el-dropdown-item command="save_as">{{ $t('api_test.definition.request.save_as_case') }}</el-dropdown-item> <el-dropdown-item command="save_as">{{ $t('api_test.definition.request.save_as_case') }}</el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
<el-button size="small" type="primary" class="ms-api-buttion" style="float: right;margin-right: 20px" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p> <p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<div v-loading="loading"> <div v-loading="loading">
<!-- 请求参数 --> <!-- 请求参数 -->

View File

@ -5,9 +5,6 @@
<el-button v-if="scenario" style="float: right;margin-right: 20px" size="small" type="primary" <el-button v-if="scenario" style="float: right;margin-right: 20px" size="small" type="primary"
@click="handleCommand"> {{ $t('commons.test') }} @click="handleCommand"> {{ $t('commons.test') }}
</el-button> </el-button>
<el-button size="small" type="primary" class="ms-api-buttion" style="float: right;margin-right: 20px" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
<el-dropdown v-else split-button type="primary" class="ms-api-buttion" @click="handleCommand" <el-dropdown v-else split-button type="primary" class="ms-api-buttion" @click="handleCommand"
@command="handleCommand" size="small" style="float: right;margin-right: 20px"> @command="handleCommand" size="small" style="float: right;margin-right: 20px">
{{ $t('commons.test') }} {{ $t('commons.test') }}
@ -15,6 +12,9 @@
<el-dropdown-item command="save_as">{{ $t('api_test.definition.request.save_as_case') }}</el-dropdown-item> <el-dropdown-item command="save_as">{{ $t('api_test.definition.request.save_as_case') }}</el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
<el-button size="small" type="primary" class="ms-api-buttion" style="float: right;margin-right: 20px" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p> <p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<div v-loading="loading"> <div v-loading="loading">
<!-- JDBC 请求参数 --> <!-- JDBC 请求参数 -->

View File

@ -13,9 +13,6 @@
<el-form-item> <el-form-item>
<el-button v-if="scenario" size="small" type="primary" @click="handleCommand"> {{ $t('commons.test') }} <el-button v-if="scenario" size="small" type="primary" @click="handleCommand"> {{ $t('commons.test') }}
</el-button> </el-button>
<el-button size="small" type="primary" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
<el-dropdown v-else split-button type="primary" class="ms-api-buttion" @click="handleCommand" <el-dropdown v-else split-button type="primary" class="ms-api-buttion" @click="handleCommand"
@command="handleCommand" size="small" style="float: right;margin-right: 20px"> @command="handleCommand" size="small" style="float: right;margin-right: 20px">
{{ $t('commons.test') }} {{ $t('commons.test') }}
@ -24,6 +21,9 @@
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
<el-button size="small" type="primary" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div v-loading="loading"> <div v-loading="loading">