refactor(接口测试): 接口管理测试增删改复制代码完善
This commit is contained in:
parent
c2c52dd971
commit
36a5753858
|
@ -5,12 +5,14 @@ import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lan
|
* @author lan
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Accessors(chain = true)
|
||||||
public class ApiDefinitionDTO extends ApiDefinition{
|
public class ApiDefinitionDTO extends ApiDefinition{
|
||||||
|
|
||||||
@Schema(description = "请求内容")
|
@Schema(description = "请求内容")
|
||||||
|
|
|
@ -105,7 +105,7 @@
|
||||||
set deleted = 1,
|
set deleted = 1,
|
||||||
delete_user = #{userId},
|
delete_user = #{userId},
|
||||||
delete_time = UNIX_TIMESTAMP()*1000
|
delete_time = UNIX_TIMESTAMP()*1000
|
||||||
where id in
|
where ref_id in
|
||||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
|
|
|
@ -145,25 +145,27 @@ public class ApiDefinitionLogService {
|
||||||
*/
|
*/
|
||||||
public List<LogDTO> batchUpdateLog(ApiDefinitionBatchUpdateRequest request) {
|
public List<LogDTO> batchUpdateLog(ApiDefinitionBatchUpdateRequest request) {
|
||||||
List<String> ids = apiDefinitionService.getBatchApiIds(request, request.getProjectId(), request.getProtocol());
|
List<String> ids = apiDefinitionService.getBatchApiIds(request, request.getProjectId(), request.getProtocol());
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
|
||||||
example.createCriteria().andIdIn(ids);
|
|
||||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
|
||||||
List<LogDTO> dtoList = new ArrayList<>();
|
List<LogDTO> dtoList = new ArrayList<>();
|
||||||
apiDefinitions.forEach(item -> {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
LogDTO dto = new LogDTO(
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
item.getProjectId(),
|
example.createCriteria().andIdIn(ids);
|
||||||
"",
|
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||||
item.getId(),
|
apiDefinitions.forEach(item -> {
|
||||||
item.getCreateUser(),
|
LogDTO dto = new LogDTO(
|
||||||
OperationLogType.UPDATE.name(),
|
item.getProjectId(),
|
||||||
OperationLogModule.API_DEFINITION,
|
"",
|
||||||
item.getName());
|
item.getId(),
|
||||||
|
item.getCreateUser(),
|
||||||
|
OperationLogType.UPDATE.name(),
|
||||||
|
OperationLogModule.API_DEFINITION,
|
||||||
|
item.getName());
|
||||||
|
|
||||||
dto.setPath("/api/definition/batch-update");
|
dto.setPath("/api/definition/batch-update");
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(item));
|
dto.setOriginalValue(JSON.toJSONBytes(item));
|
||||||
dtoList.add(dto);
|
dtoList.add(dto);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return dtoList;
|
return dtoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,12 +191,13 @@ public class ApiDefinitionLogService {
|
||||||
|
|
||||||
public List<LogDTO> batchMoveLog(ApiDefinitionBatchMoveRequest request) {
|
public List<LogDTO> batchMoveLog(ApiDefinitionBatchMoveRequest request) {
|
||||||
List<String> ids = apiDefinitionService.getBatchApiIds(request, request.getProjectId(), request.getProtocol());
|
List<String> ids = apiDefinitionService.getBatchApiIds(request, request.getProjectId(), request.getProtocol());
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
|
||||||
example.createCriteria().andIdIn(ids);
|
|
||||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
|
||||||
List<LogDTO> dtoList = new ArrayList<>();
|
List<LogDTO> dtoList = new ArrayList<>();
|
||||||
apiDefinitions.forEach(item -> {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
LogDTO dto = new LogDTO(
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
|
example.createCriteria().andIdIn(ids);
|
||||||
|
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||||
|
apiDefinitions.forEach(item -> {
|
||||||
|
LogDTO dto = new LogDTO(
|
||||||
item.getProjectId(),
|
item.getProjectId(),
|
||||||
"",
|
"",
|
||||||
item.getId(),
|
item.getId(),
|
||||||
|
@ -203,29 +206,33 @@ public class ApiDefinitionLogService {
|
||||||
OperationLogModule.API_DEFINITION,
|
OperationLogModule.API_DEFINITION,
|
||||||
item.getName());
|
item.getName());
|
||||||
|
|
||||||
dto.setPath("/api/definition/batch-move");
|
dto.setPath("/api/definition/batch-move");
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(item));
|
dto.setOriginalValue(JSON.toJSONBytes(item));
|
||||||
dtoList.add(dto);
|
dtoList.add(dto);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return dtoList;
|
return dtoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogDTO followLog(String id) {
|
public LogDTO followLog(String id) {
|
||||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
|
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||||
Project project = projectMapper.selectByPrimaryKey(apiDefinition.getProjectId());
|
if(apiDefinition != null){
|
||||||
LogDTO dto = new LogDTO(
|
Project project = projectMapper.selectByPrimaryKey(apiDefinition.getProjectId());
|
||||||
apiDefinition.getProjectId(),
|
LogDTO dto = new LogDTO(
|
||||||
project.getOrganizationId(),
|
apiDefinition.getProjectId(),
|
||||||
id,
|
project.getOrganizationId(),
|
||||||
null,
|
id,
|
||||||
OperationLogType.UPDATE.name(),
|
null,
|
||||||
OperationLogModule.API_DEFINITION,
|
OperationLogType.UPDATE.name(),
|
||||||
Translator.get("follow") + apiDefinition.getName());
|
OperationLogModule.API_DEFINITION,
|
||||||
|
Translator.get("follow") + apiDefinition.getName());
|
||||||
|
|
||||||
dto.setPath("/api/definition/follow/" + id);
|
dto.setPath("/api/definition/follow/" + id);
|
||||||
dto.setMethod(HttpMethodConstants.GET.name());
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||||
return dto;
|
return dto;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,6 @@ public class ApiDefinitionService {
|
||||||
@Resource
|
@Resource
|
||||||
private SqlSessionFactory sqlSessionFactory;
|
private SqlSessionFactory sqlSessionFactory;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ApiTestCaseService apiTestCaseService;
|
|
||||||
|
|
||||||
public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request, Boolean deleted){
|
public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request, Boolean deleted){
|
||||||
List<ApiDefinitionDTO> list = extApiDefinitionMapper.list(request, deleted);
|
List<ApiDefinitionDTO> list = extApiDefinitionMapper.list(request, deleted);
|
||||||
|
@ -212,16 +210,17 @@ public class ApiDefinitionService {
|
||||||
|
|
||||||
public void batchMove(ApiDefinitionBatchMoveRequest request, String userId) {
|
public void batchMove(ApiDefinitionBatchMoveRequest request, String userId) {
|
||||||
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocol());
|
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocol());
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
if (!ids.isEmpty()) {
|
||||||
List<String> refId = extApiDefinitionMapper.getRefIds(ids);
|
List<String> refIds = extApiDefinitionMapper.getRefIds(ids);
|
||||||
extApiDefinitionMapper.batchMove(request, refId, userId);
|
if (!refIds.isEmpty()) {
|
||||||
|
extApiDefinitionMapper.batchMove(request, refIds, userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processApiDefinitions(List<ApiDefinitionDTO> list, String projectId) {
|
private void processApiDefinitions(List<ApiDefinitionDTO> list, String projectId) {
|
||||||
Set<String> userIds = extractUserIds(list);
|
Set<String> userIds = extractUserIds(list);
|
||||||
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds));
|
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds));
|
||||||
|
|
||||||
List<String> apiDefinitionIds = list.stream().map(ApiDefinitionDTO::getId).toList();
|
List<String> apiDefinitionIds = list.stream().map(ApiDefinitionDTO::getId).toList();
|
||||||
List<ApiCaseComputeDTO> apiCaseComputeList = extApiDefinitionMapper.selectApiCaseByIdsAndStatusIsNotTrash(apiDefinitionIds, projectId);
|
List<ApiCaseComputeDTO> apiCaseComputeList = extApiDefinitionMapper.selectApiCaseByIdsAndStatusIsNotTrash(apiDefinitionIds, projectId);
|
||||||
Map<String, ApiCaseComputeDTO> resultMap = apiCaseComputeList.stream().collect(Collectors.toMap(ApiCaseComputeDTO::getApiDefinitionId, Function.identity()));
|
Map<String, ApiCaseComputeDTO> resultMap = apiCaseComputeList.stream().collect(Collectors.toMap(ApiCaseComputeDTO::getApiDefinitionId, Function.identity()));
|
||||||
|
@ -278,8 +277,6 @@ public class ApiDefinitionService {
|
||||||
FileRequest fileRequest = new FileRequest();
|
FileRequest fileRequest = new FileRequest();
|
||||||
fileRequest.setFileName(file.getName());
|
fileRequest.setFileName(file.getName());
|
||||||
fileRequest.setFolder(minioPath(projectId));
|
fileRequest.setFolder(minioPath(projectId));
|
||||||
fileRequest.setProjectId(projectId);
|
|
||||||
fileRequest.setResourceId(apiId);
|
|
||||||
fileRequest.setStorage(StorageType.MINIO.name());
|
fileRequest.setStorage(StorageType.MINIO.name());
|
||||||
try {
|
try {
|
||||||
minioRepository.saveFile(file, fileRequest);
|
minioRepository.saveFile(file, fileRequest);
|
||||||
|
@ -418,19 +415,13 @@ public class ApiDefinitionService {
|
||||||
return copyName;
|
return copyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, ApiDefinitionBlob> copyBlobInfo(List<String> ids) {
|
|
||||||
ApiDefinitionBlobExample blobExample = new ApiDefinitionBlobExample();
|
|
||||||
blobExample.createCriteria().andIdIn(ids);
|
|
||||||
List<ApiDefinitionBlob> apiDefinitionBlobs = apiDefinitionBlobMapper.selectByExampleWithBLOBs(blobExample);
|
|
||||||
return apiDefinitionBlobs.stream().collect(Collectors.toMap(ApiDefinitionBlob::getId, apiDefinitionBlob -> apiDefinitionBlob));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleDeleteApiDefinition(List<String> ids, Boolean deleteAll, String userId) {
|
private void handleDeleteApiDefinition(List<String> ids, Boolean deleteAll, String userId) {
|
||||||
if (deleteAll) {
|
if (deleteAll) {
|
||||||
//全部删除 进入回收站
|
//全部删除 进入回收站
|
||||||
List<String> refId = extApiDefinitionMapper.getRefIds(ids);
|
List<String> refId = extApiDefinitionMapper.getRefIds(ids);
|
||||||
extApiDefinitionMapper.batchDelete(refId, userId);
|
if(CollectionUtils.isNotEmpty(refId)){
|
||||||
|
extApiDefinitionMapper.batchDelete(refId, userId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//列表删除 需要判断是否存在多个版本问题
|
//列表删除 需要判断是否存在多个版本问题
|
||||||
ids.forEach(id -> {
|
ids.forEach(id -> {
|
||||||
|
|
|
@ -71,31 +71,9 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
@Resource
|
@Resource
|
||||||
private ApiDefinitionFollowerMapper apiDefinitionFollowerMapper;
|
private ApiDefinitionFollowerMapper apiDefinitionFollowerMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ApiDefinitionModuleMapper apiDefinitionModuleMapper;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ExtBaseProjectVersionMapper extBaseProjectVersionMapper;
|
private ExtBaseProjectVersionMapper extBaseProjectVersionMapper;
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(0)
|
|
||||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
|
||||||
public void initData(){
|
|
||||||
LogUtils.info("init api test data");
|
|
||||||
ApiDefinitionModule request = new ApiDefinitionModule();
|
|
||||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
|
||||||
request.setName("a1");
|
|
||||||
request.setId(DEFAULT_MODULE_ID);
|
|
||||||
request.setProtocol("HTTP");
|
|
||||||
request.setParentId("root");
|
|
||||||
request.setPos(10L);
|
|
||||||
request.setCreateTime(0L);
|
|
||||||
request.setUpdateTime(0L);
|
|
||||||
request.setUpdateUser("admin");
|
|
||||||
request.setCreateUser("admin");
|
|
||||||
apiDefinitionModuleMapper.insertSelective(request);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
|
@ -121,7 +99,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
ApiDefinition resultData = getResultData(mvcResult, ApiDefinition.class);
|
ApiDefinition resultData = getResultData(mvcResult, ApiDefinition.class);
|
||||||
ApiDefinition apiDefinition = assertAddApiDefinition(request, msHttpElement, resultData.getId());
|
ApiDefinition apiDefinition = assertAddApiDefinition(request, msHttpElement, resultData.getId());
|
||||||
// 再插入一条数据,便于修改时重名校验
|
// 再插入一条数据,便于修改时重名校验
|
||||||
request.setName("接口定义test1");
|
request.setName("接口定义test-6");
|
||||||
paramMap.clear();
|
paramMap.clear();
|
||||||
paramMap.add("request", JSON.toJSONString(request));
|
paramMap.add("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(ADD, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(ADD, paramMap);
|
||||||
|
@ -210,7 +188,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||||
public void testUpdate() throws Exception {
|
public void testUpdate() throws Exception {
|
||||||
LogUtils.info("delete api test");
|
LogUtils.info("update api test");
|
||||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||||
ApiDefinitionUpdateRequest request = new ApiDefinitionUpdateRequest();
|
ApiDefinitionUpdateRequest request = new ApiDefinitionUpdateRequest();
|
||||||
BeanUtils.copyBean(request, apiDefinition);
|
BeanUtils.copyBean(request, apiDefinition);
|
||||||
|
@ -461,49 +439,58 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
checkLog(apiDefinition.getId(), OperationLogType.DELETE);
|
checkLog(apiDefinition.getId(), OperationLogType.DELETE);
|
||||||
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||||
Assertions.assertTrue(apiDefinitionInfo.getDeleted());
|
Assertions.assertTrue(apiDefinitionInfo.getDeleted());
|
||||||
Assertions.assertEquals(apiDefinitionInfo.getDeleteUser(), "admin");
|
Assertions.assertEquals("admin", apiDefinitionInfo.getDeleteUser());
|
||||||
Assertions.assertNotNull(apiDefinitionInfo.getDeleteTime());
|
Assertions.assertNotNull(apiDefinitionInfo.getDeleteTime());
|
||||||
|
|
||||||
// @存在多个版本
|
// @存在多个版本
|
||||||
MvcResult mvcResult = this.requestGetWithOk(VERSION + apiDefinition.getId()).andReturn();
|
// 列表删除
|
||||||
|
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||||
|
apiDefinitionDeleteRequest.setId("1004");
|
||||||
|
ApiDefinition delApiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionDeleteRequest.getId());
|
||||||
|
MvcResult mvcResult = this.requestGetWithOk(VERSION + apiDefinitionDeleteRequest.getId()).andReturn();
|
||||||
ApiDataUtils.setResolver(MsHTTPElement.class);
|
ApiDataUtils.setResolver(MsHTTPElement.class);
|
||||||
List<ApiDefinitionVersionDTO> apiDefinitionVersionDTO = getResultDataArray(mvcResult, ApiDefinitionVersionDTO.class);
|
List<ApiDefinitionVersionDTO> apiDefinitionVersionDTO = getResultDataArray(mvcResult, ApiDefinitionVersionDTO.class);
|
||||||
if(!apiDefinitionVersionDTO.isEmpty()){
|
if(!apiDefinitionVersionDTO.isEmpty()){
|
||||||
ApiDefinition delApiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionDeleteRequest.getId());
|
|
||||||
// 列表删除
|
|
||||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
|
||||||
apiDefinitionDeleteRequest.setId("1004");
|
|
||||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||||
checkLog(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE);
|
// 效验数据
|
||||||
Assertions.assertTrue(delApiDefinition.getDeleted());
|
|
||||||
Assertions.assertEquals(delApiDefinition.getDeleteUser(), "admin");
|
|
||||||
Assertions.assertNotNull(delApiDefinition.getDeleteTime());
|
|
||||||
// 删除的数据为最新版本需要更新最近一条数据为最新数据
|
// 删除的数据为最新版本需要更新最近一条数据为最新数据
|
||||||
if(delApiDefinition.getLatest()){
|
if(delApiDefinition.getLatest()){
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
example.createCriteria().andRefIdEqualTo(delApiDefinition.getRefId()).andDeletedEqualTo(false).andProjectIdEqualTo(delApiDefinition.getProjectId());
|
example.createCriteria().andRefIdEqualTo(delApiDefinition.getRefId()).andDeletedEqualTo(false).andProjectIdEqualTo(delApiDefinition.getProjectId());
|
||||||
example.setOrderByClause("update_time DESC");
|
example.setOrderByClause("update_time DESC");
|
||||||
apiDefinitionMapper.selectByExample(example).stream().findFirst().ifPresent(updateApiDefinition -> Assertions.assertTrue(updateApiDefinition.getLatest()));
|
ApiDefinition updateApiDefinition = apiDefinitionMapper.selectByExample(example).stream().findFirst().orElse(null);
|
||||||
|
if(updateApiDefinition != null) {
|
||||||
|
Assertions.assertTrue(updateApiDefinition.getLatest());
|
||||||
|
Assertions.assertFalse(updateApiDefinition.getDeleted());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 全部删除
|
ApiDefinition delApiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionDeleteRequest.getId());
|
||||||
apiDefinitionDeleteRequest.setDeleteAll(true);
|
if(delApiDefinitionInfo != null){
|
||||||
apiDefinitionDeleteRequest.setId("1006");
|
Assertions.assertTrue(delApiDefinitionInfo.getDeleted());
|
||||||
// @@请求成功
|
Assertions.assertEquals("admin", delApiDefinitionInfo.getDeleteUser());
|
||||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
Assertions.assertNotNull(delApiDefinitionInfo.getDeleteTime());
|
||||||
|
|
||||||
List<String> ids = extApiDefinitionMapper.getApiDefinitionByRefId(apiDefinitionDeleteRequest.getId()).stream().map(ApiDefinitionVersionDTO::getId).toList();
|
|
||||||
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
|
||||||
apiDefinitionExample.createCriteria().andIdIn(ids).andDeletedEqualTo(false);
|
|
||||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(apiDefinitionExample);
|
|
||||||
if(CollectionUtils.isNotEmpty(apiDefinitions)){
|
|
||||||
apiDefinitions.forEach(item -> {
|
|
||||||
Assertions.assertTrue(item.getDeleted());
|
|
||||||
Assertions.assertEquals(item.getDeleteUser(), "admin");
|
|
||||||
Assertions.assertNotNull(item.getDeleteTime());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
checkLog(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE);
|
checkLog(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// 全部删除
|
||||||
|
apiDefinitionDeleteRequest.setDeleteAll(true);
|
||||||
|
apiDefinitionDeleteRequest.setId("1002");
|
||||||
|
// @@请求成功
|
||||||
|
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||||
|
|
||||||
|
List<String> ids = extApiDefinitionMapper.getApiDefinitionByRefId(apiDefinitionDeleteRequest.getId()).stream().map(ApiDefinitionVersionDTO::getId).toList();
|
||||||
|
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
||||||
|
apiDefinitionExample.createCriteria().andIdIn(ids);
|
||||||
|
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(apiDefinitionExample);
|
||||||
|
if(CollectionUtils.isNotEmpty(apiDefinitions)){
|
||||||
|
apiDefinitions.forEach(item -> {
|
||||||
|
Assertions.assertTrue(item.getDeleted());
|
||||||
|
Assertions.assertEquals("admin", item.getDeleteUser());
|
||||||
|
Assertions.assertNotNull(item.getDeleteTime());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
checkLog(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE);
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, DELETE, apiDefinitionDeleteRequest);
|
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, DELETE, apiDefinitionDeleteRequest);
|
||||||
}
|
}
|
||||||
|
@ -527,6 +514,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
checkLog("1002", OperationLogType.DELETE);
|
checkLog("1002", OperationLogType.DELETE);
|
||||||
checkLog("1005", OperationLogType.DELETE);
|
checkLog("1005", OperationLogType.DELETE);
|
||||||
// 删除全部 条件为关键字为st-6的数据
|
// 删除全部 条件为关键字为st-6的数据
|
||||||
|
request.setDeleteAll(true);
|
||||||
request.setSelectAll(true);
|
request.setSelectAll(true);
|
||||||
BaseCondition baseCondition = new BaseCondition();
|
BaseCondition baseCondition = new BaseCondition();
|
||||||
baseCondition.setKeyword("st-6");
|
baseCondition.setKeyword("st-6");
|
||||||
|
|
|
@ -26,3 +26,6 @@ INSERT INTO `api_report` (`id`, `name`, `resource_id`, `create_time`, `update_ti
|
||||||
INSERT INTO `api_report` (`id`, `name`, `resource_id`, `create_time`, `update_time`, `create_user`, `update_user`, `deleted`, `status`, `start_time`, `end_time`, `run_mode`, `pool_id`, `trigger_mode`, `version_id`, `project_id`, `integrated_report_id`, `integrated`) VALUES ('10004', '报告004', 'resource_id_10001', 1680624405386, 1680624405386, 'admin', 'admin', b'0', 'SUCCESS', 1680624405386, 1680624405386, 'API', 'pol_id_100001', 'hand', NULL, '100001100001', 'NONE', b'0');
|
INSERT INTO `api_report` (`id`, `name`, `resource_id`, `create_time`, `update_time`, `create_user`, `update_user`, `deleted`, `status`, `start_time`, `end_time`, `run_mode`, `pool_id`, `trigger_mode`, `version_id`, `project_id`, `integrated_report_id`, `integrated`) VALUES ('10004', '报告004', 'resource_id_10001', 1680624405386, 1680624405386, 'admin', 'admin', b'0', 'SUCCESS', 1680624405386, 1680624405386, 'API', 'pol_id_100001', 'hand', NULL, '100001100001', 'NONE', b'0');
|
||||||
INSERT INTO `api_report` (`id`, `name`, `resource_id`, `create_time`, `update_time`, `create_user`, `update_user`, `deleted`, `status`, `start_time`, `end_time`, `run_mode`, `pool_id`, `trigger_mode`, `version_id`, `project_id`, `integrated_report_id`, `integrated`) VALUES ('10005', '报告005', 'resource_id_10001', 1680624405386, 1680624405386, 'admin', 'admin', b'0', 'ERROR', 1680624405386, 1680624405386, 'API', 'pol_id_100001', 'hand', NULL, '100001100001', 'NONE', b'0');
|
INSERT INTO `api_report` (`id`, `name`, `resource_id`, `create_time`, `update_time`, `create_user`, `update_user`, `deleted`, `status`, `start_time`, `end_time`, `run_mode`, `pool_id`, `trigger_mode`, `version_id`, `project_id`, `integrated_report_id`, `integrated`) VALUES ('10005', '报告005', 'resource_id_10001', 1680624405386, 1680624405386, 'admin', 'admin', b'0', 'ERROR', 1680624405386, 1680624405386, 'API', 'pol_id_100001', 'hand', NULL, '100001100001', 'NONE', b'0');
|
||||||
INSERT INTO `api_report` (`id`, `name`, `resource_id`, `create_time`, `update_time`, `create_user`, `update_user`, `deleted`, `status`, `start_time`, `end_time`, `run_mode`, `pool_id`, `trigger_mode`, `version_id`, `project_id`, `integrated_report_id`, `integrated`) VALUES ('10006', '报告006', 'resource_id_10001', 1680624405386, 1680624405386, 'admin', 'admin', b'0', 'SUCCESS', 1680624405386, 1680624405386, 'API', 'pol_id_100001', 'hand', NULL, '100001100001', 'NONE', b'0');
|
INSERT INTO `api_report` (`id`, `name`, `resource_id`, `create_time`, `update_time`, `create_user`, `update_user`, `deleted`, `status`, `start_time`, `end_time`, `run_mode`, `pool_id`, `trigger_mode`, `version_id`, `project_id`, `integrated_report_id`, `integrated`) VALUES ('10006', '报告006', 'resource_id_10001', 1680624405386, 1680624405386, 'admin', 'admin', b'0', 'SUCCESS', 1680624405386, 1680624405386, 'API', 'pol_id_100001', 'hand', NULL, '100001100001', 'NONE', b'0');
|
||||||
|
|
||||||
|
DELETE FROM `api_definition_module` WHERE `id` = '10001';
|
||||||
|
INSERT INTO `api_definition_module` (`id`, `name`, `protocol`, `parent_id`, `project_id`, `pos`, `create_time`, `update_time`, `update_user`, `create_user`) VALUES ('10001', 'module1', 'HTTP', 'root', '100001100001', 10, 0, 0, 'admin', 'admin');
|
||||||
|
|
Loading…
Reference in New Issue