fix(接口导入): 修复接口导入选择覆盖时未覆盖mock期望的bug
修复接口导入选择覆盖时未覆盖mock期望的bug
This commit is contained in:
parent
a1df5c2e80
commit
4e9b9fed85
|
@ -719,6 +719,9 @@ public class ApiDefinitionService {
|
||||||
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||||
apiDefinition.setRequest(requestStr);
|
apiDefinition.setRequest(requestStr);
|
||||||
importApiCase(apiDefinition, apiTestImportRequest);
|
importApiCase(apiDefinition, apiTestImportRequest);
|
||||||
|
}else {
|
||||||
|
//不覆盖的接口,如果没有sameRequest则不导入。此时清空mock信息
|
||||||
|
mocks.clear();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, apiTestImportRequest, cases, mocks);
|
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, apiTestImportRequest, cases, mocks);
|
||||||
|
@ -811,6 +814,7 @@ public class ApiDefinitionService {
|
||||||
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
||||||
apiDefinition.setRequest(request);
|
apiDefinition.setRequest(request);
|
||||||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||||
|
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||||
importApiCase(apiDefinition, apiTestImportRequest);
|
importApiCase(apiDefinition, apiTestImportRequest);
|
||||||
} else {
|
} else {
|
||||||
apiDefinition.setId(existApi.getId());
|
apiDefinition.setId(existApi.getId());
|
||||||
|
@ -819,6 +823,7 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
apiDefinition.setOrder(existApi.getOrder());
|
apiDefinition.setOrder(existApi.getOrder());
|
||||||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||||
|
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||||
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1381,7 +1381,7 @@ public class MockConfigService {
|
||||||
if (CollectionUtils.isNotEmpty(apiImport.getMocks())) {
|
if (CollectionUtils.isNotEmpty(apiImport.getMocks())) {
|
||||||
Map<String, List<MockExpectConfigWithBLOBs>> saveMap = new HashMap<>();
|
Map<String, List<MockExpectConfigWithBLOBs>> saveMap = new HashMap<>();
|
||||||
for (MockConfigImportDTO dto : apiImport.getMocks()) {
|
for (MockConfigImportDTO dto : apiImport.getMocks()) {
|
||||||
String apiId = dto.getApiId();//de33108c-26e2-4d4f-826a-a5f8e017d2f4
|
String apiId = dto.getApiId();
|
||||||
if (saveMap.containsKey(apiId)) {
|
if (saveMap.containsKey(apiId)) {
|
||||||
saveMap.get(apiId).add(dto);
|
saveMap.get(apiId).add(dto);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1393,37 +1393,91 @@ public class MockConfigService {
|
||||||
|
|
||||||
for (Map.Entry<String, List<MockExpectConfigWithBLOBs>> entry : saveMap.entrySet()) {
|
for (Map.Entry<String, List<MockExpectConfigWithBLOBs>> entry : saveMap.entrySet()) {
|
||||||
String apiId = entry.getKey();
|
String apiId = entry.getKey();
|
||||||
this.deleteMockConfigByApiId(apiId);
|
|
||||||
|
|
||||||
List<MockExpectConfigWithBLOBs> list = entry.getValue();
|
List<MockExpectConfigWithBLOBs> list = entry.getValue();
|
||||||
|
|
||||||
String mockId = UUID.randomUUID().toString();
|
MockConfig mockConfig = this.selectMockConfigByApiId(apiId);
|
||||||
MockConfig config = new MockConfig();
|
if (mockConfig == null) {
|
||||||
config.setProjectId(request.getProjectId());
|
this.insertMockExpectConfigs(apiId, request.getProjectId(), list, sqlSession);
|
||||||
config.setId(mockId);
|
} else {
|
||||||
config.setCreateUserId(SessionUtils.getUserId());
|
this.updateMockExpectConfigs(mockConfig, list ,sqlSession);
|
||||||
config.setCreateTime(System.currentTimeMillis());
|
|
||||||
config.setUpdateTime(System.currentTimeMillis());
|
|
||||||
config.setApiId(apiId);
|
|
||||||
mockConfigMapper.insert(config);
|
|
||||||
|
|
||||||
int batchCount = 0;
|
|
||||||
for (MockExpectConfigWithBLOBs mockExpect : list) {
|
|
||||||
mockExpect.setId(UUID.randomUUID().toString());
|
|
||||||
mockExpect.setMockConfigId(mockId);
|
|
||||||
mockExpect.setCreateTime(System.currentTimeMillis());
|
|
||||||
mockExpect.setUpdateTime(System.currentTimeMillis());
|
|
||||||
mockExpect.setCreateUserId(SessionUtils.getUserId());
|
|
||||||
mockExpectConfigMapper.insert(mockExpect);
|
|
||||||
}
|
|
||||||
if (batchCount % 300 == 0) {
|
|
||||||
sqlSession.flushStatements();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateMockExpectConfigs(MockConfig mockConfig, List<MockExpectConfigWithBLOBs> list, SqlSession sqlSession) {
|
||||||
|
int batchCount = 0;
|
||||||
|
for (MockExpectConfigWithBLOBs mockExpect : list) {
|
||||||
|
MockExpectConfig expectInDb = this.findMockExpectConfigByMockConfigIdAndExpectNum(mockConfig.getId(),mockExpect.getExpectNum());
|
||||||
|
if(expectInDb == null){
|
||||||
|
mockExpect.setId(UUID.randomUUID().toString());
|
||||||
|
mockExpect.setMockConfigId(mockConfig.getId());
|
||||||
|
mockExpect.setCreateTime(System.currentTimeMillis());
|
||||||
|
mockExpect.setUpdateTime(System.currentTimeMillis());
|
||||||
|
mockExpect.setCreateUserId(SessionUtils.getUserId());
|
||||||
|
mockExpectConfigMapper.insert(mockExpect);
|
||||||
|
}else {
|
||||||
|
mockExpect.setMockConfigId(mockConfig.getId());
|
||||||
|
mockExpect.setId(expectInDb.getId());
|
||||||
|
mockExpect.setUpdateTime(System.currentTimeMillis());
|
||||||
|
mockExpectConfigMapper.updateByPrimaryKey(mockExpect);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (batchCount % 300 == 0) {
|
||||||
|
sqlSession.flushStatements();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MockExpectConfig findMockExpectConfigByMockConfigIdAndExpectNum(String mockConfigId, String expectNum) {
|
||||||
|
MockExpectConfigExample example = new MockExpectConfigExample();
|
||||||
|
example.createCriteria().andMockConfigIdEqualTo(mockConfigId).andExpectNumEqualTo(expectNum);
|
||||||
|
List<MockExpectConfig> bloBs = this.mockExpectConfigMapper.selectByExample(example);
|
||||||
|
if(CollectionUtils.isNotEmpty(bloBs)){
|
||||||
|
return bloBs.get(0);
|
||||||
|
}else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void insertMockExpectConfigs(String apiId, String projectId, List<MockExpectConfigWithBLOBs> list, SqlSession sqlSession) {
|
||||||
|
String mockId = UUID.randomUUID().toString();
|
||||||
|
MockConfig config = new MockConfig();
|
||||||
|
config.setProjectId(projectId);
|
||||||
|
config.setId(mockId);
|
||||||
|
config.setCreateUserId(SessionUtils.getUserId());
|
||||||
|
config.setCreateTime(System.currentTimeMillis());
|
||||||
|
config.setUpdateTime(System.currentTimeMillis());
|
||||||
|
config.setApiId(apiId);
|
||||||
|
mockConfigMapper.insert(config);
|
||||||
|
|
||||||
|
int batchCount = 0;
|
||||||
|
for (MockExpectConfigWithBLOBs mockExpect : list) {
|
||||||
|
mockExpect.setId(UUID.randomUUID().toString());
|
||||||
|
mockExpect.setMockConfigId(mockId);
|
||||||
|
mockExpect.setCreateTime(System.currentTimeMillis());
|
||||||
|
mockExpect.setUpdateTime(System.currentTimeMillis());
|
||||||
|
mockExpect.setCreateUserId(SessionUtils.getUserId());
|
||||||
|
mockExpectConfigMapper.insert(mockExpect);
|
||||||
|
}
|
||||||
|
if (batchCount % 300 == 0) {
|
||||||
|
sqlSession.flushStatements();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private MockConfig selectMockConfigByApiId(String apiId) {
|
||||||
|
MockConfigExample example = new MockConfigExample();
|
||||||
|
example.createCriteria().andApiIdEqualTo(apiId);
|
||||||
|
List<MockConfig> mockConfigList = this.mockConfigMapper.selectByExample(example);
|
||||||
|
if (CollectionUtils.isNotEmpty(mockConfigList)) {
|
||||||
|
return mockConfigList.get(0);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void updateMockReturnMsgByApi(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs) {
|
public void updateMockReturnMsgByApi(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs) {
|
||||||
if (apiDefinitionWithBLOBs == null) {
|
if (apiDefinitionWithBLOBs == null) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue