|
|
@@ -1,21 +1,21 @@
|
|
|
-package cn.seecoder.web.service.impl.APITest;
|
|
|
+package cn.seecoder.web.service.impl.apitest;
|
|
|
|
|
|
import cn.seecoder.common.util.LogTrackingUtil;
|
|
|
import cn.seecoder.common.util.OpType;
|
|
|
-import cn.seecoder.web.dao.APITest.APITestMapper;
|
|
|
+import cn.seecoder.web.dao.apitest.ApiTestMapper;
|
|
|
import cn.seecoder.web.dao.pipeline.PipelineMapper;
|
|
|
import cn.seecoder.web.dao.pipeline.PipelineRecordMapper;
|
|
|
import cn.seecoder.web.dao.user.UserMapper;
|
|
|
-import cn.seecoder.web.model.po.APITest.APITestInfo;
|
|
|
-import cn.seecoder.web.model.po.APITest.APITestResult;
|
|
|
-import cn.seecoder.web.model.po.APITest.TestInfo;
|
|
|
-import cn.seecoder.web.model.po.APITest.TestResult;
|
|
|
+import cn.seecoder.web.model.po.apitest.ApiTestInfo;
|
|
|
+import cn.seecoder.web.model.po.apitest.ApiTestResult;
|
|
|
+import cn.seecoder.web.model.po.apitest.TestInfo;
|
|
|
+import cn.seecoder.web.model.po.apitest.TestResult;
|
|
|
import cn.seecoder.web.model.po.pipeline.PipelinePO;
|
|
|
import cn.seecoder.web.model.po.pipeline.PipelineRecordPO;
|
|
|
-import cn.seecoder.web.model.vo.APITest.APITestBodyVO;
|
|
|
-import cn.seecoder.web.model.vo.APITest.APITestInfoVO;
|
|
|
-import cn.seecoder.web.model.vo.APITest.APITestResultVO;
|
|
|
-import cn.seecoder.web.service.APITest.APITestService;
|
|
|
+import cn.seecoder.web.model.vo.apitest.ApiTestBodyVO;
|
|
|
+import cn.seecoder.web.model.vo.apitest.ApiTestInfoVO;
|
|
|
+import cn.seecoder.web.model.vo.apitest.ApiTestResultVO;
|
|
|
+import cn.seecoder.web.service.apitest.ApiTestService;
|
|
|
import cn.seecoder.web.service.user.UserService;
|
|
|
import com.google.gson.Gson;
|
|
|
import net.sf.json.JSONArray;
|
|
|
@@ -40,10 +40,10 @@ import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
-public class APITestServiceImpl implements APITestService {
|
|
|
+public class ApiTestServiceImpl implements ApiTestService {
|
|
|
|
|
|
- private static final Logger log = LoggerFactory.getLogger(APITestServiceImpl.class);
|
|
|
- private final APITestMapper apiTestMapper;
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ApiTestServiceImpl.class);
|
|
|
+ private final ApiTestMapper apiTestMapper;
|
|
|
|
|
|
private final PipelineMapper pipelineMapper;
|
|
|
|
|
|
@@ -53,7 +53,7 @@ public class APITestServiceImpl implements APITestService {
|
|
|
private UserMapper userMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- public APITestServiceImpl(APITestMapper apiTestMapper, PipelineMapper pipelineMapper, PipelineRecordMapper pipelineRecordMapper) {
|
|
|
+ public ApiTestServiceImpl(ApiTestMapper apiTestMapper, PipelineMapper pipelineMapper, PipelineRecordMapper pipelineRecordMapper) {
|
|
|
this.apiTestMapper = apiTestMapper;
|
|
|
this.pipelineMapper = pipelineMapper;
|
|
|
this.pipelineRecordMapper = pipelineRecordMapper;
|
|
|
@@ -61,7 +61,7 @@ public class APITestServiceImpl implements APITestService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void createAPITest(APITestBodyVO apiTestBodyVO) {
|
|
|
+ public void createApiTest(ApiTestBodyVO apiTestBodyVO) {
|
|
|
TestInfo testInfo = TestInfo.builder()
|
|
|
.testName(apiTestBodyVO.getTestName())
|
|
|
.projectId(apiTestBodyVO.getProjectId())
|
|
|
@@ -76,24 +76,24 @@ public class APITestServiceImpl implements APITestService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<APITestInfoVO> getAPITestsByProjectId(Integer projectId) {
|
|
|
+ public List<ApiTestInfoVO> getApiTestsByProjectId(Integer projectId) {
|
|
|
List<TestInfo> apiTestInfos = apiTestMapper.selectByProjectId(projectId);
|
|
|
- List<APITestInfoVO> apiTestInfoVOList = new ArrayList<>();
|
|
|
+ List<ApiTestInfoVO> apiTestInfoVOList = new ArrayList<>();
|
|
|
for (TestInfo testInfo: apiTestInfos) {
|
|
|
- apiTestInfoVOList.add(new APITestInfoVO(transform(testInfo)));
|
|
|
+ apiTestInfoVOList.add(new ApiTestInfoVO(transform(testInfo)));
|
|
|
}
|
|
|
return apiTestInfoVOList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void deleteAPITest(Integer testId) {
|
|
|
+ public void deleteApiTest(Integer testId) {
|
|
|
apiTestMapper.delete(testId);
|
|
|
apiTestMapper.deleteTestResult(testId);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void executeAPITest(Integer testId) throws InterruptedException {
|
|
|
+ public void executeApiTest(Integer testId) throws InterruptedException {
|
|
|
TestInfo testInfo = apiTestMapper.selectByTestId(testId);
|
|
|
String url = testInfo.getUrl();
|
|
|
Map<String, Object> params = parseJson2Map(testInfo.getParams());
|
|
|
@@ -112,7 +112,7 @@ public class APITestServiceImpl implements APITestService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<APITestResultVO> getAPITestResultByTestId(Integer testId) {
|
|
|
+ public List<ApiTestResultVO> getApiTestResultByTestId(Integer testId) {
|
|
|
|
|
|
TestInfo testInfo = apiTestMapper.selectByTestId(testId);
|
|
|
|
|
|
@@ -126,15 +126,15 @@ public class APITestServiceImpl implements APITestService {
|
|
|
}
|
|
|
Integer recordId = latestRecord==null? -1:latestRecord.getId();
|
|
|
List<TestResult> testResultVOS = apiTestMapper.selectTestResultByTestId(testId, recordId);
|
|
|
- List<APITestResultVO> apiTestResultVOList = new ArrayList<>();
|
|
|
+ List<ApiTestResultVO> apiTestResultVOList = new ArrayList<>();
|
|
|
for (TestResult testResult: testResultVOS) {
|
|
|
- apiTestResultVOList.add(new APITestResultVO(transform1(testResult)));
|
|
|
+ apiTestResultVOList.add(new ApiTestResultVO(transform1(testResult)));
|
|
|
}
|
|
|
return apiTestResultVOList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public APITestResultVO getLatestTestResultByTestId(Integer testId) {
|
|
|
+ public ApiTestResultVO getLatestTestResultByTestId(Integer testId) {
|
|
|
TestInfo testInfo = apiTestMapper.selectByTestId(testId);
|
|
|
|
|
|
List<Integer> pipelineIds = pipelineMapper.selectByProjectId(testInfo.getProjectId()).stream().map(PipelinePO::getId).collect(Collectors.toList());
|
|
|
@@ -150,7 +150,7 @@ public class APITestServiceImpl implements APITestService {
|
|
|
if (testResult == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- return new APITestResultVO(transform1(testResult));
|
|
|
+ return new ApiTestResultVO(transform1(testResult));
|
|
|
}
|
|
|
// 将JSON格式的字符串转为 Map类型
|
|
|
public Map<String, Object> parseJson2Map(String str) {
|
|
|
@@ -170,9 +170,9 @@ public class APITestServiceImpl implements APITestService {
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
|
- // 将数据库中读取的TestInfo转为APITestInfo
|
|
|
- public APITestInfo transform(TestInfo testInfo) {
|
|
|
- APITestInfo apiTestInfo = new APITestInfo();
|
|
|
+ // 将数据库中读取的TestInfo转为ApiTestInfo
|
|
|
+ public ApiTestInfo transform(TestInfo testInfo) {
|
|
|
+ ApiTestInfo apiTestInfo = new ApiTestInfo();
|
|
|
apiTestInfo.setTestId(testInfo.getTestId());
|
|
|
apiTestInfo.setTestName(testInfo.getTestName());
|
|
|
apiTestInfo.setProjectId(testInfo.getProjectId());
|
|
|
@@ -185,8 +185,8 @@ public class APITestServiceImpl implements APITestService {
|
|
|
return apiTestInfo;
|
|
|
}
|
|
|
|
|
|
- public APITestResult transform1(TestResult testResult) {
|
|
|
- APITestResult apiTestResult = new APITestResult();
|
|
|
+ public ApiTestResult transform1(TestResult testResult) {
|
|
|
+ ApiTestResult apiTestResult = new ApiTestResult();
|
|
|
apiTestResult.setId(testResult.getId());
|
|
|
apiTestResult.setTestId(testResult.getTestId());
|
|
|
apiTestResult.setExecuteTime(testResult.getExecuteTime());
|
|
|
@@ -241,7 +241,7 @@ public class APITestServiceImpl implements APITestService {
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
- APITestServiceImpl apiTestService = new APITestServiceImpl(apiTestMapper, pipelineMapper, pipelineRecordMapper);
|
|
|
+ ApiTestServiceImpl apiTestService = new ApiTestServiceImpl(apiTestMapper, pipelineMapper, pipelineRecordMapper);
|
|
|
apiTestService.startTaskAllInOnce(10, task);
|
|
|
Integer max_time = Collections.max(timeList);
|
|
|
Integer min_time = Collections.min(timeList);
|