1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.ruoyi;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.TestRecords;
import com.ruoyi.domain.vo.CaseResultVO;
import com.ruoyi.domain.vo.StepResultVO;
import com.ruoyi.mapper.TestRecordsMapper;
import com.ruoyi.service.TestRecordsService;
import com.ruoyi.service.impl.TestRecordsServiceImpl;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.*;
@SpringBootTest
public class TestRecordsTest {
@Autowired
private TestRecordsService testRecordsService;
@Autowired
private TestRecordsMapper testRecordsMapper;
@Test
public void test() {
Map<String, Object> map = new HashMap<>();
map.put("id", "project_items;27");
map.put("verbose", "ALL");
//以post形式请求接口
String result= HttpUtil.post("https://10.12.48.78:8090/DescribeProjectTestResult",JSONObject.toJSONString(map));
JSONObject jsonObject = JSONObject.parseObject(result);
// 获取关联项目id
String projectId = (String) jsonObject.get("id");
// 获取项目用例结果列表
List<CaseResultVO> caseResultVOS = jsonObject.getList("case_result_list", CaseResultVO.class);
// 获取本地存储的列表
List<TestRecords> recordsList = testRecordsService.findByTaskId("project_items;29");
List<TestRecords> list = new ArrayList<>();
if (caseResultVOS.size() != 0 && caseResultVOS != null) {
for (CaseResultVO caseResultVO : caseResultVOS) {
// 检查 usecaseId 是否在 recordsList 中存在
boolean exists = false;
if (recordsList.size() != 0 && recordsList != null) {
for (TestRecords records : recordsList) {
if (Objects.equals(caseResultVO.getId(), records.getUsecaseId())) {
exists = true;
break;
}
}
}
if ((Objects.equals(caseResultVO.getStatus(), "PASSED") || Objects.equals(caseResultVO.getStatus(), "FAILED")) && !exists) {
TestRecords testRecords = new TestRecords();
testRecords.setProjectId(projectId);
testRecords.setUsecase(caseResultVO.getName());
testRecords.setUsecaseId(caseResultVO.getId());
testRecords.setDescription(caseResultVO.getDescription());
testRecords.setRiskLevel(caseResultVO.getRisk_level());
testRecords.setTestResult(caseResultVO.getStatus());
testRecords.setRemediation(caseResultVO.getRemediation());
List<StepResultVO> stepResultVOS = caseResultVO.getStep_result_list();
if (stepResultVOS.size() != 0 && stepResultVOS != null) {
List<String> stepList = new ArrayList<>();
for (StepResultVO stepResultVO :stepResultVOS) {
String stepName = stepResultVO.getName();
stepList.add(stepName);
}
testRecords.setTestMethod(StringUtils.join(stepList,","));
}
list.add(testRecords);
}
}
testRecordsService.saveBatch(list);
}
}
}