Merge remote-tracking branch 'origin/v1.6' into v1.6
This commit is contained in:
commit
758677beb5
|
@ -7,8 +7,11 @@ import io.metersphere.base.domain.ApiDefinitionExecResult;
|
||||||
import io.metersphere.base.domain.ApiDefinitionExecResultExample;
|
import io.metersphere.base.domain.ApiDefinitionExecResultExample;
|
||||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||||
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
import io.metersphere.commons.utils.DateUtils;
|
import io.metersphere.commons.utils.DateUtils;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
|
import io.metersphere.track.service.TestPlanApiCaseService;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -25,6 +28,8 @@ public class ApiDefinitionExecResultService {
|
||||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper;
|
private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper;
|
||||||
|
@Resource
|
||||||
|
private TestPlanApiCaseService testPlanApiCaseService;
|
||||||
|
|
||||||
|
|
||||||
public void saveApiResult(TestResult result, String type) {
|
public void saveApiResult(TestResult result, String type) {
|
||||||
|
@ -37,9 +42,13 @@ public class ApiDefinitionExecResultService {
|
||||||
saveResult.setResourceId(item.getName());
|
saveResult.setResourceId(item.getName());
|
||||||
saveResult.setContent(JSON.toJSONString(item));
|
saveResult.setContent(JSON.toJSONString(item));
|
||||||
saveResult.setStartTime(item.getStartTime());
|
saveResult.setStartTime(item.getStartTime());
|
||||||
saveResult.setType(type);
|
String status = item.isSuccess() ? "success" : "error";
|
||||||
saveResult.setEndTime(item.getResponseResult().getResponseTime());
|
saveResult.setEndTime(item.getResponseResult().getResponseTime());
|
||||||
saveResult.setStatus(item.isSuccess() ? "success" : "error");
|
saveResult.setType(type);
|
||||||
|
saveResult.setStatus(status);
|
||||||
|
if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) {
|
||||||
|
testPlanApiCaseService.setExecResult(item.getName(), status);
|
||||||
|
}
|
||||||
apiDefinitionExecResultMapper.insert(saveResult);
|
apiDefinitionExecResultMapper.insert(saveResult);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.api.dto.DeleteAPIReportRequest;
|
||||||
import io.metersphere.api.dto.QueryAPIReportRequest;
|
import io.metersphere.api.dto.QueryAPIReportRequest;
|
||||||
import io.metersphere.api.dto.automation.APIScenarioReportResult;
|
import io.metersphere.api.dto.automation.APIScenarioReportResult;
|
||||||
import io.metersphere.api.dto.automation.ExecuteType;
|
import io.metersphere.api.dto.automation.ExecuteType;
|
||||||
|
import io.metersphere.api.dto.automation.ScenarioStatus;
|
||||||
import io.metersphere.api.dto.datacount.ApiDataCountResult;
|
import io.metersphere.api.dto.datacount.ApiDataCountResult;
|
||||||
import io.metersphere.api.jmeter.ScenarioResult;
|
import io.metersphere.api.jmeter.ScenarioResult;
|
||||||
import io.metersphere.api.jmeter.TestResult;
|
import io.metersphere.api.jmeter.TestResult;
|
||||||
|
@ -124,9 +125,9 @@ public class ApiScenarioReportService {
|
||||||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId());
|
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId());
|
||||||
ScenarioResult scenarioResult = result.getScenarios().get(0);
|
ScenarioResult scenarioResult = result.getScenarios().get(0);
|
||||||
if (scenarioResult.getError() > 0) {
|
if (scenarioResult.getError() > 0) {
|
||||||
testPlanApiScenario.setLastResult("Fail");
|
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
||||||
} else {
|
} else {
|
||||||
testPlanApiScenario.setLastResult("Success");
|
testPlanApiScenario.setLastResult(ScenarioStatus.Success.name());
|
||||||
}
|
}
|
||||||
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
|
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
|
||||||
testPlanApiScenario.setPassRate(passRate);
|
testPlanApiScenario.setPassRate(passRate);
|
||||||
|
|
|
@ -11,4 +11,6 @@ public interface ExtTestPlanApiCaseMapper {
|
||||||
void insertIfNotExists(@Param("request") TestPlanApiCase request);
|
void insertIfNotExists(@Param("request") TestPlanApiCase request);
|
||||||
|
|
||||||
List<TestPlanApiCaseDTO> list(@Param("request") ApiTestCaseRequest request);
|
List<TestPlanApiCaseDTO> list(@Param("request") ApiTestCaseRequest request);
|
||||||
|
|
||||||
|
List<String> getExecResultByPlanId(String planId);
|
||||||
}
|
}
|
|
@ -108,5 +108,11 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getExecResultByPlanId" resultType="java.lang.String">
|
||||||
|
select status
|
||||||
|
from
|
||||||
|
test_plan_api_case
|
||||||
|
where test_plan_id = #{planId}
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
|
@ -18,4 +18,5 @@ public interface ExtTestPlanScenarioCaseMapper {
|
||||||
|
|
||||||
List<ApiScenarioDTO> list(@Param("request") TestPlanScenarioRequest request);
|
List<ApiScenarioDTO> list(@Param("request") TestPlanScenarioRequest request);
|
||||||
|
|
||||||
|
List<String> getExecResultByPlanId(String planId);
|
||||||
}
|
}
|
|
@ -80,5 +80,11 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getExecResultByPlanId" resultType="java.lang.String">
|
||||||
|
select last_result
|
||||||
|
from
|
||||||
|
test_plan_api_scenario
|
||||||
|
where test_plan_id = #{planId}
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
|
@ -41,4 +41,6 @@ public interface ExtTestPlanTestCaseMapper {
|
||||||
TestPlanCaseDTO get(String testPlanTestCaseId);
|
TestPlanCaseDTO get(String testPlanTestCaseId);
|
||||||
|
|
||||||
void deleteByTestCaseID(String id);
|
void deleteByTestCaseID(String id);
|
||||||
|
|
||||||
|
List<String> getExecResultByPlanId(String planId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,6 +330,13 @@
|
||||||
where test_plan_test_case.id = #{testPlanTestCaseId}
|
where test_plan_test_case.id = #{testPlanTestCaseId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getExecResultByPlanId" resultType="java.lang.String">
|
||||||
|
select status
|
||||||
|
from
|
||||||
|
test_plan_test_case
|
||||||
|
where plan_id = #{planId}
|
||||||
|
</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
|
||||||
<set>
|
<set>
|
||||||
|
|
|
@ -11,6 +11,7 @@ import io.metersphere.base.mapper.TestPlanApiCaseMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper;
|
import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper;
|
||||||
import io.metersphere.commons.utils.ServiceUtils;
|
import io.metersphere.commons.utils.ServiceUtils;
|
||||||
import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest;
|
import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
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;
|
||||||
|
@ -29,6 +30,7 @@ public class TestPlanApiCaseService {
|
||||||
ApiTestCaseService apiTestCaseService;
|
ApiTestCaseService apiTestCaseService;
|
||||||
@Resource
|
@Resource
|
||||||
ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
|
ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
|
||||||
|
@Lazy
|
||||||
@Resource
|
@Resource
|
||||||
ApiDefinitionExecResultService apiDefinitionExecResultService;
|
ApiDefinitionExecResultService apiDefinitionExecResultService;
|
||||||
|
|
||||||
|
@ -43,6 +45,10 @@ public class TestPlanApiCaseService {
|
||||||
return apiTestCases;
|
return apiTestCases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getExecResultByPlanId(String plan) {
|
||||||
|
return extTestPlanApiCaseMapper.getExecResultByPlanId(plan);
|
||||||
|
}
|
||||||
|
|
||||||
public List<ApiTestCaseDTO> relevanceList(ApiTestCaseRequest request) {
|
public List<ApiTestCaseDTO> relevanceList(ApiTestCaseRequest request) {
|
||||||
List<String> ids = apiTestCaseService.selectIdsNotExistsInPlan(request.getProjectId(), request.getPlanId());
|
List<String> ids = apiTestCaseService.selectIdsNotExistsInPlan(request.getProjectId(), request.getPlanId());
|
||||||
if (CollectionUtils.isEmpty(ids)) {
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
|
@ -78,4 +84,11 @@ public class TestPlanApiCaseService {
|
||||||
example.createCriteria().andTestPlanIdEqualTo(planId);
|
example.createCriteria().andTestPlanIdEqualTo(planId);
|
||||||
return testPlanApiCaseMapper.selectByExample(example);
|
return testPlanApiCaseMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setExecResult(String id, String status) {
|
||||||
|
TestPlanApiCase apiCase = new TestPlanApiCase();
|
||||||
|
apiCase.setId(id);
|
||||||
|
apiCase.setStatus(status);
|
||||||
|
testPlanApiCaseMapper.updateByPrimaryKeySelective(apiCase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,4 +89,8 @@ public class TestPlanScenarioCaseService {
|
||||||
example.createCriteria().andTestPlanIdEqualTo(planId);
|
example.createCriteria().andTestPlanIdEqualTo(planId);
|
||||||
return testPlanApiScenarioMapper.selectByExample(example);
|
return testPlanApiScenarioMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getExecResultByPlanId(String planId) {
|
||||||
|
return extTestPlanScenarioCaseMapper.getExecResultByPlanId(planId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ package io.metersphere.track.service;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.metersphere.api.dto.automation.ApiScenarioDTO;
|
import io.metersphere.api.dto.automation.ApiScenarioDTO;
|
||||||
|
import io.metersphere.api.dto.automation.ScenarioStatus;
|
||||||
import io.metersphere.api.dto.automation.TestPlanScenarioRequest;
|
import io.metersphere.api.dto.automation.TestPlanScenarioRequest;
|
||||||
import io.metersphere.api.dto.definition.ApiTestCaseRequest;
|
import io.metersphere.api.dto.definition.ApiTestCaseRequest;
|
||||||
import io.metersphere.api.dto.definition.TestPlanApiCaseDTO;
|
import io.metersphere.api.dto.definition.TestPlanApiCaseDTO;
|
||||||
|
@ -300,35 +301,44 @@ public class TestPlanService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calcTestPlanRate(List<TestPlanDTOWithMetric> testPlans) {
|
private void calcTestPlanRate(List<TestPlanDTOWithMetric> testPlans) {
|
||||||
List<String> projectIds = extProjectMapper.getProjectIdByWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
|
||||||
Map<String, List<TestPlanCaseDTO>> testCaseMap = new HashMap<>();
|
|
||||||
listTestCaseByProjectIds(projectIds).forEach(testCase -> {
|
|
||||||
List<TestPlanCaseDTO> list = testCaseMap.get(testCase.getPlanId());
|
|
||||||
if (list == null) {
|
|
||||||
list = new ArrayList<>();
|
|
||||||
list.add(testCase);
|
|
||||||
testCaseMap.put(testCase.getPlanId(), list);
|
|
||||||
} else {
|
|
||||||
list.add(testCase);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
testPlans.forEach(testPlan -> {
|
testPlans.forEach(testPlan -> {
|
||||||
List<TestPlanCaseDTO> testCases = testCaseMap.get(testPlan.getId());
|
|
||||||
testPlan.setTested(0);
|
testPlan.setTested(0);
|
||||||
testPlan.setPassed(0);
|
testPlan.setPassed(0);
|
||||||
testPlan.setTotal(0);
|
testPlan.setTotal(0);
|
||||||
if (testCases != null) {
|
|
||||||
testPlan.setTotal(testCases.size());
|
List<String> functionalExecResults = extTestPlanTestCaseMapper.getExecResultByPlanId(testPlan.getId());
|
||||||
testCases.forEach(testCase -> {
|
functionalExecResults.forEach(item -> {
|
||||||
if (!StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Prepare.name())
|
if (!StringUtils.equals(item, TestPlanTestCaseStatus.Prepare.name())
|
||||||
&& !StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Underway.name())) {
|
&& !StringUtils.equals(item, TestPlanTestCaseStatus.Underway.name())) {
|
||||||
testPlan.setTested(testPlan.getTested() + 1);
|
testPlan.setTested(testPlan.getTested() + 1);
|
||||||
if (StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Pass.name())) {
|
if (StringUtils.equals(item, TestPlanTestCaseStatus.Pass.name())) {
|
||||||
testPlan.setPassed(testPlan.getPassed() + 1);
|
testPlan.setPassed(testPlan.getPassed() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
List<String> apiExecResults = testPlanApiCaseService.getExecResultByPlanId(testPlan.getId());
|
||||||
|
apiExecResults.forEach(item -> {
|
||||||
|
if (StringUtils.isNotBlank(item)) {
|
||||||
|
testPlan.setTested(testPlan.getTested() + 1);
|
||||||
|
if (StringUtils.equals(item, "success")) {
|
||||||
|
testPlan.setPassed(testPlan.getPassed() + 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
List<String> scenarioExecResults = testPlanScenarioCaseService.getExecResultByPlanId(testPlan.getId());
|
||||||
|
scenarioExecResults.forEach(item -> {
|
||||||
|
if (StringUtils.isNotBlank(item)) {
|
||||||
|
testPlan.setTested(testPlan.getTested() + 1);
|
||||||
|
if (StringUtils.equals(item, ScenarioStatus.Success.name())) {
|
||||||
|
testPlan.setPassed(testPlan.getPassed() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testPlan.setTotal(apiExecResults.size() + scenarioExecResults.size() + functionalExecResults.size());
|
||||||
|
|
||||||
testPlan.setPassRate(MathUtils.getPercentWithDecimal(testPlan.getTested() == 0 ? 0 : testPlan.getPassed() * 1.0 / testPlan.getTested()));
|
testPlan.setPassRate(MathUtils.getPercentWithDecimal(testPlan.getTested() == 0 ? 0 : testPlan.getPassed() * 1.0 / testPlan.getTested()));
|
||||||
testPlan.setTestRate(MathUtils.getPercentWithDecimal(testPlan.getTotal() == 0 ? 0 : testPlan.getTested() * 1.0 / testPlan.getTotal()));
|
testPlan.setTestRate(MathUtils.getPercentWithDecimal(testPlan.getTotal() == 0 ? 0 : testPlan.getTested() * 1.0 / testPlan.getTotal()));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue