From 2133419ca0229412bc473f430d01d22aa157f161 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 6 Jan 2023 17:44:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E8=B5=8B=E5=80=BC=E7=89=88=E6=9C=AC=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=97=B6Mock=E6=95=B0=E6=8D=AE=E5=A4=8D=E5=88=B6=E9=94=99?= =?UTF-8?q?=E8=AF=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1021663 --user=宋天阳 【接口测试】接口定义-左上角筛选版本为v1.8,批量复制版本数据v1.0到v1.8版本后Mock错误 https://www.tapd.cn/55049933/s/1323686 --- .../service/MockConfigService.java | 9 ++- .../definition/ApiDefinitionService.java | 60 +++++++++++-------- .../components/version/VersionSelector.vue | 12 ++-- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java index dad301ab62..2992ed0124 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java @@ -187,6 +187,13 @@ public class MockConfigService { } } + public void sendMockNotice(String mockExpectId, String defaultContext, String event) { + MockExpectConfigWithBLOBs mockExpectConfigWithBLOBs = mockExpectConfigMapper.selectByPrimaryKey(mockExpectId); + if (mockExpectConfigWithBLOBs != null) { + this.sendMockNotice(mockExpectConfigWithBLOBs, defaultContext, event); + } + } + private void getParamMap(Map paramMap, String userId, MockExpectConfigWithBLOBs mockExpectConfigWithBLOBs, MockConfig mockConfig) { paramMap.put("operator", userId); paramMap.put("id", mockExpectConfigWithBLOBs.getId()); @@ -213,7 +220,7 @@ public class MockConfigService { model.setUpdateTime(timestamp); model.setStatus(request.getStatus()); mockExpectConfigMapper.updateByPrimaryKeySelective(model); - sendMockNotice(model, "更新了mock", NoticeConstants.Event.MOCK_UPDATE); + sendMockNotice(request.getId(), "更新了mock", NoticeConstants.Event.MOCK_UPDATE); return model; } else { return null; diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index 26c3077c1f..f6a050eb6b 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -1463,7 +1463,15 @@ public class ApiDefinitionService { } public List preparedUrl(String projectId, String method, String baseUrlSuffix, String mockApiResourceId) { - if (StringUtils.isEmpty(baseUrlSuffix)) { + if (StringUtils.isNotBlank(mockApiResourceId)) { + //如果请求头中指定了API 则返回当前API + List returnList = new ArrayList<>(); + ApiDefinitionWithBLOBs apiDefinition = apiDefinitionMapper.selectByPrimaryKey(mockApiResourceId); + if (apiDefinition != null) { + returnList.add(apiDefinition); + } + return returnList; + } else if (StringUtils.isEmpty(baseUrlSuffix)) { return new ArrayList<>(); } else { String apiId = this.getApiIdFromMockApiResourceId(mockApiResourceId, projectId); @@ -2206,70 +2214,70 @@ public class ApiDefinitionService { long timeStamp = System.currentTimeMillis(); MockConfigExample mockConfigExample = new MockConfigExample(); mockConfigExample.createCriteria().andApiIdIn(new ArrayList<>(sourceApiIdRefIdMap.keySet())); - List mockConfigList = mockConfigMapper.selectByExample(mockConfigExample); - if (CollectionUtils.isNotEmpty(mockConfigList)) { - List mockIdList = mockConfigList.stream().map(MockConfig::getId).collect(Collectors.toList()); + List sourceMockConfigList = mockConfigMapper.selectByExample(mockConfigExample); + if (CollectionUtils.isNotEmpty(sourceMockConfigList)) { + List sourceMockConfigIdList = sourceMockConfigList.stream().map(MockConfig::getId).collect(Collectors.toList()); MockExpectConfigExample mockExpectConfigExample = new MockExpectConfigExample(); - mockExpectConfigExample.createCriteria().andMockConfigIdIn(mockIdList); + mockExpectConfigExample.createCriteria().andMockConfigIdIn(sourceMockConfigIdList); List mockExpectConfigWithBLOBsList = mockExpectConfigMapper.selectByExampleWithBLOBs(mockExpectConfigExample); - Map> mockConfigIdExpectMap = mockExpectConfigWithBLOBsList.stream().collect(Collectors.groupingBy(MockExpectConfigWithBLOBs::getMockConfigId)); + Map> sourceMockConfigIdMap = mockExpectConfigWithBLOBsList.stream().collect(Collectors.groupingBy(MockExpectConfigWithBLOBs::getMockConfigId)); List saveMockList = new ArrayList<>(); List saveMockExpectList = new ArrayList<>(); List updateMockExpectList = new ArrayList<>(); - mockConfigList.forEach(item -> { - String oldApiId = item.getApiId(); - String refId = sourceApiIdRefIdMap.get(oldApiId); + sourceMockConfigList.forEach(item -> { + String sourceApiId = item.getApiId(); + String refId = sourceApiIdRefIdMap.get(sourceApiId); if (StringUtils.isNotBlank(refId)) { - ApiDefinition api = refIdMap.get(refId); - if (api != null) { - MockConfig baseMockConfig = mockConfigService.selectMockConfigByApiId(api.getId()); - String mockConfigId = UUID.randomUUID().toString(); + ApiDefinition goalApi = refIdMap.get(refId); + if (goalApi != null) { + MockConfig goalApiMockConfig = mockConfigService.selectMockConfigByApiId(goalApi.getId()); + String goalApiMockConfigId = UUID.randomUUID().toString(); Map oldMockExpectConfig = new HashMap<>(); //已经存储的mock期望编号 List saveExpectNumList = new ArrayList<>(); - if (baseMockConfig == null) { + if (goalApiMockConfig == null) { MockConfig mockConfig = new MockConfig(); BeanUtils.copyBean(mockConfig, item); - mockConfig.setApiId(api.getId()); - mockConfig.setId(mockConfigId); + mockConfig.setApiId(goalApi.getId()); + mockConfig.setId(goalApiMockConfigId); mockConfig.setCreateTime(timeStamp); mockConfig.setUpdateTime(timeStamp); saveMockList.add(mockConfig); } else { - mockConfigId = baseMockConfig.getId(); - saveExpectNumList = mockConfigService.selectExpectNumberByConfigId(mockConfigId); - List oldMockExpectList = mockConfigService.selectSimpleMockExpectConfigByMockConfigId(mockConfigId); - oldMockExpectList.forEach(mockExpectConfig -> { + goalApiMockConfigId = goalApiMockConfig.getId(); + saveExpectNumList = mockConfigService.selectExpectNumberByConfigId(goalApiMockConfigId); + List goalMockExpectList = mockConfigService.selectSimpleMockExpectConfigByMockConfigId(goalApiMockConfigId); + goalMockExpectList.forEach(mockExpectConfig -> { oldMockExpectConfig.put(StringUtils.trim(mockExpectConfig.getName()), mockExpectConfig); }); } - List mockExpectConfigList = mockConfigIdExpectMap.get(item.getId()); + List mockExpectConfigList = sourceMockConfigIdMap.get(item.getId()); if (CollectionUtils.isNotEmpty(mockExpectConfigList)) { - String finalMockConfigId = mockConfigId; + String finalMockConfigId = goalApiMockConfigId; List finalSaveExpectNumList = saveExpectNumList; mockExpectConfigList.forEach(mockExpectConfigWithBLOBs -> { MockExpectConfig oldExpect = oldMockExpectConfig.get(StringUtils.trim(mockExpectConfigWithBLOBs.getName())); MockExpectConfigWithBLOBs expectConfigWithBLOBs = new MockExpectConfigWithBLOBs(); BeanUtils.copyBean(expectConfigWithBLOBs, mockExpectConfigWithBLOBs); + expectConfigWithBLOBs.setMockConfigId(finalMockConfigId); + expectConfigWithBLOBs.setUpdateTime(timeStamp); if (oldExpect == null) { - String newMockExpectNum = mockConfigService.getMockExpectId(String.valueOf(api.getNum()), finalSaveExpectNumList); + String newMockExpectNum = mockConfigService.getMockExpectId(String.valueOf(goalApi.getNum()), finalSaveExpectNumList); finalSaveExpectNumList.add(newMockExpectNum); expectConfigWithBLOBs.setId(UUID.randomUUID().toString()); expectConfigWithBLOBs.setExpectNum(newMockExpectNum); expectConfigWithBLOBs.setCreateTime(timeStamp); - expectConfigWithBLOBs.setUpdateTime(timeStamp); - expectConfigWithBLOBs.setMockConfigId(finalMockConfigId); + saveMockExpectList.add(expectConfigWithBLOBs); } else { expectConfigWithBLOBs.setId(oldExpect.getId()); expectConfigWithBLOBs.setCreateTime(oldExpect.getCreateTime()); - expectConfigWithBLOBs.setUpdateTime(timeStamp); updateMockExpectList.add(expectConfigWithBLOBs); } }); diff --git a/api-test/frontend/src/business/definition/components/version/VersionSelector.vue b/api-test/frontend/src/business/definition/components/version/VersionSelector.vue index de6b2f257d..8a8f83a963 100644 --- a/api-test/frontend/src/business/definition/components/version/VersionSelector.vue +++ b/api-test/frontend/src/business/definition/components/version/VersionSelector.vue @@ -1,7 +1,7 @@