Merge branch 'master' of https://github.com/metersphere/metersphere
This commit is contained in:
commit
e522ab0034
|
@ -188,11 +188,11 @@ public class ApiDataCountDTO {
|
|||
for (ApiDataCountResult countResult : allExecuteResult) {
|
||||
if("Success".equals(countResult.getGroupField())){
|
||||
this.successCount+= countResult.getCountNumber();
|
||||
}else if("Error".equals(countResult.getGroupField())){
|
||||
this.executedCount+= countResult.getCountNumber();
|
||||
}else if("Error".equals(countResult.getGroupField())||"Fail".equals(countResult.getGroupField())){
|
||||
this.failedCount+= countResult.getCountNumber();
|
||||
this.executedCount+= countResult.getCountNumber();
|
||||
}
|
||||
|
||||
this.executedCount+= countResult.getCountNumber();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ 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;
|
||||
|
@ -179,28 +178,31 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
testResult.setTestId(testId);
|
||||
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){
|
||||
String scenaName = scenarioReport.getName();
|
||||
if (scenaName == null) {
|
||||
scenaName = "";
|
||||
}else {
|
||||
scenaName = scenaName.split("-")[0];
|
||||
} else {
|
||||
String[] sceneNameArr = scenaName.split("-");
|
||||
if (sceneNameArr.length >= 4) {
|
||||
String endStr = "-" + sceneNameArr[sceneNameArr.length - 3] + "-" + sceneNameArr[sceneNameArr.length - 2] + "-" + sceneNameArr[sceneNameArr.length - 1];
|
||||
scenaName = scenaName.split(endStr)[0];
|
||||
} else {
|
||||
scenaName = scenaName.split("-")[0];
|
||||
}
|
||||
}
|
||||
|
||||
String scenarioID = apiScenarioReportService.getApiScenarioId(scenaName,scenarioReport.getProjectId());
|
||||
String scenarioID = apiScenarioReportService.getApiScenarioId(scenaName, scenarioReport.getProjectId());
|
||||
testResult.setTestId(scenarioID);
|
||||
} else {
|
||||
apiTestService.changeStatus(testId, APITestStatus.Completed);
|
||||
|
@ -224,14 +226,14 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
}
|
||||
}
|
||||
try {
|
||||
sendTask(report,reportUrl, testResult);
|
||||
sendTask(report, reportUrl, testResult);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void sendTask(ApiTestReport report,String reportUrl, 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;
|
||||
|
@ -239,7 +241,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
String url = reportUrl;
|
||||
if(StringUtils.isEmpty(url)){
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId();
|
||||
}
|
||||
String successContext = "";
|
||||
|
@ -267,6 +269,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
paramMap.put("id", report.getId());
|
||||
paramMap.put("type", "performance");
|
||||
paramMap.put("url", baseSystemConfigDTO.getUrl());
|
||||
paramMap.put("status", report.getStatus());
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.successContext(successContext)
|
||||
.successMailTemplate("ApiSuccessfulNotification")
|
||||
|
|
|
@ -160,15 +160,14 @@ public class ApiAutomationService {
|
|||
apiScenarioMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void preDelete(String scenarioID) {
|
||||
ApiScenarioReportExample scenarioReportExample = new ApiScenarioReportExample();
|
||||
scenarioReportExample.createCriteria().andScenarioIdEqualTo(scenarioID);
|
||||
List<ApiScenarioReport> list = apiScenarioReportMapper.selectByExample(scenarioReportExample);
|
||||
deleteApiScenarioReport(list);
|
||||
scheduleService.deleteByResourceId(scenarioID);
|
||||
public void preDelete(String scenarioId) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
ids.add(scenarioId);
|
||||
deleteApiScenarioReport(ids);
|
||||
|
||||
scheduleService.deleteByResourceId(scenarioId);
|
||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||
example.createCriteria().andApiScenarioIdEqualTo(scenarioID);
|
||||
example.createCriteria().andApiScenarioIdEqualTo(scenarioId);
|
||||
List<TestPlanApiScenario> testPlanApiScenarioList = testPlanApiScenarioMapper.selectByExample(example);
|
||||
|
||||
List<String> idList = new ArrayList<>(testPlanApiScenarioList.size());
|
||||
|
@ -185,7 +184,10 @@ public class ApiAutomationService {
|
|||
|
||||
}
|
||||
|
||||
private void deleteApiScenarioReport(List<ApiScenarioReport> list) {
|
||||
private void deleteApiScenarioReport(List<String> scenarioIds) {
|
||||
ApiScenarioReportExample scenarioReportExample = new ApiScenarioReportExample();
|
||||
scenarioReportExample.createCriteria().andScenarioIdIn(scenarioIds);
|
||||
List<ApiScenarioReport> list = apiScenarioReportMapper.selectByExample(scenarioReportExample);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
List<String> ids = list.stream().map(ApiScenarioReport::getId).collect(Collectors.toList());
|
||||
DeleteAPIReportRequest reportRequest = new DeleteAPIReportRequest();
|
||||
|
@ -194,13 +196,11 @@ public class ApiAutomationService {
|
|||
}
|
||||
}
|
||||
|
||||
public void preDeleteBatch(List<String> scenarioIDList) {
|
||||
ApiScenarioReportExample scenarioReportExample = new ApiScenarioReportExample();
|
||||
scenarioReportExample.createCriteria().andScenarioIdIn(scenarioIDList);
|
||||
List<ApiScenarioReport> list = apiScenarioReportMapper.selectByExample(scenarioReportExample);
|
||||
deleteApiScenarioReport(list);
|
||||
public void preDeleteBatch(List<String> scenarioIds) {
|
||||
deleteApiScenarioReport(scenarioIds);
|
||||
|
||||
List<String> testPlanApiScenarioIdList = new ArrayList<>();
|
||||
for (String id : scenarioIDList) {
|
||||
for (String id : scenarioIds) {
|
||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||
example.createCriteria().andApiScenarioIdEqualTo(id);
|
||||
List<TestPlanApiScenario> testPlanApiScenarioList = testPlanApiScenarioMapper.selectByExample(example);
|
||||
|
|
|
@ -67,6 +67,7 @@ public class ApiScenarioReportService {
|
|||
MSException.throwException(Translator.get("api_report_is_null"));
|
||||
}
|
||||
APIScenarioReportResult report = (APIScenarioReportResult) obj;
|
||||
report.setTestId(result.getTestId());
|
||||
if (CollectionUtils.isNotEmpty(result.getScenarios())) {
|
||||
try {
|
||||
report.setName(result.getScenarios().get(0).getName() + "-" + DateUtils.getTimeString(System.currentTimeMillis()));
|
||||
|
@ -142,10 +143,14 @@ public class ApiScenarioReportService {
|
|||
}
|
||||
}
|
||||
|
||||
public ApiScenarioReport createReport(APIScenarioReportResult test, String scenarioName, String scenarioId, String result) {
|
||||
public ApiScenarioReport createReport(APIScenarioReportResult test, String scenarioName, String scenarioId, String result, String testId) {
|
||||
checkNameExist(test);
|
||||
ApiScenarioReport report = new ApiScenarioReport();
|
||||
report.setId(UUID.randomUUID().toString());
|
||||
if (StringUtils.isNotEmpty(testId)) {
|
||||
report.setId(testId);
|
||||
} else {
|
||||
report.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
report.setProjectId(test.getProjectId());
|
||||
report.setName(scenarioName + "-" + DateUtils.getTimeStr(System.currentTimeMillis()));
|
||||
report.setTriggerMode(test.getTriggerMode());
|
||||
|
@ -174,21 +179,19 @@ public class ApiScenarioReportService {
|
|||
report.setStatus(test.getStatus());
|
||||
report.setUserId(test.getUserId());
|
||||
report.setExecuteType(test.getExecuteType());
|
||||
report.setScenarioId(test.getScenarioId());
|
||||
report.setScenarioName(test.getScenarioName());
|
||||
apiScenarioReportMapper.updateByPrimaryKey(report);
|
||||
return report;
|
||||
}
|
||||
|
||||
private TestResult createTestResult(TestResult result) {
|
||||
TestResult newrResult = new TestResult();
|
||||
newrResult.setTestId(result.getTestId());
|
||||
newrResult.setTotal(result.getTotal());
|
||||
newrResult.setError(result.getError());
|
||||
newrResult.setPassAssertions(result.getPassAssertions());
|
||||
newrResult.setSuccess(result.getSuccess());
|
||||
newrResult.setTotalAssertions(result.getTotalAssertions());
|
||||
return newrResult;
|
||||
TestResult testResult = new TestResult();
|
||||
testResult.setTestId(result.getTestId());
|
||||
testResult.setTotal(result.getTotal());
|
||||
testResult.setError(result.getError());
|
||||
testResult.setPassAssertions(result.getPassAssertions());
|
||||
testResult.setSuccess(result.getSuccess());
|
||||
testResult.setTotalAssertions(result.getTotalAssertions());
|
||||
return testResult;
|
||||
}
|
||||
|
||||
public void save(APIScenarioReportResult test, String runModel) {
|
||||
|
@ -198,13 +201,13 @@ public class ApiScenarioReportService {
|
|||
if (StringUtils.equals(runModel, ApiRunMode.SCENARIO_PLAN.name())) {
|
||||
updatePlanCase(result, test);
|
||||
} else {
|
||||
updateScenario(test, result);
|
||||
updateScenario(result, test);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlanCase(TestResult result, APIScenarioReportResult test) {
|
||||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(test.getId());
|
||||
public void updatePlanCase(TestResult result, APIScenarioReportResult scenarioReportResult) {
|
||||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(scenarioReportResult.getId());
|
||||
ScenarioResult scenarioResult = result.getScenarios().get(0);
|
||||
if (scenarioResult.getError() > 0) {
|
||||
testPlanApiScenario.setLastResult("Fail");
|
||||
|
@ -214,7 +217,11 @@ public class ApiScenarioReportService {
|
|||
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
|
||||
testPlanApiScenario.setPassRate(passRate);
|
||||
// 存储场景报告
|
||||
ApiScenarioReport report = createReport(test, scenarioResult.getName(), testPlanApiScenario.getApiScenarioId(), scenarioResult.getError() == 0 ? "Success" : "Error");
|
||||
String testId = null;
|
||||
if (CollectionUtils.isNotEmpty(result.getScenarios()) && result.getScenarios().size() == 1) {
|
||||
testId = scenarioReportResult.getTestId();
|
||||
}
|
||||
ApiScenarioReport report = createReport(scenarioReportResult, scenarioResult.getName(), testPlanApiScenario.getApiScenarioId(), scenarioResult.getError() == 0 ? "Success" : "Error", testId);
|
||||
// 报告详情内容
|
||||
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
|
||||
TestResult newResult = createTestResult(result);
|
||||
|
@ -223,17 +230,17 @@ public class ApiScenarioReportService {
|
|||
newResult.setScenarios(scenarioResults);
|
||||
detail.setContent(JSON.toJSONString(newResult).getBytes(StandardCharsets.UTF_8));
|
||||
detail.setReportId(report.getId());
|
||||
detail.setProjectId(test.getProjectId());
|
||||
detail.setProjectId(scenarioReportResult.getProjectId());
|
||||
apiScenarioReportDetailMapper.insert(detail);
|
||||
|
||||
testPlanApiScenario.setReportId(report.getId());
|
||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||
}
|
||||
|
||||
public void updateScenario(APIScenarioReportResult test, TestResult result) {
|
||||
public void updateScenario(TestResult result, APIScenarioReportResult scenarioReportResult) {
|
||||
result.getScenarios().forEach(item -> {
|
||||
ApiScenarioExample example = new ApiScenarioExample();
|
||||
example.createCriteria().andNameEqualTo(item.getName()).andProjectIdEqualTo(test.getProjectId());
|
||||
example.createCriteria().andNameEqualTo(item.getName()).andProjectIdEqualTo(scenarioReportResult.getProjectId());
|
||||
List<ApiScenario> list = apiScenarioMapper.selectByExample(example);
|
||||
if (list.size() > 0) {
|
||||
ApiScenario scenario = list.get(0);
|
||||
|
@ -246,7 +253,11 @@ public class ApiScenarioReportService {
|
|||
scenario.setPassRate(passRate);
|
||||
|
||||
// 存储场景报告
|
||||
ApiScenarioReport report = createReport(test, scenario.getName(), scenario.getId(), scenario.getLastResult());
|
||||
String testId = null;
|
||||
if (CollectionUtils.isNotEmpty(result.getScenarios()) && result.getScenarios().size() == 1) {
|
||||
testId = scenarioReportResult.getTestId();
|
||||
}
|
||||
ApiScenarioReport report = createReport(scenarioReportResult, scenario.getName(), scenario.getId(), scenario.getLastResult(), testId);
|
||||
// 报告详情内容
|
||||
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
|
||||
TestResult newResult = createTestResult(result);
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
SELECT scene.`name` AS caseName,apiScene.testPlanName 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 report.scenario_id = scene.id
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT
|
||||
|
|
|
@ -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.`name` FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
|
||||
) ac on acr.content like CONCAT('%"', ac.`name`,'"%')
|
||||
SELECT acitem.`name`,acitem.id FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
|
||||
) ac on ar.scenario_id = ac.id
|
||||
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.`name` FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
|
||||
) ac on acr.content like CONCAT('%"', ac.`name`,'"%')
|
||||
SELECT acitem.`name`,acitem.id FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
|
||||
) ac on ar.scenario_id = ac.id
|
||||
WHERE acr.project_id = #{projectId}
|
||||
</select>
|
||||
</mapper>
|
|
@ -38,17 +38,17 @@
|
|||
|
||||
<select id="countTaskByProjectId" resultType="java.lang.Long">
|
||||
SELECT COUNT(id) AS countNumber FROM `schedule` WHERE resource_id IN (
|
||||
SELECT id FROM api_test WHERE project_id = #{0,jdbcType=VARCHAR}
|
||||
SELECT id FROM api_test WHERE project_id = #{0,jdbcType=VARCHAR} AND status != 'Trash'
|
||||
UNION
|
||||
SELECT id FROM api_scenario WHERE project_id = #{0,jdbcType=VARCHAR}
|
||||
SELECT id FROM api_scenario WHERE project_id = #{0,jdbcType=VARCHAR} AND status != 'Trash'
|
||||
)
|
||||
</select>
|
||||
<select id="countTaskByProjectIdAndCreateTimeRange" resultType="java.lang.Long">
|
||||
SELECT COUNT(id) AS countNumber FROM `schedule`
|
||||
WHERE resource_id IN (
|
||||
SELECT id FROM api_test WHERE project_id = #{projectId,jdbcType=VARCHAR}
|
||||
SELECT id FROM api_test WHERE project_id = #{projectId,jdbcType=VARCHAR} AND status != 'Trash'
|
||||
UNION
|
||||
SELECT id FROM api_scenario WHERE project_id = #{projectId,jdbcType=VARCHAR}
|
||||
SELECT id FROM api_scenario WHERE project_id = #{projectId,jdbcType=VARCHAR} AND status != 'Trash'
|
||||
)
|
||||
AND create_time BETWEEN #{startTime} and #{endTime}
|
||||
</select>
|
||||
|
@ -61,8 +61,8 @@
|
|||
UNION
|
||||
SELECT apiScene.`name` AS scenario,sch.id AS taskID,sch.`value` AS rule,sch.`enable` AS `taskStatus`,u.`name` AS creator,sch.update_time AS updateTime
|
||||
FROM api_scenario apiScene
|
||||
INNER JOIN `schedule` sch ON apiScene.id = sch.resource_id
|
||||
INNER JOIN `user` u ON u.id = sch.user_id
|
||||
INNER JOIN `schedule` sch ON apiScene.id = sch.resource_id
|
||||
INNER JOIN `user` u ON u.id = sch.user_id
|
||||
WHERE sch.`enable` = true AND apiScene.project_id = #{0,jdbcType=VARCHAR}
|
||||
</select>
|
||||
</mapper>
|
|
@ -87,6 +87,7 @@ public class PerformanceNoticeTask {
|
|||
paramMap.put("testName", loadTestReport.getName());
|
||||
paramMap.put("id", loadTestReport.getId());
|
||||
paramMap.put("type", "performance");
|
||||
paramMap.put("status", loadTestReport.getStatus());
|
||||
paramMap.put("url", baseSystemConfigDTO.getUrl());
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.successContext(successContext)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9f4a9bbf46fc1333dbcccea21f83e27e3ec10b1f
|
||||
Subproject commit 79343a2763b014355f91fc21b2356a95ae437973
|
|
@ -450,7 +450,8 @@
|
|||
}
|
||||
return false;
|
||||
},
|
||||
outsideClick() {
|
||||
outsideClick(e) {
|
||||
e.stopPropagation()
|
||||
this.operatingElements = ELEMENTS.get("ALL");
|
||||
},
|
||||
addComponent(type) {
|
||||
|
|
|
@ -242,11 +242,30 @@
|
|||
this.showCasePage = true;
|
||||
},
|
||||
exportAPI() {
|
||||
if (!this.$refs.apiList[0].tableData) {
|
||||
return;
|
||||
let obj = {projectName: getCurrentProjectID(), protocol: this.currentProtocol}
|
||||
if (this.$refs.apiList[0].selectRows && this.$refs.apiList[0].selectRows.length > 0) {
|
||||
let arr = Array.from(this.$refs.apiList[0].selectRows);
|
||||
obj.data = arr;
|
||||
downloadFile("导出API.json", JSON.stringify(obj));
|
||||
} else {
|
||||
let condition = {};
|
||||
if (this.isApiListEnable) {
|
||||
let url = "/api/definition/list/1/100000";
|
||||
condition.filters = ["Prepare", "Underway", "Completed"];
|
||||
condition.projectId = getCurrentProjectID();
|
||||
this.$post(url, condition, response => {
|
||||
obj.data = response.data.listObject;
|
||||
downloadFile("导出API.json", JSON.stringify(obj));
|
||||
});
|
||||
} else {
|
||||
let url = "/api/testcase/list/";
|
||||
condition.projectId = getCurrentProjectID();
|
||||
this.$post(url, condition, response => {
|
||||
obj.data = response.data;
|
||||
downloadFile("导出API.json", JSON.stringify(obj));
|
||||
});
|
||||
}
|
||||
}
|
||||
let obj = {projectName: getCurrentProjectID(), protocol: this.currentProtocol, data: this.$refs.apiList[0].tableData}
|
||||
downloadFile("导出API.json", JSON.stringify(obj));
|
||||
},
|
||||
refresh(data) {
|
||||
this.$refs.apiList[0].initTable(data);
|
||||
|
|
|
@ -221,7 +221,6 @@
|
|||
}
|
||||
|
||||
this.condition.projectId = this.getProjectId();
|
||||
|
||||
if (this.currentProtocol != null) {
|
||||
this.condition.protocol = this.currentProtocol;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 010ad7a5f072a5e9d368c756a2473bbd20781433
|
||||
Subproject commit 8cda5c873cd9985c97adb34efacf507167fa4182
|
Loading…
Reference in New Issue