Merge branch 'v1.6'
This commit is contained in:
commit
3801ab6bb5
|
@ -85,15 +85,15 @@ public class ApiAutomationController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/run")
|
@PostMapping(value = "/run")
|
||||||
public void run(@RequestBody RunScenarioRequest request) {
|
public String run(@RequestBody RunScenarioRequest request) {
|
||||||
request.setExecuteType(ExecuteType.Completed.name());
|
request.setExecuteType(ExecuteType.Completed.name());
|
||||||
apiAutomationService.run(request);
|
return apiAutomationService.run(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/run/batch")
|
@PostMapping(value = "/run/batch")
|
||||||
public void runBatch(@RequestBody RunScenarioRequest request) {
|
public String runBatch(@RequestBody RunScenarioRequest request) {
|
||||||
request.setExecuteType(ExecuteType.Saved.name());
|
request.setExecuteType(ExecuteType.Saved.name());
|
||||||
apiAutomationService.run(request);
|
return apiAutomationService.run(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,4 +98,9 @@ public class ApiTestCaseController {
|
||||||
public void testPlanRelevance(@RequestBody ApiCaseRelevanceRequest request) {
|
public void testPlanRelevance(@RequestBody ApiCaseRelevanceRequest request) {
|
||||||
apiTestCaseService.relevanceByCase(request);
|
apiTestCaseService.relevanceByCase(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/jenkins/run")
|
||||||
|
public String jenkinsRun(@RequestPart("request") RunCaseRequest request) {
|
||||||
|
return apiTestCaseService.run(request);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package io.metersphere.api.dto.definition;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class RunCaseRequest {
|
||||||
|
|
||||||
|
private String caseId;
|
||||||
|
|
||||||
|
private String reportId;
|
||||||
|
}
|
|
@ -1,11 +1,14 @@
|
||||||
package io.metersphere.api.service;
|
package io.metersphere.api.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.metersphere.api.dto.automation.ApiScenarioDTO;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import io.metersphere.api.dto.automation.ApiScenarioRequest;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import io.metersphere.api.dto.ApiCaseBatchRequest;
|
||||||
import io.metersphere.api.dto.datacount.ApiDataCountResult;
|
import io.metersphere.api.dto.datacount.ApiDataCountResult;
|
||||||
import io.metersphere.api.dto.definition.*;
|
import io.metersphere.api.dto.definition.*;
|
||||||
import io.metersphere.api.dto.ApiCaseBatchRequest;
|
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||||
|
import io.metersphere.api.jmeter.JMeterService;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||||
|
@ -14,6 +17,7 @@ import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper;
|
import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper;
|
import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
|
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
|
||||||
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.*;
|
import io.metersphere.commons.utils.*;
|
||||||
import io.metersphere.i18n.Translator;
|
import io.metersphere.i18n.Translator;
|
||||||
|
@ -21,11 +25,12 @@ import io.metersphere.service.FileService;
|
||||||
import io.metersphere.service.QuotaService;
|
import io.metersphere.service.QuotaService;
|
||||||
import io.metersphere.service.UserService;
|
import io.metersphere.service.UserService;
|
||||||
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.ibatis.session.ExecutorType;
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.apache.jorphan.collections.HashTree;
|
||||||
import org.aspectj.util.FileUtil;
|
import org.aspectj.util.FileUtil;
|
||||||
import org.python.antlr.ast.Str;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
@ -57,6 +62,8 @@ public class ApiTestCaseService {
|
||||||
private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper;
|
private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiDefinitionMapper apiDefinitionMapper;
|
private ApiDefinitionMapper apiDefinitionMapper;
|
||||||
|
@Resource
|
||||||
|
private JMeterService jMeterService;
|
||||||
|
|
||||||
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
|
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
|
||||||
|
|
||||||
|
@ -271,7 +278,7 @@ public class ApiTestCaseService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteBatch(List<String> ids) {
|
public void deleteBatch(List<String> ids) {
|
||||||
for (String testId:ids) {
|
for (String testId : ids) {
|
||||||
extTestPlanTestCaseMapper.deleteByTestCaseID(testId);
|
extTestPlanTestCaseMapper.deleteByTestCaseID(testId);
|
||||||
}
|
}
|
||||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||||
|
@ -331,10 +338,10 @@ public class ApiTestCaseService {
|
||||||
Date firstTime = startAndEndDateInWeek.get("firstTime");
|
Date firstTime = startAndEndDateInWeek.get("firstTime");
|
||||||
Date lastTime = startAndEndDateInWeek.get("lastTime");
|
Date lastTime = startAndEndDateInWeek.get("lastTime");
|
||||||
|
|
||||||
if(firstTime==null || lastTime == null){
|
if (firstTime == null || lastTime == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}else {
|
} else {
|
||||||
return extApiTestCaseMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime());
|
return extApiTestCaseMapper.countByProjectIDAndCreateInThisWeek(projectId, firstTime.getTime(), lastTime.getTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,16 +358,16 @@ public class ApiTestCaseService {
|
||||||
|
|
||||||
public void deleteBatchByParam(ApiTestBatchRequest request) {
|
public void deleteBatchByParam(ApiTestBatchRequest request) {
|
||||||
List<String> ids = request.getIds();
|
List<String> ids = request.getIds();
|
||||||
if(request.isSelectAllDate()){
|
if (request.isSelectAllDate()) {
|
||||||
ids = this.getAllApiCaseIdsByFontedSelect(request.getFilters(),request.getModuleIds(),request.getName(),request.getProjectId(),request.getProtocol(),request.getUnSelectIds(),request.getStatus());
|
ids = this.getAllApiCaseIdsByFontedSelect(request.getFilters(), request.getModuleIds(), request.getName(), request.getProjectId(), request.getProtocol(), request.getUnSelectIds(), request.getStatus());
|
||||||
}
|
}
|
||||||
this.deleteBatch(ids);
|
this.deleteBatch(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editApiBathByParam(ApiTestBatchRequest request) {
|
public void editApiBathByParam(ApiTestBatchRequest request) {
|
||||||
List<String> ids = request.getIds();
|
List<String> ids = request.getIds();
|
||||||
if(request.isSelectAllDate()){
|
if (request.isSelectAllDate()) {
|
||||||
ids = this.getAllApiCaseIdsByFontedSelect(request.getFilters(),request.getModuleIds(),request.getName(),request.getProjectId(),request.getProtocol(),request.getUnSelectIds(),request.getStatus());
|
ids = this.getAllApiCaseIdsByFontedSelect(request.getFilters(), request.getModuleIds(), request.getName(), request.getProjectId(), request.getProtocol(), request.getUnSelectIds(), request.getStatus());
|
||||||
}
|
}
|
||||||
request.cleanSelectParam();
|
request.cleanSelectParam();
|
||||||
ApiTestCaseExample apiDefinitionExample = new ApiTestCaseExample();
|
ApiTestCaseExample apiDefinitionExample = new ApiTestCaseExample();
|
||||||
|
@ -371,7 +378,7 @@ public class ApiTestCaseService {
|
||||||
apiTestCaseMapper.updateByExampleSelective(apiDefinitionWithBLOBs, apiDefinitionExample);
|
apiTestCaseMapper.updateByExampleSelective(apiDefinitionWithBLOBs, apiDefinitionExample);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getAllApiCaseIdsByFontedSelect(Map<String, List<String>> filters,List<String>moduleIds, String name, String projectId, String protocol,List<String> unSelectIds,String status) {
|
private List<String> getAllApiCaseIdsByFontedSelect(Map<String, List<String>> filters, List<String> moduleIds, String name, String projectId, String protocol, List<String> unSelectIds, String status) {
|
||||||
ApiTestCaseRequest selectRequest = new ApiTestCaseRequest();
|
ApiTestCaseRequest selectRequest = new ApiTestCaseRequest();
|
||||||
selectRequest.setFilters(filters);
|
selectRequest.setFilters(filters);
|
||||||
selectRequest.setModuleIds(moduleIds);
|
selectRequest.setModuleIds(moduleIds);
|
||||||
|
@ -383,6 +390,27 @@ public class ApiTestCaseService {
|
||||||
List<ApiTestCaseResult> list = extApiTestCaseMapper.list(selectRequest);
|
List<ApiTestCaseResult> list = extApiTestCaseMapper.list(selectRequest);
|
||||||
List<String> allIds = list.stream().map(ApiTestCaseResult::getId).collect(Collectors.toList());
|
List<String> allIds = list.stream().map(ApiTestCaseResult::getId).collect(Collectors.toList());
|
||||||
List<String> ids = allIds.stream().filter(id -> !unSelectIds.contains(id)).collect(Collectors.toList());
|
List<String> ids = allIds.stream().filter(id -> !unSelectIds.contains(id)).collect(Collectors.toList());
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String run(RunCaseRequest request) {
|
||||||
|
ApiTestCaseWithBLOBs testCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(request.getCaseId());
|
||||||
|
// 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取
|
||||||
|
if (testCaseWithBLOBs != null && StringUtils.isNotEmpty(testCaseWithBLOBs.getRequest())) {
|
||||||
|
try {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
MsTestElement elements = mapper.readValue(testCaseWithBLOBs.getRequest(), new TypeReference<MsTestElement>() { });
|
||||||
|
HashTree hashTree = elements.generateHashTree();
|
||||||
|
String runMode = ApiRunMode.DELIMIT.name();
|
||||||
|
// 调用执行方法
|
||||||
|
jMeterService.runDefinition(request.getReportId(), hashTree, request.getReportId(), runMode);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogUtil.error(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return request.getReportId();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,6 +333,13 @@
|
||||||
and project_id= #{request.projectId}
|
and project_id= #{request.projectId}
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
|
UNION ALL
|
||||||
|
select id,name,status,project_id,"scenario" as type from api_scenario
|
||||||
|
<where>
|
||||||
|
<if test="request.projectId!=null">
|
||||||
|
and project_id= #{request.projectId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
</select>
|
</select>
|
||||||
<select id="listByTestCaseIds" resultType="io.metersphere.track.dto.TestCaseDTO">
|
<select id="listByTestCaseIds" resultType="io.metersphere.track.dto.TestCaseDTO">
|
||||||
select test_case.*,api_test.name as apiName,load_test.name AS performName from test_case left join api_test on
|
select test_case.*,api_test.name as apiName,load_test.name AS performName from test_case left join api_test on
|
||||||
|
|
|
@ -15,6 +15,8 @@ public interface ExtTestPlanTestCaseMapper {
|
||||||
|
|
||||||
List<TestPlanCaseDTO> list(@Param("request") QueryTestPlanCaseRequest request);
|
List<TestPlanCaseDTO> list(@Param("request") QueryTestPlanCaseRequest request);
|
||||||
|
|
||||||
|
List<TestPlanCaseDTO> listByPlanId(@Param("request") QueryTestPlanCaseRequest request);
|
||||||
|
|
||||||
List<TestPlanCaseDTO> listByNode(@Param("request") QueryTestPlanCaseRequest request);
|
List<TestPlanCaseDTO> listByNode(@Param("request") QueryTestPlanCaseRequest request);
|
||||||
|
|
||||||
List<TestPlanCaseDTO> listByNodes(@Param("request") QueryTestPlanCaseRequest request);
|
List<TestPlanCaseDTO> listByNodes(@Param("request") QueryTestPlanCaseRequest request);
|
||||||
|
|
|
@ -334,6 +334,34 @@
|
||||||
test_plan_test_case
|
test_plan_test_case
|
||||||
where plan_id = #{planId}
|
where plan_id = #{planId}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="listByPlanId" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
|
||||||
|
SELECT test_plan_api_case.api_case_id as id,"definition" as type,api_test_case.name,test_plan_api_case.status
|
||||||
|
from test_plan_api_case left join api_test_case on test_plan_api_case.api_case_id=api_test_case.id
|
||||||
|
<where>
|
||||||
|
<if test="request.planId != null">
|
||||||
|
and test_plan_api_case.test_plan_id = #{request.planId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
UNION ALL
|
||||||
|
SELECT test_plan_api_scenario.api_scenario_id as id,"scenario" as type,api_scenario.name,test_plan_api_scenario.status
|
||||||
|
from test_plan_api_scenario left join api_scenario on test_plan_api_scenario.api_scenario_id=api_scenario.id
|
||||||
|
<where>
|
||||||
|
<if test="request.planId != null">
|
||||||
|
and test_plan_api_scenario.test_plan_id = #{request.planId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
UNION ALL
|
||||||
|
SELECT test_case.test_id as id,test_case.type as type,test_case.name,test_plan_test_case.status
|
||||||
|
from test_plan_test_case left join test_case on test_plan_test_case.case_id =test_case.id
|
||||||
|
<where>
|
||||||
|
<if test="request.planId != null">
|
||||||
|
and test_plan_test_case.plan_id = #{request.planId}
|
||||||
|
</if>
|
||||||
|
<if test="request.method != null">
|
||||||
|
and test_case.method = #{request.method}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
<update id="updateTestCaseStates" parameterType="java.lang.String">
|
<update id="updateTestCaseStates" parameterType="java.lang.String">
|
||||||
update test_plan_test_case
|
update test_plan_test_case
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package io.metersphere.commons.constants;
|
package io.metersphere.commons.constants;
|
||||||
|
|
||||||
public enum ApiRunMode {
|
public enum ApiRunMode {
|
||||||
RUN, DEBUG,DELIMIT,SCENARIO, API_PLAN, SCENARIO_PLAN
|
RUN, DEBUG,DELIMIT,SCENARIO, API_PLAN, SCENARIO_PLAN,API
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class TestCaseController {
|
||||||
return testCaseService.listTestCase(request);
|
return testCaseService.listTestCase(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*jenkins项目下所有接口和性能测试用例*/
|
||||||
@GetMapping("/list/method/{projectId}")
|
@GetMapping("/list/method/{projectId}")
|
||||||
public List<TestCaseDTO> listByMethod(@PathVariable String projectId) {
|
public List<TestCaseDTO> listByMethod(@PathVariable String projectId) {
|
||||||
QueryTestCaseRequest request = new QueryTestCaseRequest();
|
QueryTestCaseRequest request = new QueryTestCaseRequest();
|
||||||
|
|
|
@ -30,13 +30,13 @@ public class TestPlanTestCaseController {
|
||||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||||
return PageUtils.setPageInfo(page, testPlanTestCaseService.list(request));
|
return PageUtils.setPageInfo(page, testPlanTestCaseService.list(request));
|
||||||
}
|
}
|
||||||
|
/*jenkins测试计划下全部用例*/
|
||||||
@GetMapping("/list/{planId}")
|
@GetMapping("/list/{planId}")
|
||||||
public List<TestPlanCaseDTO> getTestPlanCaseByPlanId(@PathVariable String planId) {
|
public List<TestPlanCaseDTO> getTestPlanCaseByPlanId(@PathVariable String planId) {
|
||||||
QueryTestPlanCaseRequest request = new QueryTestPlanCaseRequest();
|
QueryTestPlanCaseRequest request = new QueryTestPlanCaseRequest();
|
||||||
request.setPlanId(planId);
|
request.setPlanId(planId);
|
||||||
request.setMethod("auto");
|
request.setMethod("auto");
|
||||||
return testPlanTestCaseService.list(request);
|
return testPlanTestCaseService.listByPlanId(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/list/node/{planId}/{nodePaths}")
|
@GetMapping("/list/node/{planId}/{nodePaths}")
|
||||||
|
|
|
@ -55,6 +55,11 @@ public class TestPlanTestCaseService {
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
public List<TestPlanCaseDTO> listByPlanId(QueryTestPlanCaseRequest request) {
|
||||||
|
List<TestPlanCaseDTO> list = extTestPlanTestCaseMapper.listByPlanId(request);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public List<TestPlanCaseDTO> listByNode(QueryTestPlanCaseRequest request) {
|
public List<TestPlanCaseDTO> listByNode(QueryTestPlanCaseRequest request) {
|
||||||
List<TestPlanCaseDTO> list = extTestPlanTestCaseMapper.listByNode(request);
|
List<TestPlanCaseDTO> list = extTestPlanTestCaseMapper.listByNode(request);
|
||||||
|
|
|
@ -56,10 +56,10 @@
|
||||||
</el-input>
|
</el-input>
|
||||||
</div>
|
</div>
|
||||||
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
|
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
|
||||||
<ms-api-request-form :referenced="true" :headers="request.headers " :request="request" v-if="request.protocol==='HTTP'"/>
|
<ms-api-request-form :referenced="true" :headers="request.headers " :request="request" v-if="request.protocol==='HTTP' || request.type==='HTTPSamplerProxy'"/>
|
||||||
<ms-tcp-basis-parameters :request="request" v-if="request.protocol==='TCP'"/>
|
<ms-tcp-basis-parameters :request="request" v-if="request.protocol==='TCP'|| request.type==='TCPSampler'"/>
|
||||||
<ms-sql-basis-parameters :request="request" v-if="request.protocol==='SQL'"/>
|
<ms-sql-basis-parameters :request="request" v-if="request.protocol==='SQL'|| request.type==='JDBCSampler'"/>
|
||||||
<ms-dubbo-basis-parameters :request="request" v-if="request.protocol==='DUBBO' || request.protocol==='dubbo://'"/>
|
<ms-dubbo-basis-parameters :request="request" v-if="request.protocol==='DUBBO' || request.protocol==='dubbo://'|| request.type==='DubboSampler'"/>
|
||||||
|
|
||||||
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
|
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
|
||||||
<ms-request-result-tail :response="request.requestResult" ref="runResult"/>
|
<ms-request-result-tail :response="request.requestResult" ref="runResult"/>
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
},
|
},
|
||||||
open() {
|
open() {
|
||||||
this.dialogVisible = true;
|
this.dialogVisible = true;
|
||||||
this.size = this.$parent.selectRows.size;
|
this.size = this.$parent.selectDataCounts;
|
||||||
listenGoBack(this.handleClose);
|
listenGoBack(this.handleClose);
|
||||||
},
|
},
|
||||||
handleClose() {
|
handleClose() {
|
||||||
|
|
Loading…
Reference in New Issue