refactor(接口测试): 接口同步功能优化
--user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001016065 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001015922 refactor(接口测试): 接口同步发消息功能优化 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001015943 refactor(接口测试): 接口同步功能优化 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001016065 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001015922
This commit is contained in:
parent
a3f49e4ca2
commit
b6048c9845
|
@ -0,0 +1,31 @@
|
||||||
|
package io.metersphere.api.dto.definition;
|
||||||
|
|
||||||
|
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||||
|
import io.metersphere.api.dto.mockconfig.MockConfigImportDTO;
|
||||||
|
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||||
|
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class ApiDefinitionImportParamDTO {
|
||||||
|
private ApiDefinitionWithBLOBs apiDefinition;
|
||||||
|
private ApiTestImportRequest apiTestImportRequest;
|
||||||
|
private List<MockConfigImportDTO> mocks;
|
||||||
|
private List<ApiDefinitionWithBLOBs> updateList;
|
||||||
|
private List<ApiTestCaseWithBLOBs> caseList;
|
||||||
|
|
||||||
|
public ApiDefinitionImportParamDTO() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiDefinitionImportParamDTO(ApiDefinitionWithBLOBs apiDefinition, ApiTestImportRequest apiTestImportRequest, List<MockConfigImportDTO> mocks, List<ApiDefinitionWithBLOBs> updateList, List<ApiTestCaseWithBLOBs> caseList) {
|
||||||
|
this.apiDefinition = apiDefinition;
|
||||||
|
this.apiTestImportRequest = apiTestImportRequest;
|
||||||
|
this.mocks = mocks;
|
||||||
|
this.updateList = updateList;
|
||||||
|
this.caseList = caseList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,4 +33,6 @@ public class ApiDefinitionResult extends ApiDefinitionWithBLOBs {
|
||||||
private String versionName;
|
private String versionName;
|
||||||
|
|
||||||
private Boolean versionEnable;
|
private Boolean versionEnable;
|
||||||
|
|
||||||
|
private boolean updated;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package io.metersphere.api.dto.definition;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class ApiImportSendNoticeDTO {
|
||||||
|
private ApiDefinitionResult apiDefinitionResult;
|
||||||
|
private List<ApiTestCaseDTO> caseDTOList;
|
||||||
|
}
|
|
@ -19,4 +19,5 @@ public class ApiTestCaseDTO extends ApiTestCase {
|
||||||
private String environment;
|
private String environment;
|
||||||
private String execResult;
|
private String execResult;
|
||||||
private String versionName;
|
private String versionName;
|
||||||
|
private boolean updated;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,10 @@ public class ApiTestCaseRequest extends BaseQueryRequest {
|
||||||
* 进入待更新列表用例状态集合
|
* 进入待更新列表用例状态集合
|
||||||
*/
|
*/
|
||||||
private List<String> statusList;
|
private List<String> statusList;
|
||||||
|
/**
|
||||||
|
* 不需要查用例状态
|
||||||
|
*/
|
||||||
|
private boolean noSearchStatus;
|
||||||
/**
|
/**
|
||||||
* 是否需要查询环境字段
|
* 是否需要查询环境字段
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -877,11 +877,10 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiDefinition importCreate(ApiDefinitionWithBLOBs apiDefinition, ApiDefinitionMapper batchMapper,
|
private ApiImportSendNoticeDTO importCreate(ApiDefinitionMapper batchMapper, ExtApiDefinitionMapper extApiDefinitionMapper, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionImportParamDTO apiDefinitionImportParamDTO) {
|
||||||
ExtApiDefinitionMapper extApiDefinitionMapper,
|
ApiImportSendNoticeDTO apiImportSendNoticeDTO = new ApiImportSendNoticeDTO();
|
||||||
ApiTestImportRequest apiTestImportRequest, List<MockConfigImportDTO> mocks,
|
|
||||||
List<ApiDefinitionWithBLOBs> updateList, ApiTestCaseMapper apiTestCaseMapper, List<ApiTestCaseWithBLOBs> caseList) {
|
|
||||||
SaveApiDefinitionRequest saveReq = new SaveApiDefinitionRequest();
|
SaveApiDefinitionRequest saveReq = new SaveApiDefinitionRequest();
|
||||||
|
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionImportParamDTO.getApiDefinition();
|
||||||
BeanUtils.copyBean(saveReq, apiDefinition);
|
BeanUtils.copyBean(saveReq, apiDefinition);
|
||||||
|
|
||||||
if (StringUtils.isEmpty(apiDefinition.getStatus())) {
|
if (StringUtils.isEmpty(apiDefinition.getStatus())) {
|
||||||
|
@ -892,10 +891,13 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
apiDefinition.setDescription(apiDefinition.getDescription());
|
apiDefinition.setDescription(apiDefinition.getDescription());
|
||||||
List<ApiDefinitionWithBLOBs> collect = updateList.stream().filter(t -> t.getId().equals(apiDefinition.getId())).collect(Collectors.toList());
|
List<ApiDefinitionWithBLOBs> collect = apiDefinitionImportParamDTO.getUpdateList().stream().filter(t -> t.getId().equals(apiDefinition.getId())).collect(Collectors.toList());
|
||||||
|
apiDefinitionImportParamDTO.setUpdateList(collect);
|
||||||
|
ApiTestImportRequest apiTestImportRequest = apiDefinitionImportParamDTO.getApiTestImportRequest();
|
||||||
|
List<MockConfigImportDTO> mocks = apiDefinitionImportParamDTO.getMocks();
|
||||||
|
List<ApiTestCaseWithBLOBs> caseList = apiDefinitionImportParamDTO.getCaseList();
|
||||||
if (StringUtils.equals("fullCoverage", apiTestImportRequest.getModeId())) {
|
if (StringUtils.equals("fullCoverage", apiTestImportRequest.getModeId())) {
|
||||||
_importCreate(collect, batchMapper, apiDefinition, extApiDefinitionMapper, apiTestImportRequest, mocks, apiTestCaseMapper, caseList);
|
return _importCreate(batchMapper, extApiDefinitionMapper, apiTestCaseMapper, apiDefinitionImportParamDTO);
|
||||||
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
||||||
if (CollectionUtils.isEmpty(collect)) {
|
if (CollectionUtils.isEmpty(collect)) {
|
||||||
String originId = apiDefinition.getId();
|
String originId = apiDefinition.getId();
|
||||||
|
@ -918,34 +920,41 @@ public class ApiDefinitionService {
|
||||||
String requestStr = setImportHashTree(apiDefinition);
|
String requestStr = setImportHashTree(apiDefinition);
|
||||||
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||||
apiDefinition.setRequest(requestStr);
|
apiDefinition.setRequest(requestStr);
|
||||||
sendImportApiCreateNotice(apiDefinition);
|
|
||||||
batchMapper.insert(apiDefinition);
|
batchMapper.insert(apiDefinition);
|
||||||
importCase(apiDefinition, apiTestCaseMapper, caseList);
|
List<ApiTestCaseDTO> apiTestCaseDTOS = importCase(apiDefinition, apiTestCaseMapper, caseList);
|
||||||
|
apiImportSendNoticeDTO.setCaseDTOList(apiTestCaseDTOS);
|
||||||
extApiDefinitionMapper.clearLatestVersion(apiDefinition.getRefId());
|
extApiDefinitionMapper.clearLatestVersion(apiDefinition.getRefId());
|
||||||
extApiDefinitionMapper.addLatestVersion(apiDefinition.getRefId());
|
extApiDefinitionMapper.addLatestVersion(apiDefinition.getRefId());
|
||||||
|
ApiDefinitionResult apiDefinitionResult = getApiDefinitionResult(apiDefinition, false);
|
||||||
|
apiImportSendNoticeDTO.setApiDefinitionResult(apiDefinitionResult);
|
||||||
|
return apiImportSendNoticeDTO;
|
||||||
} else {
|
} else {
|
||||||
//不覆盖的接口,如果没有sameRequest则不导入。此时清空mock信息
|
//不覆盖的接口,如果没有sameRequest则不导入。此时清空mock信息
|
||||||
mocks.clear();
|
mocks.clear();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_importCreate(collect, batchMapper, apiDefinition, extApiDefinitionMapper, apiTestImportRequest, mocks, apiTestCaseMapper, caseList);
|
return _importCreate(batchMapper, extApiDefinitionMapper, apiTestCaseMapper, apiDefinitionImportParamDTO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiDefinition;
|
private ApiDefinitionResult getApiDefinitionResult(ApiDefinitionWithBLOBs apiDefinition, boolean isUpdate) {
|
||||||
|
ApiDefinitionResult apiDefinitionResult = new ApiDefinitionResult();
|
||||||
|
BeanUtils.copyBean(apiDefinitionResult, apiDefinition);
|
||||||
|
apiDefinitionResult.setUpdated(isUpdate);
|
||||||
|
return apiDefinitionResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importCase(ApiDefinitionWithBLOBs apiDefinition, ApiTestCaseMapper apiTestCaseMapper, List<ApiTestCaseWithBLOBs> caseList) {
|
private List<ApiTestCaseDTO> importCase(ApiDefinitionWithBLOBs apiDefinition, ApiTestCaseMapper apiTestCaseMapper, List<ApiTestCaseWithBLOBs> caseList) {
|
||||||
if (CollectionUtils.isEmpty(caseList)) {
|
if (CollectionUtils.isEmpty(caseList)) {
|
||||||
return;
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
List<ApiTestCaseDTO> apiTestCaseDTOS = new ArrayList<>();
|
||||||
for (int i = 0; i < caseList.size(); i++) {
|
for (int i = 0; i < caseList.size(); i++) {
|
||||||
|
ApiTestCaseDTO apiTestCaseDTO = new ApiTestCaseDTO();
|
||||||
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = caseList.get(i);
|
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = caseList.get(i);
|
||||||
apiTestCaseWithBLOBs.setApiDefinitionId(apiDefinition.getId());
|
apiTestCaseWithBLOBs.setApiDefinitionId(apiDefinition.getId());
|
||||||
if (apiDefinition.getToBeUpdated() != null && apiDefinition.getToBeUpdated() && StringUtils.equalsIgnoreCase(apiTestCaseWithBLOBs.getVersionId(), "old_case")) {
|
apiTestCaseWithBLOBs.setToBeUpdated(apiDefinition.getToBeUpdated() != null && apiDefinition.getToBeUpdated() && StringUtils.equalsIgnoreCase(apiTestCaseWithBLOBs.getVersionId(), "old_case"));
|
||||||
apiTestCaseWithBLOBs.setToBeUpdated(true);
|
|
||||||
} else {
|
|
||||||
apiTestCaseWithBLOBs.setToBeUpdated(false);
|
|
||||||
}
|
|
||||||
apiTestCaseWithBLOBs.setVersionId(apiDefinition.getVersionId());
|
apiTestCaseWithBLOBs.setVersionId(apiDefinition.getVersionId());
|
||||||
if (apiTestCaseWithBLOBs.getCreateTime() == null) {
|
if (apiTestCaseWithBLOBs.getCreateTime() == null) {
|
||||||
apiTestCaseWithBLOBs.setCreateTime(System.currentTimeMillis());
|
apiTestCaseWithBLOBs.setCreateTime(System.currentTimeMillis());
|
||||||
|
@ -974,16 +983,20 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(apiTestCaseWithBLOBs.getId())) {
|
if (StringUtils.isNotBlank(apiTestCaseWithBLOBs.getId())) {
|
||||||
sendImportCaseUpdateNotice(apiTestCaseWithBLOBs);
|
BeanUtils.copyBean(apiTestCaseDTO, apiTestCaseWithBLOBs);
|
||||||
|
apiTestCaseDTO.setUpdated(true);
|
||||||
apiTestCaseMapper.updateByPrimaryKeyWithBLOBs(apiTestCaseWithBLOBs);
|
apiTestCaseMapper.updateByPrimaryKeyWithBLOBs(apiTestCaseWithBLOBs);
|
||||||
} else {
|
} else {
|
||||||
apiTestCaseWithBLOBs.setId(UUID.randomUUID().toString());
|
apiTestCaseWithBLOBs.setId(UUID.randomUUID().toString());
|
||||||
apiTestCaseWithBLOBs.setCreateUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
apiTestCaseWithBLOBs.setCreateUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||||
apiTestCaseWithBLOBs.setUpdateUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
apiTestCaseWithBLOBs.setUpdateUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||||
sendImportCaseCreateNotice(apiTestCaseWithBLOBs);
|
BeanUtils.copyBean(apiTestCaseDTO, apiTestCaseWithBLOBs);
|
||||||
|
apiTestCaseDTO.setUpdated(false);
|
||||||
apiTestCaseMapper.insert(apiTestCaseWithBLOBs);
|
apiTestCaseMapper.insert(apiTestCaseWithBLOBs);
|
||||||
}
|
}
|
||||||
|
apiTestCaseDTOS.add(apiTestCaseDTO);
|
||||||
}
|
}
|
||||||
|
return apiTestCaseDTOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getImportNextOrder(String projectId) {
|
public Long getImportNextOrder(String projectId) {
|
||||||
|
@ -1006,11 +1019,16 @@ public class ApiDefinitionService {
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _importCreate(List<ApiDefinitionWithBLOBs> sameRequest, ApiDefinitionMapper batchMapper, ApiDefinitionWithBLOBs apiDefinition,
|
private ApiImportSendNoticeDTO _importCreate(ApiDefinitionMapper batchMapper,
|
||||||
ExtApiDefinitionMapper extApiDefinitionMapper,
|
ExtApiDefinitionMapper extApiDefinitionMapper,
|
||||||
ApiTestImportRequest apiTestImportRequest, List<MockConfigImportDTO> mocks, ApiTestCaseMapper apiTestCaseMapper, List<ApiTestCaseWithBLOBs> caseList) {
|
ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionImportParamDTO apiDefinitionImportParamDTO) {
|
||||||
|
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionImportParamDTO.getApiDefinition();
|
||||||
|
ApiTestImportRequest apiTestImportRequest = apiDefinitionImportParamDTO.getApiTestImportRequest();
|
||||||
|
List<ApiDefinitionWithBLOBs> sameRequest = apiDefinitionImportParamDTO.getUpdateList();
|
||||||
|
List<MockConfigImportDTO> mocks = apiDefinitionImportParamDTO.getMocks();
|
||||||
|
List<ApiTestCaseWithBLOBs> caseList = apiDefinitionImportParamDTO.getCaseList();
|
||||||
String originId = apiDefinition.getId();
|
String originId = apiDefinition.getId();
|
||||||
|
ApiImportSendNoticeDTO apiImportSendNoticeDTO = new ApiImportSendNoticeDTO();
|
||||||
if (CollectionUtils.isEmpty(sameRequest)) { // 没有这个接口 新增
|
if (CollectionUtils.isEmpty(sameRequest)) { // 没有这个接口 新增
|
||||||
apiDefinition.setId(UUID.randomUUID().toString());
|
apiDefinition.setId(UUID.randomUUID().toString());
|
||||||
|
|
||||||
|
@ -1038,16 +1056,19 @@ public class ApiDefinitionService {
|
||||||
if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) {
|
if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) {
|
||||||
String request = setImportHashTree(apiDefinition);
|
String request = setImportHashTree(apiDefinition);
|
||||||
apiDefinition.setRequest(request);
|
apiDefinition.setRequest(request);
|
||||||
sendImportApiCreateNotice(apiDefinition);
|
|
||||||
batchMapper.insert(apiDefinition);
|
batchMapper.insert(apiDefinition);
|
||||||
|
ApiDefinitionResult apiDefinitionResult = getApiDefinitionResult(apiDefinition, false);
|
||||||
|
apiImportSendNoticeDTO.setApiDefinitionResult(apiDefinitionResult);
|
||||||
} else {
|
} else {
|
||||||
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
|
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
|
||||||
setImportTCPHashTree(apiDefinition);
|
setImportTCPHashTree(apiDefinition);
|
||||||
}
|
}
|
||||||
sendImportApiCreateNotice(apiDefinition);
|
|
||||||
batchMapper.insert(apiDefinition);
|
batchMapper.insert(apiDefinition);
|
||||||
|
ApiDefinitionResult apiDefinitionResult = getApiDefinitionResult(apiDefinition, false);
|
||||||
|
apiImportSendNoticeDTO.setApiDefinitionResult(apiDefinitionResult);
|
||||||
}
|
}
|
||||||
importCase(apiDefinition, apiTestCaseMapper, caseList);
|
List<ApiTestCaseDTO> apiTestCaseDTOS = importCase(apiDefinition, apiTestCaseMapper, caseList);
|
||||||
|
apiImportSendNoticeDTO.setCaseDTOList(apiTestCaseDTOS);
|
||||||
} else { //如果存在则修改
|
} else { //如果存在则修改
|
||||||
if (StringUtils.isEmpty(apiTestImportRequest.getUpdateVersionId())) {
|
if (StringUtils.isEmpty(apiTestImportRequest.getUpdateVersionId())) {
|
||||||
apiTestImportRequest.setUpdateVersionId(apiTestImportRequest.getDefaultVersion());
|
apiTestImportRequest.setUpdateVersionId(apiTestImportRequest.getDefaultVersion());
|
||||||
|
@ -1075,10 +1096,11 @@ public class ApiDefinitionService {
|
||||||
if (sameRequest.get(0).getUserId() != null) {
|
if (sameRequest.get(0).getUserId() != null) {
|
||||||
apiDefinition.setUserId(sameRequest.get(0).getUserId());
|
apiDefinition.setUserId(sameRequest.get(0).getUserId());
|
||||||
}
|
}
|
||||||
sendImportApiCreateNotice(apiDefinition);
|
|
||||||
batchMapper.insert(apiDefinition);
|
batchMapper.insert(apiDefinition);
|
||||||
sendImportApiCreateNotice(apiDefinition);
|
ApiDefinitionResult apiDefinitionResult = getApiDefinitionResult(apiDefinition, false);
|
||||||
importCase(apiDefinition, apiTestCaseMapper, caseList);
|
apiImportSendNoticeDTO.setApiDefinitionResult(apiDefinitionResult);
|
||||||
|
List<ApiTestCaseDTO> apiTestCaseDTOS = importCase(apiDefinition, apiTestCaseMapper, caseList);
|
||||||
|
apiImportSendNoticeDTO.setCaseDTOList(apiTestCaseDTOS);
|
||||||
} else {
|
} else {
|
||||||
ApiDefinitionWithBLOBs existApi = apiOp.get();
|
ApiDefinitionWithBLOBs existApi = apiOp.get();
|
||||||
apiDefinition.setStatus(existApi.getStatus());
|
apiDefinition.setStatus(existApi.getStatus());
|
||||||
|
@ -1125,8 +1147,9 @@ public class ApiDefinitionService {
|
||||||
apiDefinition.setOrder(existApi.getOrder());
|
apiDefinition.setOrder(existApi.getOrder());
|
||||||
apiDefinition.setRequest(request);
|
apiDefinition.setRequest(request);
|
||||||
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||||
sendImportApiUpdateNotice(existApi);
|
|
||||||
batchMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
batchMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
||||||
|
ApiDefinitionResult apiDefinitionResult = getApiDefinitionResult(apiDefinition, true);
|
||||||
|
apiImportSendNoticeDTO.setApiDefinitionResult(apiDefinitionResult);
|
||||||
} else {
|
} else {
|
||||||
apiDefinition.setId(existApi.getId());
|
apiDefinition.setId(existApi.getId());
|
||||||
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
|
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
|
||||||
|
@ -1134,14 +1157,17 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
apiDefinition.setOrder(existApi.getOrder());
|
apiDefinition.setOrder(existApi.getOrder());
|
||||||
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||||
sendImportApiUpdateNotice(existApi);
|
|
||||||
batchMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
batchMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
||||||
|
ApiDefinitionResult apiDefinitionResult = getApiDefinitionResult(apiDefinition, true);
|
||||||
|
apiImportSendNoticeDTO.setApiDefinitionResult(apiDefinitionResult);
|
||||||
}
|
}
|
||||||
importCase(apiDefinition, apiTestCaseMapper, caseList);
|
List<ApiTestCaseDTO> apiTestCaseDTOS = importCase(apiDefinition, apiTestCaseMapper, caseList);
|
||||||
|
apiImportSendNoticeDTO.setCaseDTOList(apiTestCaseDTOS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
extApiDefinitionMapper.clearLatestVersion(apiDefinition.getRefId());
|
extApiDefinitionMapper.clearLatestVersion(apiDefinition.getRefId());
|
||||||
extApiDefinitionMapper.addLatestVersion(apiDefinition.getRefId());
|
extApiDefinitionMapper.addLatestVersion(apiDefinition.getRefId());
|
||||||
|
return apiImportSendNoticeDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendImportApiUpdateNotice(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs) {
|
public void sendImportApiUpdateNotice(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs) {
|
||||||
|
@ -1628,7 +1654,7 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
importApi(request, apiImport);
|
List<ApiImportSendNoticeDTO> apiImportSendNoticeDTOS = importApi(request, apiImport);
|
||||||
if (CollectionUtils.isNotEmpty(apiImport.getData())) {
|
if (CollectionUtils.isNotEmpty(apiImport.getData())) {
|
||||||
List<String> names = apiImport.getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList());
|
List<String> names = apiImport.getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList());
|
||||||
request.setName(String.join(",", names));
|
request.setName(String.join(",", names));
|
||||||
|
@ -1651,6 +1677,26 @@ public class ApiDefinitionService {
|
||||||
.build();
|
.build();
|
||||||
noticeSendService.send(NoticeConstants.Mode.SCHEDULE, "", noticeModel);
|
noticeSendService.send(NoticeConstants.Mode.SCHEDULE, "", noticeModel);
|
||||||
}
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(apiImportSendNoticeDTOS)) {
|
||||||
|
for (ApiImportSendNoticeDTO apiImportSendNoticeDTO : apiImportSendNoticeDTOS) {
|
||||||
|
if (apiImportSendNoticeDTO.getApiDefinitionResult() != null && apiImportSendNoticeDTO.getApiDefinitionResult().isUpdated()) {
|
||||||
|
sendImportApiCreateNotice(apiImportSendNoticeDTO.getApiDefinitionResult());
|
||||||
|
}
|
||||||
|
if (apiImportSendNoticeDTO.getApiDefinitionResult() != null && !apiImportSendNoticeDTO.getApiDefinitionResult().isUpdated()) {
|
||||||
|
sendImportApiUpdateNotice(apiImportSendNoticeDTO.getApiDefinitionResult());
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(apiImportSendNoticeDTO.getCaseDTOList())) {
|
||||||
|
for (ApiTestCaseDTO apiTestCaseDTO : apiImportSendNoticeDTO.getCaseDTOList()) {
|
||||||
|
if (apiTestCaseDTO.isUpdated()) {
|
||||||
|
sendImportCaseUpdateNotice(apiTestCaseDTO);
|
||||||
|
}
|
||||||
|
if (!apiTestCaseDTO.isUpdated()) {
|
||||||
|
sendImportCaseCreateNotice(apiTestCaseDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
this.sendFailMessage(request, project);
|
this.sendFailMessage(request, project);
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
|
@ -1696,7 +1742,7 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importApi(ApiTestImportRequest request, ApiDefinitionImport apiImport) {
|
private List<ApiImportSendNoticeDTO> importApi(ApiTestImportRequest request, ApiDefinitionImport apiImport) {
|
||||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
currentApiCaseOrder.remove();
|
currentApiCaseOrder.remove();
|
||||||
currentApiOrder.remove();
|
currentApiOrder.remove();
|
||||||
|
@ -1713,7 +1759,7 @@ public class ApiDefinitionService {
|
||||||
//过滤(一次只导入一个协议)
|
//过滤(一次只导入一个协议)
|
||||||
List<ApiDefinitionWithBLOBs> filterData = initData.stream().filter(t -> t.getProtocol().equals(request.getProtocol())).collect(Collectors.toList());
|
List<ApiDefinitionWithBLOBs> filterData = initData.stream().filter(t -> t.getProtocol().equals(request.getProtocol())).collect(Collectors.toList());
|
||||||
if (filterData.isEmpty()) {
|
if (filterData.isEmpty()) {
|
||||||
return;
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
UpdateApiModuleDTO updateApiModuleDTO = apiModuleService.checkApiModule(request, apiImport, filterData, StringUtils.equals("fullCoverage", request.getModeId()), urlRepeat);
|
UpdateApiModuleDTO updateApiModuleDTO = apiModuleService.checkApiModule(request, apiImport, filterData, StringUtils.equals("fullCoverage", request.getModeId()), urlRepeat);
|
||||||
List<ApiDefinitionWithBLOBs> updateList = updateApiModuleDTO.getNeedUpdateList();
|
List<ApiDefinitionWithBLOBs> updateList = updateApiModuleDTO.getNeedUpdateList();
|
||||||
|
@ -1741,6 +1787,7 @@ public class ApiDefinitionService {
|
||||||
if (data.isEmpty()) {
|
if (data.isEmpty()) {
|
||||||
apiImport.getMocks().clear();
|
apiImport.getMocks().clear();
|
||||||
}
|
}
|
||||||
|
List<ApiImportSendNoticeDTO> apiImportSendNoticeDTOS = new ArrayList<>();
|
||||||
for (int i = 0; i < data.size(); i++) {
|
for (int i = 0; i < data.size(); i++) {
|
||||||
ApiDefinitionWithBLOBs item = data.get(i);
|
ApiDefinitionWithBLOBs item = data.get(i);
|
||||||
List<ApiTestCaseWithBLOBs> caseList = apiIdCaseMap.get(item.getId());
|
List<ApiTestCaseWithBLOBs> caseList = apiIdCaseMap.get(item.getId());
|
||||||
|
@ -1753,18 +1800,26 @@ public class ApiDefinitionService {
|
||||||
item.setNum(num++);
|
item.setNum(num++);
|
||||||
}
|
}
|
||||||
//如果EsbData需要存储,则需要进行接口是否更新的判断
|
//如果EsbData需要存储,则需要进行接口是否更新的判断
|
||||||
|
ApiDefinitionImportParamDTO apiDefinitionImportParamDTO = new ApiDefinitionImportParamDTO(item, request, apiImport.getMocks(), updateList, caseList);
|
||||||
if (apiImport.getEsbApiParamsMap() != null) {
|
if (apiImport.getEsbApiParamsMap() != null) {
|
||||||
String apiId = item.getId();
|
String apiId = item.getId();
|
||||||
EsbApiParamsWithBLOBs model = apiImport.getEsbApiParamsMap().get(apiId);
|
EsbApiParamsWithBLOBs model = apiImport.getEsbApiParamsMap().get(apiId);
|
||||||
request.setModeId("fullCoverage");//标准版ESB数据导入不区分是否覆盖,默认都为覆盖
|
request.setModeId("fullCoverage");//标准版ESB数据导入不区分是否覆盖,默认都为覆盖
|
||||||
importCreate(item, batchMapper, extApiDefinitionMapper, request, apiImport.getMocks(), updateList, apiTestCaseMapper, caseList);
|
|
||||||
|
ApiImportSendNoticeDTO apiImportSendNoticeDTO = importCreate(batchMapper, extApiDefinitionMapper, apiTestCaseMapper, apiDefinitionImportParamDTO);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
apiImport.getEsbApiParamsMap().remove(apiId);
|
apiImport.getEsbApiParamsMap().remove(apiId);
|
||||||
model.setResourceId(item.getId());
|
model.setResourceId(item.getId());
|
||||||
apiImport.getEsbApiParamsMap().put(item.getId(), model);
|
apiImport.getEsbApiParamsMap().put(item.getId(), model);
|
||||||
}
|
}
|
||||||
|
if (apiImportSendNoticeDTO != null) {
|
||||||
|
apiImportSendNoticeDTOS.add(apiImportSendNoticeDTO);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
importCreate(item, batchMapper, extApiDefinitionMapper, request, apiImport.getMocks(), updateList, apiTestCaseMapper, caseList);
|
ApiImportSendNoticeDTO apiImportSendNoticeDTO = importCreate(batchMapper, extApiDefinitionMapper, apiTestCaseMapper, apiDefinitionImportParamDTO);
|
||||||
|
if (apiImportSendNoticeDTO != null) {
|
||||||
|
apiImportSendNoticeDTOS.add(apiImportSendNoticeDTO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (i % 300 == 0) {
|
if (i % 300 == 0) {
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
|
@ -1795,6 +1850,8 @@ public class ApiDefinitionService {
|
||||||
if (sqlSession != null && sqlSessionFactory != null) {
|
if (sqlSession != null && sqlSessionFactory != null) {
|
||||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return apiImportSendNoticeDTOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReferenceDTO getReference(ApiScenarioRequest request) {
|
public ReferenceDTO getReference(ApiScenarioRequest request) {
|
||||||
|
|
|
@ -1044,7 +1044,8 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap;
|
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap;
|
||||||
List<String> definitionIds = repeatApiDefinitionWithBLOBs.stream().map(ApiDefinition::getId).collect(Collectors.toList());
|
List<String> definitionIds = repeatApiDefinitionWithBLOBs.stream().map(ApiDefinition::getId).collect(Collectors.toList());
|
||||||
ApiTestCaseExample testCaseExample = new ApiTestCaseExample();
|
ApiTestCaseExample testCaseExample = new ApiTestCaseExample();
|
||||||
testCaseExample.createCriteria().andApiDefinitionIdIn(definitionIds).andStatusNotEqualTo("Trash");
|
testCaseExample.createCriteria().andApiDefinitionIdIn(definitionIds);
|
||||||
|
testCaseExample.or(testCaseExample.createCriteria().andStatusNotEqualTo(ScenarioStatus.Trash.name()).andStatusIsNull());
|
||||||
List<ApiTestCaseWithBLOBs> caseWithBLOBs = apiTestCaseMapper.selectByExampleWithBLOBs(testCaseExample);
|
List<ApiTestCaseWithBLOBs> caseWithBLOBs = apiTestCaseMapper.selectByExampleWithBLOBs(testCaseExample);
|
||||||
oldCaseMap = caseWithBLOBs.stream().collect(Collectors.groupingBy(ApiTestCase::getApiDefinitionId));
|
oldCaseMap = caseWithBLOBs.stream().collect(Collectors.groupingBy(ApiTestCase::getApiDefinitionId));
|
||||||
return oldCaseMap;
|
return oldCaseMap;
|
||||||
|
@ -1370,12 +1371,24 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
importCaseWithBLOBs.setCreateUserId(caseWithBLOBs.get(i).getCreateUserId());
|
importCaseWithBLOBs.setCreateUserId(caseWithBLOBs.get(i).getCreateUserId());
|
||||||
importCaseWithBLOBs.setUpdateUserId(caseWithBLOBs.get(i).getCreateUserId());
|
importCaseWithBLOBs.setUpdateUserId(caseWithBLOBs.get(i).getCreateUserId());
|
||||||
} else {
|
} else {
|
||||||
|
//同名的旧数据处理
|
||||||
caseWithBLOBs.get(i).setVersionId("old_case");
|
caseWithBLOBs.get(i).setVersionId("old_case");
|
||||||
optionDataCases.add(caseWithBLOBs.get(i));
|
optionDataCases.add(caseWithBLOBs.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldCaseNameMap.remove(name);
|
oldCaseNameMap.remove(name);
|
||||||
}
|
}
|
||||||
|
//不同名的旧数据处理
|
||||||
|
oldCaseNameMap.forEach((k, v) -> {
|
||||||
|
if (!StringUtils.equals(k, name)) {
|
||||||
|
if (CollectionUtils.isNotEmpty(v)) {
|
||||||
|
for (ApiTestCaseWithBLOBs apiTestCaseWithBLOBs : v) {
|
||||||
|
apiTestCaseWithBLOBs.setVersionId("old_case");
|
||||||
|
optionDataCases.add(apiTestCaseWithBLOBs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
//否则直接给新增用例赋值新的接口ID
|
//否则直接给新增用例赋值新的接口ID
|
||||||
|
|
|
@ -1307,12 +1307,16 @@ public class ApiTestCaseService {
|
||||||
request.setToBeUpdateTime(toBeUpdatedTime);
|
request.setToBeUpdateTime(toBeUpdatedTime);
|
||||||
request.setUpdateTime(toBeUpdatedTime);
|
request.setUpdateTime(toBeUpdatedTime);
|
||||||
}
|
}
|
||||||
|
if (request.isNoSearchStatus()) {
|
||||||
|
request.setStatusList(new ArrayList<>());
|
||||||
|
} else {
|
||||||
List<String> syncRuleCaseStatus = apiTestCaseSyncService.getSyncRuleCaseStatus(request.getProjectId());
|
List<String> syncRuleCaseStatus = apiTestCaseSyncService.getSyncRuleCaseStatus(request.getProjectId());
|
||||||
if (CollectionUtils.isEmpty(syncRuleCaseStatus)) {
|
if (CollectionUtils.isEmpty(syncRuleCaseStatus)) {
|
||||||
syncRuleCaseStatus = new ArrayList<>();
|
syncRuleCaseStatus = new ArrayList<>();
|
||||||
}
|
}
|
||||||
request.setStatusList(syncRuleCaseStatus);
|
request.setStatusList(syncRuleCaseStatus);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getCitedScenarioCount(String testId) {
|
public Integer getCitedScenarioCount(String testId) {
|
||||||
ApiScenarioReferenceIdExample apiScenarioReferenceIdExample = new ApiScenarioReferenceIdExample();
|
ApiScenarioReferenceIdExample apiScenarioReferenceIdExample = new ApiScenarioReferenceIdExample();
|
||||||
|
|
|
@ -77,10 +77,16 @@ public abstract class AbstractNoticeSender implements NoticeSender {
|
||||||
JSONArray array = JSON.parseArray(specialReceivers);
|
JSONArray array = JSON.parseArray(specialReceivers);
|
||||||
if (CollectionUtils.isNotEmpty(array)) {
|
if (CollectionUtils.isNotEmpty(array)) {
|
||||||
for (Object o : array) {
|
for (Object o : array) {
|
||||||
|
List<Receiver> receivers = noticeModel.getReceivers();
|
||||||
|
if (CollectionUtils.isNotEmpty(receivers)) {
|
||||||
|
List<Receiver> collect = receivers.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getType(), NotificationConstants.Type.MENTIONED_ME.name()) && StringUtils.equalsIgnoreCase(t.getUserId(), o.toString())).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isEmpty(collect)) {
|
||||||
noticeModel.getReceivers().add(new Receiver(o.toString(), NotificationConstants.Type.MENTIONED_ME.name()));
|
noticeModel.getReceivers().add(new Receiver(o.toString(), NotificationConstants.Type.MENTIONED_ME.name()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 如果配置了模版就直接使用模版
|
// 如果配置了模版就直接使用模版
|
||||||
if (StringUtils.isNotBlank(messageDetail.getTemplate())) {
|
if (StringUtils.isNotBlank(messageDetail.getTemplate())) {
|
||||||
|
|
Loading…
Reference in New Issue