Merge branch 'master' of https://github.com/metersphere/metersphere
This commit is contained in:
commit
c49e4c46b8
|
@ -302,7 +302,7 @@ public class APITestController {
|
|||
if(allCount!=0){
|
||||
float coverageRageNumber =(float)apiCountResult.getSuccessCount()*100/allCount;
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
apiCountResult.setCoverageRage(df.format(coverageRageNumber)+"%");
|
||||
apiCountResult.setSuccessRage(df.format(coverageRageNumber)+"%");
|
||||
}
|
||||
|
||||
return apiCountResult;
|
||||
|
@ -354,6 +354,6 @@ public class APITestController {
|
|||
public void updateScheduleEnableByPrimyKey(@RequestBody ScheduleInfoRequest request) {
|
||||
Schedule schedule = scheduleService.getSchedule(request.getTaskID());
|
||||
schedule.setEnable(request.isEnable());
|
||||
apiTestService.updateSchedule(schedule);
|
||||
apiAutomationService.updateSchedule(schedule);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,21 +44,20 @@ public class ApiDefinitionController {
|
|||
@PostMapping(value = "/create", consumes = {"multipart/form-data"})
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
|
||||
public void create(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
checkPermissionService.checkReadOnlyUser();
|
||||
checkPermissionService.checkProjectOwner(request.getProjectId());
|
||||
apiDefinitionService.create(request, bodyFiles);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/update", consumes = {"multipart/form-data"})
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
|
||||
public void update(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
checkPermissionService.checkReadOnlyUser();
|
||||
checkPermissionService.checkProjectOwner(request.getProjectId());
|
||||
apiDefinitionService.update(request, bodyFiles);
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{id}")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
|
||||
public void delete(@PathVariable String id) {
|
||||
checkPermissionService.checkReadOnlyUser();
|
||||
apiDefinitionService.delete(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.api.jmeter;
|
||||
|
||||
import io.metersphere.api.service.*;
|
||||
import io.metersphere.base.domain.ApiScenarioReport;
|
||||
import io.metersphere.base.domain.ApiTestReport;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
|
@ -20,6 +21,7 @@ import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
|
|||
import org.apache.jmeter.samplers.SampleResult;
|
||||
import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
|
||||
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
|
||||
import org.python.antlr.ast.Str;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -50,6 +52,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
|
||||
private ApiScenarioReportService apiScenarioReportService;
|
||||
|
||||
|
||||
public String runMode = ApiRunMode.RUN.name();
|
||||
|
||||
// 测试ID
|
||||
|
@ -155,6 +158,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
testResult.getScenarios().addAll(scenarios.values());
|
||||
testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getId));
|
||||
ApiTestReport report = null;
|
||||
String reportUrl = null;
|
||||
// 这部分后续优化只留 DELIMIT 和 SCENARIO 两部分
|
||||
if (StringUtils.equals(this.runMode, ApiRunMode.DEBUG.name())) {
|
||||
report = apiReportService.get(debugReportId);
|
||||
|
@ -173,7 +177,31 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
} else if (StringUtils.equalsAny(this.runMode, ApiRunMode.SCENARIO.name(), ApiRunMode.SCENARIO_PLAN.name())) {
|
||||
// 执行报告不需要存储,由用户确认后在存储
|
||||
testResult.setTestId(testId);
|
||||
apiScenarioReportService.complete(testResult, this.runMode);
|
||||
ApiScenarioReport scenarioReport = apiScenarioReportService.complete(testResult, this.runMode);
|
||||
|
||||
|
||||
report = new ApiTestReport();
|
||||
report.setStatus(scenarioReport.getStatus());
|
||||
report.setId(scenarioReport.getId());
|
||||
report.setTriggerMode(scenarioReport.getTriggerMode());
|
||||
report.setName(scenarioReport.getName());
|
||||
|
||||
|
||||
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
||||
assert systemParameterService != null;
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report";
|
||||
|
||||
|
||||
String scenaName = scenarioReport.getName();
|
||||
if(scenaName==null){
|
||||
scenaName = "";
|
||||
}else {
|
||||
scenaName = scenaName.split("-")[0];
|
||||
}
|
||||
|
||||
String scenarioID = apiScenarioReportService.getApiScenarioId(scenaName,scenarioReport.getProjectId());
|
||||
testResult.setTestId(scenarioID);
|
||||
} else {
|
||||
apiTestService.changeStatus(testId, APITestStatus.Completed);
|
||||
report = apiReportService.getRunningReport(testResult.getTestId());
|
||||
|
@ -196,22 +224,24 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
}
|
||||
}
|
||||
try {
|
||||
sendTask(report, testResult);
|
||||
sendTask(report,reportUrl, testResult);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void sendTask(ApiTestReport report, TestResult testResult) {
|
||||
private static void sendTask(ApiTestReport report,String reportUrl, TestResult testResult) {
|
||||
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
||||
NoticeSendService noticeSendService = CommonBeanFactory.getBean(NoticeSendService.class);
|
||||
assert systemParameterService != null;
|
||||
assert noticeSendService != null;
|
||||
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
String url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId();
|
||||
|
||||
String url = reportUrl;
|
||||
if(StringUtils.isEmpty(url)){
|
||||
url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId();
|
||||
}
|
||||
String successContext = "";
|
||||
String failedContext = "";
|
||||
String subject = "";
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.ibatis.session.SqlSession;
|
|||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
import org.python.antlr.ast.Str;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
@ -155,7 +156,7 @@ public class ApiAutomationService {
|
|||
apiScenarioMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void preDelete(String scenarioID){
|
||||
public void preDelete(String scenarioID) {
|
||||
scheduleService.deleteByResourceId(scenarioID);
|
||||
|
||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||
|
@ -169,37 +170,40 @@ public class ApiAutomationService {
|
|||
}
|
||||
example = new TestPlanApiScenarioExample();
|
||||
|
||||
if(!idList.isEmpty()){
|
||||
if (!idList.isEmpty()) {
|
||||
example.createCriteria().andIdIn(idList);
|
||||
testPlanApiScenarioMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
}
|
||||
public void preDelete(List<String> scenarioIDList){
|
||||
|
||||
public void preDelete(List<String> scenarioIDList) {
|
||||
List<String> testPlanApiScenarioIdList = new ArrayList<>();
|
||||
List<String> scheduleIdList = new ArrayList<>();
|
||||
for (String id :scenarioIDList) {
|
||||
for (String id : scenarioIDList) {
|
||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||
example.createCriteria().andApiScenarioIdEqualTo(id);
|
||||
List<TestPlanApiScenario> testPlanApiScenarioList = testPlanApiScenarioMapper.selectByExample(example);
|
||||
for (TestPlanApiScenario api :testPlanApiScenarioList) {
|
||||
if(!testPlanApiScenarioIdList.contains(api.getId())){
|
||||
for (TestPlanApiScenario api : testPlanApiScenarioList) {
|
||||
if (!testPlanApiScenarioIdList.contains(api.getId())) {
|
||||
testPlanApiScenarioIdList.add(api.getId());
|
||||
}
|
||||
}
|
||||
|
||||
scheduleService.deleteByResourceId(id);
|
||||
}
|
||||
if(!testPlanApiScenarioIdList.isEmpty()){
|
||||
if (!testPlanApiScenarioIdList.isEmpty()) {
|
||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||
example.createCriteria().andIdIn(testPlanApiScenarioIdList);
|
||||
testPlanApiScenarioMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void deleteBatch(List<String> ids) {
|
||||
//及连删除外键表
|
||||
preDelete(ids);;
|
||||
preDelete(ids);
|
||||
;
|
||||
ApiScenarioExample example = new ApiScenarioExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
apiScenarioMapper.deleteByExample(example);
|
||||
|
@ -237,16 +241,16 @@ public class ApiAutomationService {
|
|||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private void createAPIScenarioReportResult(String id, String triggerMode, String execType, String projectId,String userID) {
|
||||
private void createAPIScenarioReportResult(String id, String triggerMode, String execType, String projectId, String userID) {
|
||||
APIScenarioReportResult report = new APIScenarioReportResult();
|
||||
report.setId(id);
|
||||
report.setName("测试执行结果");
|
||||
report.setCreateTime(System.currentTimeMillis());
|
||||
report.setUpdateTime(System.currentTimeMillis());
|
||||
report.setStatus(APITestStatus.Running.name());
|
||||
if(StringUtils.isNotEmpty(userID)){
|
||||
if (StringUtils.isNotEmpty(userID)) {
|
||||
report.setUserId(userID);
|
||||
}else {
|
||||
} else {
|
||||
report.setUserId(SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
|
@ -311,7 +315,7 @@ public class ApiAutomationService {
|
|||
jMeterService.runDefinition(request.getId(), jmeterTestPlanHashTree, request.getReportId(), runMode);
|
||||
|
||||
createAPIScenarioReportResult(request.getId(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
||||
request.getExecuteType(), projectID,request.getReportUserID());
|
||||
request.getExecuteType(), projectID, request.getReportUserID());
|
||||
return request.getId();
|
||||
}
|
||||
|
||||
|
@ -361,8 +365,8 @@ public class ApiAutomationService {
|
|||
ExtTestPlanScenarioCaseMapper scenarioBatchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class);
|
||||
ExtTestPlanApiCaseMapper apiCaseBatchMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class);
|
||||
|
||||
for (TestPlanDTO testPlan:list) {
|
||||
if(request.getScenarioIds()!=null){
|
||||
for (TestPlanDTO testPlan : list) {
|
||||
if (request.getScenarioIds() != null) {
|
||||
for (String scenarioId : request.getScenarioIds()) {
|
||||
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
|
||||
testPlanApiScenario.setId(UUID.randomUUID().toString());
|
||||
|
@ -373,7 +377,7 @@ public class ApiAutomationService {
|
|||
scenarioBatchMapper.insertIfNotExists(testPlanApiScenario);
|
||||
}
|
||||
}
|
||||
if(request.getApiIds()!=null){
|
||||
if (request.getApiIds() != null) {
|
||||
for (String caseId : request.getApiIds()) {
|
||||
TestPlanApiCase testPlanApiCase = new TestPlanApiCase();
|
||||
testPlanApiCase.setId(UUID.randomUUID().toString());
|
||||
|
|
|
@ -50,7 +50,18 @@ public class ApiScenarioReportService {
|
|||
@Resource
|
||||
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
|
||||
|
||||
public void complete(TestResult result, String runMode) {
|
||||
public String getApiScenarioId(String name, String projectID) {
|
||||
ApiScenarioExample example = new ApiScenarioExample();
|
||||
example.createCriteria().andNameEqualTo(name).andProjectIdEqualTo(projectID).andStatusNotEqualTo("Trash");
|
||||
List<ApiScenario> list = apiScenarioMapper.selectByExample(example);
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return list.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
public ApiScenarioReport complete(TestResult result, String runMode) {
|
||||
Object obj = cache.get(result.getTestId());
|
||||
if (obj == null) {
|
||||
MSException.throwException(Translator.get("api_report_is_null"));
|
||||
|
@ -83,6 +94,7 @@ public class ApiScenarioReportService {
|
|||
if (!report.getTriggerMode().equals(ReportTriggerMode.SCHEDULE.name())) {
|
||||
cache.put(report.getId(), report);
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
SELECT scene.`name` AS caseName,testPlan.`name` AS testPlan,count(report.id) AS failureTimes,'scenario' AS caseType
|
||||
FROM api_scenario_report report
|
||||
INNER JOIN api_scenario_report_detail reportDetail ON report.id = reportDetail.report_id
|
||||
INNER JOIN api_scenario scene ON reportDetail.content like concat('%"',scene.`name`,'"%')
|
||||
INNER JOIN api_scenario scene ON reportDetail.content like concat('%"', scene.`name`,'"%')
|
||||
LEFT JOIN test_plan_api_scenario apiScene ON apiScene.api_scenario_id = scene.id
|
||||
LEFT JOIN test_plan testPlan ON testPlan.id = apiScene.test_plan_id
|
||||
WHERE report.project_id = #{projectId}
|
||||
|
|
|
@ -179,8 +179,8 @@
|
|||
SELECT count(acr.report_id) AS countNumber FROM api_scenario_report_detail acr
|
||||
INNER JOIN api_scenario_report ar ON ar.id = acr.report_id
|
||||
INNER JOIN (
|
||||
SELECT acitem.id FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
|
||||
) ac on acr.content like CONCAT('%', ac.id,'%')
|
||||
SELECT acitem.`name` FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
|
||||
) ac on acr.content like CONCAT('%"', ac.`name`,'"%')
|
||||
WHERE acr.project_id = #{projectId} AND ar.create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp}
|
||||
</select>
|
||||
|
||||
|
@ -189,8 +189,8 @@
|
|||
FROM api_scenario_report_detail acr
|
||||
INNER JOIN api_scenario_report ar ON ar.id = acr.report_id
|
||||
INNER JOIN (
|
||||
SELECT acitem.id FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
|
||||
) ac on acr.content like CONCAT('%', ac.id,'%')
|
||||
SELECT acitem.`name` FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
|
||||
) ac on acr.content like CONCAT('%"', ac.`name`,'"%')
|
||||
WHERE acr.project_id = #{projectId}
|
||||
</select>
|
||||
</mapper>
|
|
@ -160,7 +160,6 @@
|
|||
WHERE sch.resource_id IN (
|
||||
SELECT id FROM api_test WHERE project_id = #{projectId,jdbcType=VARCHAR}
|
||||
)
|
||||
AND `group` = #{group}
|
||||
</select>
|
||||
|
||||
<select id="countByProjectIDAndCreateInThisWeek" resultType="java.lang.Long">
|
||||
|
|
|
@ -75,7 +75,7 @@ public class PerformanceTestController {
|
|||
@RequestPart("request") SaveTestPlanRequest request,
|
||||
@RequestPart(value = "file") List<MultipartFile> files
|
||||
) {
|
||||
checkPermissionService.checkReadOnlyUser();
|
||||
checkPermissionService.checkProjectOwner(request.getProjectId());
|
||||
return performanceTestService.save(request, files);
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,6 @@ public class PerformanceTestController {
|
|||
@RequestPart("request") EditTestPlanRequest request,
|
||||
@RequestPart(value = "file", required = false) List<MultipartFile> files
|
||||
) {
|
||||
checkPermissionService.checkReadOnlyUser();
|
||||
checkPermissionService.checkPerformanceTestOwner(request.getId());
|
||||
return performanceTestService.edit(request, files);
|
||||
}
|
||||
|
@ -115,7 +114,6 @@ public class PerformanceTestController {
|
|||
|
||||
@PostMapping("/delete")
|
||||
public void delete(@RequestBody DeleteTestPlanRequest request) {
|
||||
checkPermissionService.checkReadOnlyUser();
|
||||
checkPermissionService.checkPerformanceTestOwner(request.getId());
|
||||
performanceTestService.delete(request);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9f4a9bbf46fc1333dbcccea21f83e27e3ec10b1f
|
||||
Subproject commit 79343a2763b014355f91fc21b2356a95ae437973
|
Loading…
Reference in New Issue