Commit a242efd7 authored by wdy's avatar wdy

Merge branch 'dev' into 'master'

dev - master 25

See merge request !366
parents df46c679 327b3b4c
......@@ -13,6 +13,8 @@ public class UseCaseVO {
private String name;
private String displayID;
// 测试场景
private String scenarioName;
private ScenarioKEVO scenario;
......
......@@ -10,4 +10,5 @@ public interface MatrixService {
MatrixResponse getMatrixForUrl() throws IOException;
MatrixResponse getMatrixForUrlPad() throws IOException;
}
......@@ -115,6 +115,70 @@ public class MatrixServiceImpl implements MatrixService {
return response;
}
@Override
public MatrixResponse getMatrixForUrlPad() throws IOException {
//以post形式请求接口
String result= HttpUtil.post("https://10.12.48.78:8090/DescribeScenarioTestTypeList","");
JSONObject jsonObject = JSONObject.parseObject(result);
// 获取测试场景列表
List<ScenarioVO> scenarioList = jsonObject.getList("scenario_list", ScenarioVO.class);
if (scenarioList != null && scenarioList.size() != 0 ) {
for (int i = 0; i < scenarioList.size(); i++) {
scenarioList.get(i).setId((long) i);
}
}
// 获取测试方法列表
List<TestTypeVO> testTypeList = jsonObject.getList("test_type_list", TestTypeVO.class);
if (testTypeList != null && testTypeList.size() != 0 ) {
for (int i = 0; i < testTypeList.size(); i++) {
testTypeList.get(i).setId((long) i);
}
}
// 获取测试用例
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
// 创建请求体
String request = "{\"offset\": {\n" +
" \"offset\": 0,\n" +
" \"limit\": 9999\n" +
" },\n" +
" \"searchFields\":{\n" +
" \"name\": \"\",\n" +
" \"scenario\":\"\",\n" +
" \"method\":\"\"\n" +
" }}";
RequestBody body = RequestBody.create(mediaType, "{\"query\":\"query useCases($offset:OffsetConnectionInput$orderBy:OrderByInput$filter:Map$search:String$searchFields:Map){useCases(offset:$offset orderBy:$orderBy filterFields:$filter search:$search searchFields:$searchFields){nodes{id displayID class name description remediation requirements riskLevel method{name}scenario{name}}totalCount}}\",\"variables\":"+ request +"}");
Request requestKE = new Request.Builder()
.url("http://10.12.48.80:8089/api/query")
.method("POST", body)
.addHeader("Content-Type", "application/json")
// TODO 连接
// .addHeader("Host", "10.12.48.80:8089")
// .addHeader("Origin", "http://10.12.48.80:8089")
// .addHeader("Referer", "http://10.12.48.80:8089/api/graphql/playground")
// .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36")
.build();
Response responseR = client.newCall(requestKE).execute();
String string = responseR.body().string();
JSONObject jsonO = JSONObject.parseObject(string);
// 获取测试用例列表
List<UseCaseVO> caseList = jsonO.getJSONObject("data").getJSONObject("useCases").getList("nodes", UseCaseVO.class);
MatrixResponse response = new MatrixResponse();
setHeaderName(response, testTypeList);
setRowsNamePad(response, scenarioList, testTypeList, caseList);
return response;
}
private void setRowsName(MatrixResponse response, List<ScenarioVO> scenarioList, List<TestTypeVO> testTypeList, List<UseCaseVO> caseList) {
List<Map<String, Object>> rows = new ArrayList();
......@@ -139,6 +203,40 @@ public class MatrixServiceImpl implements MatrixService {
response.setRows(rows);
}
private void setRowsNamePad(MatrixResponse response, List<ScenarioVO> scenarioList, List<TestTypeVO> testTypeList, List<UseCaseVO> caseList) {
List<Map<String, Object>> rows = new ArrayList();
for(ScenarioVO scenario : scenarioList) {
Map<String, Object> row = new HashMap();
row.put("name", scenario.getName());
for(TestTypeVO type : testTypeList) {
String column = type.getName();
String columnId = String.valueOf(type.getId());
String coordinates = scenario.getName() + column;
String useCase = getUseCaseIdByCoordinatesNamePad(caseList, coordinates);
row.put(columnId, useCase == null ? "" : useCase);
}
rows.add(row);
}
response.setRows(rows);
}
public String getUseCaseIdByCoordinatesNamePad(List<UseCaseVO> caseList, String coordinates) {
for(UseCaseVO useCase : caseList) {
if(useCase.getCoordinates().equals(coordinates)) {
return useCase.getDisplayID();
}
}
return null;
}
public String getUseCaseIdByCoordinatesName(List<UseCaseVO> caseList, String coordinates) {
for(UseCaseVO useCase : caseList) {
......
......@@ -30,4 +30,12 @@ public class MatrixController {
return R.ok(matrixService.getMatrixForUrl());
}
@ApiOperation("查看任务详情pad")
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/getInfoPad")
public R<MatrixResponse> getInfoPad() throws IOException {
return R.ok(matrixService.getMatrixForUrlPad());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment