Commit e42426f3 authored by wdy's avatar wdy

查看测试矩阵

parent f5e6c9bc
package com.ruoyi.domain.vo;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ApiModel( description = "测试场景VO")
@Data
public class ScenarioVO {
private Long id;
private String name;
}
package com.ruoyi.domain.vo;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ApiModel( description = "测试方法(类型)VO")
@Data
public class TestTypeVO {
private Long id;
private String name;
}
package com.ruoyi.domain.vo;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ApiModel( description = "测试用例VO")
@Data
public class UseCaseVO {
private String id;
private String name;
// 测试场景
private String scenario;
// 测试方法
private String test_type;
/**
* 返回用例在矩阵中的坐标
* @return
*/
public String getCoordinates() {
return scenario + test_type;
}
}
......@@ -6,4 +6,6 @@ public interface MatrixService {
MatrixResponse getMatrix();
MatrixResponse getMatrixForUrl();
}
package com.ruoyi.service.impl;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.domain.TestScenario;
import com.ruoyi.domain.TestType;
import com.ruoyi.domain.TestUseCase;
import com.ruoyi.domain.vo.MatrixColumnVO;
import com.ruoyi.domain.vo.MatrixRowVO;
import com.ruoyi.domain.vo.*;
import com.ruoyi.service.ITestScenarioService;
import com.ruoyi.service.ITestTypeService;
import com.ruoyi.service.MatrixService;
......@@ -13,8 +14,6 @@ import com.ruoyi.web.response.MatrixResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.format.TextStyle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -47,6 +46,88 @@ public class MatrixServiceImpl implements MatrixService {
return response;
}
@Override
public MatrixResponse getMatrixForUrl() {
//以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);
}
}
String caseResult= HttpUtil.post("https://10.12.48.78:8090/DescribeCaseList","");
JSONObject object = JSONObject.parseObject(caseResult);
// 获取测试用例列表
List<UseCaseVO> caseList = object.getList("case_list", UseCaseVO.class);
MatrixResponse response = new MatrixResponse();
setHeaderName(response, testTypeList);
setRowsName(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();
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 = getUseCaseIdByCoordinatesName(caseList, coordinates);
row.put(columnId, useCase == null ? "" : useCase);
}
rows.add(row);
}
response.setRows(rows);
}
public String getUseCaseIdByCoordinatesName(List<UseCaseVO> caseList, String coordinates) {
for(UseCaseVO useCase : caseList) {
if(useCase.getCoordinates().equals(coordinates)) {
return useCase.getId();
}
}
return null;
}
private void setHeaderName(MatrixResponse response, List<TestTypeVO> testTypeList) {
List<MatrixColumnVO> columns = new ArrayList();
for(TestTypeVO type : testTypeList) {
MatrixColumnVO column = new MatrixColumnVO(String.valueOf(type.getId()),type.getName());
columns.add(column);
}
response.setHeader(columns);
}
private void setHeader(MatrixResponse response, List<TestType> types) {
List<MatrixColumnVO> columns = new ArrayList();
......
......@@ -25,7 +25,7 @@ public class MatrixController {
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/getInfo")
public R<MatrixResponse> getInfo() {
return R.ok(matrixService.getMatrix());
return R.ok(matrixService.getMatrixForUrl());
}
}
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