fix(接口测试): 修复用例执行未选择环境不提示问题 (#10989)
--bug=1010594 --user=赵勇 【接口测试】执行用例,没选过环境,执行使用了mock环境 https://www.tapd.cn/55049933/s/1109818 Co-authored-by: fit2-zhao <yong.zhao@fit2cloud.com> Co-authored-by: fit2-zhao <70558837+fit2-zhao@users.noreply.github.com>
This commit is contained in:
parent
1b34753ccc
commit
a8b28badd1
|
@ -14,9 +14,9 @@ public class ApiDefinitionEnvController {
|
|||
@Resource
|
||||
private ApiDefinitionEnvService apiDefinitionEnvService;
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public ApiDefinitionEnv get(@PathVariable String id) {
|
||||
return apiDefinitionEnvService.get(id);
|
||||
@GetMapping("/get/{id}/{projectId}")
|
||||
public ApiDefinitionEnv get(@PathVariable String id, @PathVariable String projectId) {
|
||||
return apiDefinitionEnvService.get(id, projectId);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/create")
|
||||
|
|
|
@ -10,7 +10,6 @@ import io.metersphere.api.exec.api.ApiCaseExecuteService;
|
|||
import io.metersphere.api.exec.api.ApiExecuteService;
|
||||
import io.metersphere.api.service.ApiTestCaseService;
|
||||
import io.metersphere.base.domain.ApiTestCase;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestEnvironment;
|
||||
import io.metersphere.commons.constants.NoticeConstants;
|
||||
import io.metersphere.commons.constants.OperLogConstants;
|
||||
|
|
|
@ -197,25 +197,26 @@ public class ApiCaseExecuteService {
|
|||
Map<String, ApiDefinitionExecResult> executeQueue = new LinkedHashMap<>();
|
||||
String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? APITestStatus.Waiting.name() : APITestStatus.Running.name();
|
||||
|
||||
String finalSerialReportId = serialReportId;
|
||||
caseList.forEach(caseWithBLOBs -> {
|
||||
for (int i = 0; i < caseList.size(); i++) {
|
||||
ApiTestCaseWithBLOBs caseWithBLOBs = caseList.get(i);
|
||||
ApiDefinitionExecResult report = ApiDefinitionExecResultUtil.initBase(caseWithBLOBs.getId(), APITestStatus.Running.name(), null, request.getConfig());
|
||||
report.setStatus(status);
|
||||
report.setName(caseWithBLOBs.getName());
|
||||
report.setProjectId(caseWithBLOBs.getProjectId());
|
||||
report.setVersionId(caseWithBLOBs.getVersionId());
|
||||
if (StringUtils.isNotEmpty(finalSerialReportId)) {
|
||||
report.setIntegratedReportId(finalSerialReportId);
|
||||
report.setCreateTime(System.currentTimeMillis() + i);
|
||||
if (StringUtils.isNotEmpty(serialReportId)) {
|
||||
report.setIntegratedReportId(serialReportId);
|
||||
}
|
||||
executeQueue.put(caseWithBLOBs.getId(), report);
|
||||
responseDTOS.add(new MsExecResponseDTO(caseWithBLOBs.getId(), report.getId(), request.getTriggerMode()));
|
||||
});
|
||||
}
|
||||
|
||||
apiCaseResultService.batchSave(executeQueue);
|
||||
|
||||
String reportType = request.getConfig().getReportType();
|
||||
String poolId = request.getConfig().getResourcePoolId();
|
||||
DBTestQueue deQueue = apiExecutionQueueService.add(executeQueue, poolId, ApiRunMode.DEFINITION.name(), finalSerialReportId, reportType, ApiRunMode.DEFINITION.name(), request.getConfig());
|
||||
DBTestQueue deQueue = apiExecutionQueueService.add(executeQueue, poolId, ApiRunMode.DEFINITION.name(), serialReportId, reportType, ApiRunMode.DEFINITION.name(), request.getConfig());
|
||||
// 开始选择执行模式
|
||||
if (deQueue != null && deQueue.getQueue() != null) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
|
|
@ -2,7 +2,9 @@ package io.metersphere.api.service;
|
|||
|
||||
import io.metersphere.base.domain.ApiDefinitionEnv;
|
||||
import io.metersphere.base.domain.ApiDefinitionEnvExample;
|
||||
import io.metersphere.base.domain.ApiTestEnvironmentExample;
|
||||
import io.metersphere.base.mapper.ApiDefinitionEnvMapper;
|
||||
import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -16,6 +18,8 @@ import java.util.UUID;
|
|||
public class ApiDefinitionEnvService {
|
||||
@Resource
|
||||
private ApiDefinitionEnvMapper apiDefinitionEnvMapper;
|
||||
@Resource
|
||||
private ApiTestEnvironmentMapper apiTestEnvironmentMapper;
|
||||
|
||||
public void insert(ApiDefinitionEnv env) {
|
||||
env.setId(UUID.randomUUID().toString());
|
||||
|
@ -31,6 +35,22 @@ public class ApiDefinitionEnvService {
|
|||
}
|
||||
}
|
||||
|
||||
public ApiDefinitionEnv get(String userId, String projectId) {
|
||||
ApiDefinitionEnvExample example = new ApiDefinitionEnvExample();
|
||||
example.createCriteria().andUserIdEqualTo(userId);
|
||||
List<ApiDefinitionEnv> list = apiDefinitionEnvMapper.selectByExample(example);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
ApiTestEnvironmentExample environmentExample = new ApiTestEnvironmentExample();
|
||||
environmentExample.createCriteria().andProjectIdEqualTo(projectId).andIdEqualTo(list.get(0).getEnvId());
|
||||
long count = apiTestEnvironmentMapper.countByExample(environmentExample);
|
||||
if (count > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ApiDefinitionEnv get(String userId) {
|
||||
ApiDefinitionEnvExample example = new ApiDefinitionEnvExample();
|
||||
example.createCriteria().andUserIdEqualTo(userId);
|
||||
|
|
|
@ -361,7 +361,10 @@ public class ApiDefinitionExecResultService {
|
|||
|
||||
saveResult.setName(item.getName());
|
||||
saveResult.setType(type);
|
||||
saveResult.setCreateTime(item.getStartTime());
|
||||
|
||||
if (saveResult.getCreateTime() == null || saveResult.getCreateTime() == 0) {
|
||||
saveResult.setCreateTime(item.getStartTime());
|
||||
}
|
||||
editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId);
|
||||
saveResult.setStatus(status);
|
||||
saveResult.setResourceId(item.getName());
|
||||
|
|
|
@ -282,7 +282,7 @@ public class ApiScenarioReportStructureService {
|
|||
private List<ApiDefinitionExecResultVo> formatApiReport(String reportId, List<StepTreeDTO> stepList) {
|
||||
ApiDefinitionExecResultExample example = new ApiDefinitionExecResultExample();
|
||||
example.createCriteria().andIntegratedReportIdEqualTo(reportId);
|
||||
example.setOrderByClause("end_time desc");
|
||||
example.setOrderByClause("create_time asc");
|
||||
List<ApiDefinitionExecResult> reportResults = definitionExecResultMapper.selectByExampleWithBLOBs(example);
|
||||
List<ApiDefinitionExecResultVo> resultVos = new LinkedList<>();
|
||||
for (int i = 0; i < reportResults.size(); i++) {
|
||||
|
|
|
@ -44,8 +44,7 @@
|
|||
right-content="CASE"
|
||||
>
|
||||
<template v-slot:version>
|
||||
<version-select v-xpack :project-id="projectId" :version-id="trashVersion"
|
||||
@changeVersion="changeVersion"/>
|
||||
<version-select v-xpack :project-id="projectId" :version-id="trashVersion" @changeVersion="changeVersion"/>
|
||||
</template>
|
||||
<!-- 列表集合 -->
|
||||
<ms-api-list
|
||||
|
@ -455,7 +454,7 @@ export default {
|
|||
});
|
||||
},
|
||||
getEnv() {
|
||||
this.$get("/api/definition/env/get/" + getCurrentUserId(), response => {
|
||||
this.$get("/api/definition/env/get/" + getCurrentUserId() + "/" + getCurrentProjectID(), response => {
|
||||
let env = response.data;
|
||||
if (env) {
|
||||
this.$store.state.useEnvironment = env.envId;
|
||||
|
|
Loading…
Reference in New Issue