refactor(接口测试): 优化关联用例入参

This commit is contained in:
WangXu10 2024-07-10 15:42:39 +08:00 committed by 刘瑞斌
parent 501be1b6b3
commit dbbc60c6a5
11 changed files with 26 additions and 35 deletions

View File

@ -179,7 +179,7 @@ public class Swagger3ExportParser implements ExportParser<ApiExportResponse> {
JSONObject body = respOrReq.optJSONObject("body");
if (body != null) { // 将请求体转换成相应的格式导出
String bodyType = body.optString(PropertyConstant.BODYTYPE);
String bodyType = body.optString(PropertyConstant.BODY_TYPE);
if (StringUtils.isNotBlank(bodyType) && bodyType.equalsIgnoreCase(Body.BodyType.JSON.name())) {
try {
// json
@ -235,7 +235,7 @@ public class Swagger3ExportParser implements ExportParser<ApiExportResponse> {
String type = null;
if (respOrReq.optJSONObject("body") != null) {
type = respOrReq.optJSONObject("body").optString(PropertyConstant.BODYTYPE);
type = respOrReq.optJSONObject("body").optString(PropertyConstant.BODY_TYPE);
}
JSONObject content = new JSONObject();
Object schema = bodyInfo; // 请求体部分
@ -516,7 +516,7 @@ public class Swagger3ExportParser implements ExportParser<ApiExportResponse> {
for (String key : kvs.keySet()) {
JSONObject property = new JSONObject();
JSONObject obj = ((JSONObject) kvs.get(key));
property.put(PropertyConstant.TYPE, StringUtils.isNotEmpty(obj.optString(PropertyConstant.PARAMTYPE)) ? obj.optString(PropertyConstant.PARAMTYPE) : PropertyConstant.STRING);
property.put(PropertyConstant.TYPE, StringUtils.isNotEmpty(obj.optString(PropertyConstant.PARAM_TYPE)) ? obj.optString(PropertyConstant.PARAM_TYPE) : PropertyConstant.STRING);
String value = obj.optString("value");
if (StringUtils.isBlank(value)) {
JSONObject mock = obj.optJSONObject(PropertyConstant.MOCK);
@ -536,7 +536,7 @@ public class Swagger3ExportParser implements ExportParser<ApiExportResponse> {
property.put(PropertyConstant.PROPERTIES, childProperties.optJSONObject(PropertyConstant.PROPERTIES));
} else {
JSONObject childProperties = buildJsonSchema(obj);
if (StringUtils.equalsIgnoreCase(obj.optString(PropertyConstant.PARAMTYPE), PropertyConstant.ARRAY)) {
if (StringUtils.equalsIgnoreCase(obj.optString(PropertyConstant.PARAM_TYPE), PropertyConstant.ARRAY)) {
if (childProperties.optJSONObject(PropertyConstant.ITEMS) != null) {
property.put(PropertyConstant.ITEMS, childProperties.optJSONObject(PropertyConstant.ITEMS));
}

View File

@ -20,7 +20,7 @@ public class PropertyConstant {
public final static String PROPERTIES = "properties";
public final static String ENABLE = "enable";
public final static String MOCK = "mock";
public final static String BODYTYPE = "bodyType";
public final static String PARAMTYPE = "paramtype";
public final static String BODY_TYPE = "bodyType";
public final static String PARAM_TYPE = "paramType";
}

View File

@ -22,7 +22,7 @@ public class TestPlanCollectionAssociateDTO implements Serializable {
private boolean selectAllModule;
@Schema(description = "模块下的id集合属性", requiredMode = Schema.RequiredMode.REQUIRED)
private List<Map<String, ModuleSelectDTO>> moduleMaps;
private Map<String, ModuleSelectDTO> moduleMaps;
@Schema(description = "关联关系的type(功能FUNCTIONAL/接口定义API/接口用例API_CASE/场景API_SCENARIO)", requiredMode = Schema.RequiredMode.REQUIRED)
private String associateType;

View File

@ -587,8 +587,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
apiCaseList.forEach(apiCase -> {
super.checkCollection(testPlan.getId(), apiCase.getCollectionId(), CaseType.API_CASE.getKey());
boolean selectAllModule = apiCase.getModules().isSelectAllModule();
List<Map<String, ModuleSelectDTO>> moduleMaps = apiCase.getModules().getModuleMaps();
Map<String, ModuleSelectDTO> moduleMaps = apiCase.getModules().getModuleMaps();
if (selectAllModule) {
// 选择了全部模块
List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId());
@ -608,7 +607,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
apiCaseList.forEach(apiCase -> {
super.checkCollection(testPlan.getId(), apiCase.getCollectionId(), CaseType.API_CASE.getKey());
boolean selectAllModule = apiCase.getModules().isSelectAllModule();
List<Map<String, ModuleSelectDTO>> moduleMaps = apiCase.getModules().getModuleMaps();
Map<String, ModuleSelectDTO> moduleMaps = apiCase.getModules().getModuleMaps();
if (selectAllModule) {
// 选择了全部模块
List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId());

View File

@ -198,7 +198,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
apiScenarioList.forEach(apiScenario -> {
super.checkCollection(testPlan.getId(), apiScenario.getCollectionId(), CaseType.SCENARIO_CASE.getKey());
boolean selectAllModule = apiScenario.getModules().isSelectAllModule();
List<Map<String, ModuleSelectDTO>> moduleMaps = apiScenario.getModules().getModuleMaps();
Map<String, ModuleSelectDTO> moduleMaps = apiScenario.getModules().getModuleMaps();
if (selectAllModule) {
// 选择了全部模块
List<ApiScenario> scenarioList = extApiScenarioMapper.selectAllCase(isRepeat, apiScenario.getModules().getProjectId(), testPlan.getId());

View File

@ -142,6 +142,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
public List<TestPlanResourceExecResultDTO> selectDistinctExecResult(String projectId) {
return extTestPlanFunctionalCaseMapper.selectDistinctExecResult(projectId);
}
@Override
public long copyResource(String originalTestPlanId, String newTestPlanId, Map<String, String> oldCollectionIdToNewCollectionId, String operator, long operatorTime) {
List<TestPlanFunctionalCase> copyList = new ArrayList<>();
@ -797,7 +798,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
private void buildTestPlanFunctionalCase(TestPlan testPlan, BaseCollectionAssociateRequest functional, SessionUser user, List<TestPlanFunctionalCase> testPlanFunctionalCaseList, boolean isRepeat) {
super.checkCollection(testPlan.getId(), functional.getCollectionId(), CaseType.FUNCTIONAL_CASE.getKey());
boolean selectAllModule = functional.getModules().isSelectAllModule();
List<Map<String, ModuleSelectDTO>> moduleMaps = functional.getModules().getModuleMaps();
Map<String, ModuleSelectDTO> moduleMaps = functional.getModules().getModuleMaps();
if (selectAllModule) {
// 选择了全部模块

View File

@ -67,6 +67,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
public abstract long copyResource(String originalTestPlanId, String newTestPlanId, Map<String, String> oldCollectionIdToNewCollectionId, String operator, long operatorTime);
public abstract List<TestPlanResourceExecResultDTO> selectDistinctExecResult(String projectId);
/**
* 关联用例
*
@ -106,23 +107,21 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
* @param moduleMaps
* @return
*/
protected AssociateCaseDTO getCaseIds(List<Map<String, ModuleSelectDTO>> moduleMaps) {
protected AssociateCaseDTO getCaseIds(Map<String, ModuleSelectDTO> moduleMaps) {
// 排除的ids
List<String> excludeIds = moduleMaps.stream()
.flatMap(map -> map.values().stream())
List<String> excludeIds = moduleMaps.values().stream()
.flatMap(moduleSelectDTO -> moduleSelectDTO.getExcludeIds().stream())
.toList();
// 选中的ids
List<String> selectIds = moduleMaps.stream()
.flatMap(map -> map.values().stream())
List<String> selectIds = moduleMaps.values().stream()
.flatMap(moduleSelectDTO -> moduleSelectDTO.getSelectIds().stream())
.toList();
// 全选的模块
List<String> moduleIds = moduleMaps.stream()
.flatMap(map -> map.entrySet().stream())
List<String> moduleIds = moduleMaps.entrySet().stream()
.filter(entry -> BooleanUtils.isTrue(entry.getValue().isSelectAll()) && org.apache.commons.collections.CollectionUtils.isEmpty(entry.getValue().getSelectIds()))
.map(Map.Entry::getKey)
.toList();
AssociateCaseDTO associateCaseDTO = new AssociateCaseDTO(excludeIds, selectIds, moduleIds);
return associateCaseDTO;
}

View File

@ -306,15 +306,13 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
return associateDTO;
}
private List<Map<String, ModuleSelectDTO>> buildModuleMap() {
List<Map<String, ModuleSelectDTO>> moduleMaps = new ArrayList<>();
private Map<String, ModuleSelectDTO> buildModuleMap() {
Map<String, ModuleSelectDTO> moduleMap = new HashMap<>();
ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();
moduleSelectDTO.setSelectAll(false);
moduleSelectDTO.setSelectIds(List.of("wxxx_api_1"));
moduleMap.put("123", moduleSelectDTO);
moduleMaps.add(moduleMap);
return moduleMaps;
return moduleMap;
}
private TestPlanCollectionAssociateDTO buildModulesAll(String type) {

View File

@ -294,15 +294,13 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
return associateDTO;
}
private List<Map<String, ModuleSelectDTO>> buildModuleMap() {
List<Map<String, ModuleSelectDTO>> moduleMaps = new ArrayList<>();
private Map<String, ModuleSelectDTO> buildModuleMap() {
Map<String, ModuleSelectDTO> moduleMap = new HashMap<>();
ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();
moduleSelectDTO.setSelectAll(false);
moduleSelectDTO.setSelectIds(List.of("wxxx_api_scenario_1"));
moduleMap.put("wx_scenario_module_123", moduleSelectDTO);
moduleMaps.add(moduleMap);
return moduleMaps;
return moduleMap;
}

View File

@ -395,15 +395,13 @@ public class TestPlanCaseControllerTests extends BaseTest {
return associateDTO;
}
private List<Map<String, ModuleSelectDTO>> buildModuleMap() {
List<Map<String, ModuleSelectDTO>> moduleMaps = new ArrayList<>();
private Map<String, ModuleSelectDTO> buildModuleMap() {
Map<String, ModuleSelectDTO> moduleMap = new HashMap<>();
ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();
moduleSelectDTO.setSelectAll(false);
moduleSelectDTO.setSelectIds(List.of("fc_1"));
moduleMap.put("100001", moduleSelectDTO);
moduleMaps.add(moduleMap);
return moduleMaps;
return moduleMap;
}
private TestPlanCollectionAssociateDTO buildModulesAll() {

View File

@ -222,13 +222,11 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest {
Assertions.assertTrue(CollectionUtils.isEmpty(testPlanCollections));
}
private List<Map<String, ModuleSelectDTO>> getModuleMaps() {
private Map<String, ModuleSelectDTO> getModuleMaps() {
ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();
moduleSelectDTO.setSelectAll(true);
moduleSelectDTO.setSelectIds(List.of("gyq_plan_api-case-associate-1"));
List<Map<String, ModuleSelectDTO>> moduleMaps = new ArrayList<>();
moduleMaps.add(Map.of("testmodule", moduleSelectDTO));
return moduleMaps;
return Map.of("testmodule", moduleSelectDTO);
}