refactor(接口测试): 接口管理模块接口定义去除分页返回 Blob 内容

This commit is contained in:
lan-yonghui 2023-11-24 13:07:22 +08:00 committed by Craftsman
parent 53c01b7f2d
commit f313c43ba3
3 changed files with 30 additions and 34 deletions

View File

@ -46,6 +46,6 @@ public class ApiDefinitionPageRequest extends BasePageRequest {
@Schema(description = "模块ID(根据模块树查询时要把当前节点以及子节点都放在这里。)")
private List<String> moduleIds;
@Schema(description = "删除状态(状态为 0 时为回收站数据)")
@Schema(description = "删除状态(状态为 1 时为回收站数据)")
private Boolean deleted = false;
}

View File

@ -265,15 +265,6 @@ public class ApiDefinitionService {
item.setDeleteUserName(userMap.get(item.getDeleteUser()));
item.setUpdateUserName(userMap.get(item.getUpdateUser()));
// Convert Blob
Optional<ApiDefinitionBlob> apiDefinitionBlobOptional = Optional.ofNullable(apiDefinitionBlobMapper.selectByPrimaryKey(item.getId()));
apiDefinitionBlobOptional.ifPresent(blob -> {
item.setRequest(ApiDataUtils.parseObject(new String(blob.getRequest()), AbstractMsTestElement.class));
// blob.getResponse() null 时不进行转换
if (blob.getResponse() != null) {
item.setResponse(ApiDataUtils.parseArray(new String(blob.getResponse()), HttpResponse.class));
}
});
// Calculate API Case Metrics
ApiCaseComputeDTO apiCaseComputeDTO = resultMap.get(item.getId());
if (apiCaseComputeDTO != null) {

View File

@ -611,7 +611,29 @@ public class ApiDefinitionControllerTests extends BaseTest {
@Order(11)
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void getPage() throws Exception {
ApiDefinitionPageRequest request = createApiDefinitionPageRequest();
doApiDefinitionPage("All");
doApiDefinitionPage("KEYWORD");
doApiDefinitionPage("FILTER");
doApiDefinitionPage("COMBINE");
doApiDefinitionPage("DELETED");
}
private void doApiDefinitionPage(String search) throws Exception {
ApiDefinitionPageRequest request = new ApiDefinitionPageRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setCurrent(1);
request.setPageSize(10);
request.setDeleted(false);
request.setSort(Map.of("createTime", "asc"));
// "ALL", "KEYWORD", "FILTER", "COMBINE", "DELETED"
switch (search) {
case "ALL" -> configureAllSearch(request);
case "KEYWORD" -> configureKeywordSearch(request);
case "FILTER" -> configureFilterSearch(request);
case "COMBINE" -> configureCombineSearch(request);
case "DELETED" -> configureDeleteSearch(request);
default -> {}
}
MvcResult mvcResult = this.requestPostWithOkAndReturn(PAGE, request);
// 获取返回值
@ -626,30 +648,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
Assertions.assertEquals(pageData.getCurrent(), request.getCurrent());
// 返回的数据量不超过规定要返回的数据量相同
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(pageData.getList())).size() <= request.getPageSize());
}
private ApiDefinitionPageRequest createApiDefinitionPageRequest() {
ApiDefinitionPageRequest request = new ApiDefinitionPageRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setCurrent(1);
request.setPageSize(10);
request.setSort(Map.of("createTime", "asc"));
String search = getRandomSearchType();
switch (search) {
case "ALL" -> configureAllSearch(request);
case "KEYWORD" -> configureKeywordSearch(request);
case "FILTER" -> configureFilterSearch(request);
case "COMBINE" -> configureCombineSearch(request);
default -> {}
}
return request;
}
private String getRandomSearchType() {
List<String> searchTypes = Arrays.asList("ALL", "KEYWORD", "FILTER", "COMBINE");
return searchTypes.get(new Random().nextInt(searchTypes.size()));
}
private void configureAllSearch(ApiDefinitionPageRequest request) {
@ -686,6 +685,12 @@ public class ApiDefinitionControllerTests extends BaseTest {
request.setCombine(map);
}
private void configureDeleteSearch(ApiDefinitionPageRequest request) {
request.setKeyword("100");
request.setVersionId("100570499574136985");
request.setDeleted(true);
}
@Test
@Order(12)
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))