From 71f9fa01262a1f716ea1b5692645ed90b6be4e72 Mon Sep 17 00:00:00 2001 From: yangzl Date: Mon, 7 Oct 2024 22:21:55 +0800 Subject: [PATCH 1/8] feat: openapi query namespace support not fill item --- .../ServerNamespaceOpenApiService.java | 8 ++++---- .../v1/controller/NamespaceController.java | 12 ++++++----- .../controller/ConfigsExportController.java | 2 +- .../portal/service/ConfigsExportService.java | 2 +- .../portal/service/NamespaceService.java | 20 +++++++++++-------- .../service/ConfigsExportServiceTest.java | 8 ++++---- .../portal/service/NamespaceServiceTest.java | 2 +- pom.xml | 4 ++-- 8 files changed, 32 insertions(+), 26 deletions(-) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java index cc2cf13f829..5ae1ebbdf6f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java @@ -58,9 +58,9 @@ public ServerNamespaceOpenApiService( @Override public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, - String namespaceName) { + String namespaceName, boolean fillItemDetail) { NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf - (env), clusterName, namespaceName, false); + (env), clusterName, namespaceName, fillItemDetail, false); if (namespaceBO == null) { return null; } @@ -68,10 +68,10 @@ public OpenNamespaceDTO getNamespace(String appId, String env, String clusterNam } @Override - public List getNamespaces(String appId, String env, String clusterName) { + public List getNamespaces(String appId, String env, String clusterName, boolean fillItemDetail) { return OpenApiBeanUtils .batchTransformFromNamespaceBOs(namespaceService.findNamespaceBOs(appId, Env - .valueOf(env), clusterName, false)); + .valueOf(env), clusterName, fillItemDetail, false)); } @Override diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java index bbe3ba8e422..69e88fb4cb9 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java @@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; @@ -81,15 +82,16 @@ public OpenAppNamespaceDTO createNamespace(@PathVariable String appId, @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces") public List findNamespaces(@PathVariable String appId, @PathVariable String env, - @PathVariable String clusterName) { - return this.namespaceOpenApiService.getNamespaces(appId, env, clusterName); + @PathVariable String clusterName, + @RequestParam(defaultValue="true") boolean fillItemDetail) { + return this.namespaceOpenApiService.getNamespaces(appId, env, clusterName, fillItemDetail); } @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}") public OpenNamespaceDTO loadNamespace(@PathVariable String appId, @PathVariable String env, - @PathVariable String clusterName, @PathVariable String - namespaceName) { - return this.namespaceOpenApiService.getNamespace(appId, env, clusterName, namespaceName); + @PathVariable String clusterName, @PathVariable String namespaceName, + @RequestParam(defaultValue="true") boolean fillItemDetail) { + return this.namespaceOpenApiService.getNamespace(appId, env, clusterName, namespaceName, fillItemDetail); } @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock") diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java index 1d3c7d79c2d..fc6ae086f4d 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java @@ -93,7 +93,7 @@ public void exportItems(@PathVariable String appId, @PathVariable String env, } NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf - (env), clusterName, namespaceName, false); + (env), clusterName, namespaceName, true, false); //generate a file. res.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + fileName); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java index aa524105169..1dc32fd4586 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java @@ -235,7 +235,7 @@ private void exportNamespaces(final Env env, final App exportApp, final ClusterD ZipOutputStream zipOutputStream) { String clusterName = exportCluster.getName(); - List namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName, false); + List namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName, true, false); if (CollectionUtils.isEmpty(namespaceBOS)) { return; diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java index 183a58b891e..3d3e56c0a3a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java @@ -186,7 +186,7 @@ public NamespaceDTO loadNamespaceBaseInfo(String appId, Env env, String clusterN /** * load cluster all namespace info with items */ - public List findNamespaceBOs(String appId, Env env, String clusterName, boolean includeDeletedItems) { + public List findNamespaceBOs(String appId, Env env, String clusterName, boolean fillItemDetail, boolean includeDeletedItems) { List namespaces = namespaceAPI.findNamespaceByCluster(appId, env, clusterName); if (namespaces == null || namespaces.size() == 0) { @@ -200,7 +200,7 @@ public List findNamespaceBOs(String appId, Env env, String clusterN executorService.submit(() -> { NamespaceBO namespaceBO; try { - namespaceBO = transformNamespace2BO(env, namespace, includeDeletedItems); + namespaceBO = transformNamespace2BO(env, namespace, fillItemDetail, includeDeletedItems); namespaceBOs.add(namespaceBO); } catch (Exception e) { LOGGER.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}", @@ -229,7 +229,7 @@ public List findNamespaceBOs(String appId, Env env, String clusterN } public List findNamespaceBOs(String appId, Env env, String clusterName) { - return findNamespaceBOs(appId, env, clusterName, true); + return findNamespaceBOs(appId, env, clusterName, true, true); } public List findNamespaces(String appId, Env env, String clusterName) { @@ -250,17 +250,17 @@ public List getPublicAppNamespaceAllNamespaces(Env env, String pub } public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName, - String namespaceName, boolean includeDeletedItems) { + String namespaceName, boolean fillItemDetail, boolean includeDeletedItems) { NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName); if (namespace == null) { throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName); } - return transformNamespace2BO(env, namespace, includeDeletedItems); + return transformNamespace2BO(env, namespace, fillItemDetail, includeDeletedItems); } public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName, String namespaceName) { - return loadNamespaceBO(appId, env, clusterName, namespaceName, true); + return loadNamespaceBO(appId, env, clusterName, namespaceName, true, true); } public boolean publicAppNamespaceHasAssociatedNamespace(String publicNamespaceName, Env env) { @@ -293,7 +293,7 @@ public Map> getNamespacesPublishInfo(String appId) return result; } - private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boolean includeDeletedItems) { + private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boolean fillItemDetail, boolean includeDeletedItems) { NamespaceBO namespaceBO = new NamespaceBO(); namespaceBO.setBaseInfo(namespace); @@ -306,6 +306,10 @@ private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boole List itemBOs = new LinkedList<>(); namespaceBO.setItems(itemBOs); + if (!fillItemDetail) { + return namespaceBO; + } + //latest Release ReleaseDTO latestRelease; Map releaseItems = new HashMap<>(); @@ -347,7 +351,7 @@ private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boole } private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace) { - return transformNamespace2BO(env, namespace, true); + return transformNamespace2BO(env, namespace, true, true); } private void fillAppNamespaceProperties(NamespaceBO namespace) { diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java index 05391706e3f..c7b0ba3f874 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java @@ -146,10 +146,10 @@ public void testNamespaceExportImport() throws FileNotFoundException { when(permissionValidator.isAppAdmin(any())).thenReturn(true); when(clusterService.findClusters(env, appId1)).thenReturn(app1Clusters); when(clusterService.findClusters(env, appId2)).thenReturn(app2Clusters); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, false)).thenReturn(app1Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, false)).thenReturn(app1Cluster2Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, false)).thenReturn(app2Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, false)).thenReturn(app2Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, true, false)).thenReturn(app1Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, true, false)).thenReturn(app1Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, true, false)).thenReturn(app2Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, true, false)).thenReturn(app2Cluster2Namespace); FileOutputStream fileOutputStream = new FileOutputStream(filePath); diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java index 8efecccb82e..7f14639223a 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java @@ -265,7 +265,7 @@ public void testLoadNamespaceBO() { assertThat(namespaceBO1.getItems().size()).isEqualTo(3); assertThat(namespaceKey1).isEqualTo(Arrays.asList("k1", "k2", "k3")); - NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, false); + NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true, false); List namespaceKey2 = namespaceBO2.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList()); assertThat(namespaceBO2.getItemModifiedCnt()).isEqualTo(2); assertThat(namespaceBO2.getItems().size()).isEqualTo(2); diff --git a/pom.xml b/pom.xml index 465a1c01343..31929d5d2bc 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ 2.4.0-SNAPSHOT 1.8 UTF-8 - 2.2.0 + 2.4.0-SNAPSHOT 2.7.11 2021.0.5 @@ -649,4 +649,4 @@ - \ No newline at end of file + From 01defd278387f6dc66dbe507d85f94d9d15fd6ce Mon Sep 17 00:00:00 2001 From: yangzl Date: Mon, 21 Oct 2024 23:02:36 +0800 Subject: [PATCH 2/8] =?UTF-8?q?fix=EF=BC=9Aadd=20unit=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConfigsExportServiceTest.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java index c7b0ba3f874..381441f13a6 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java @@ -83,6 +83,18 @@ public class ConfigsExportServiceTest extends AbstractUnitTest { @Test public void testNamespaceExportImport() throws FileNotFoundException { + // Test with fillItemDetail = true + testExportImportScenario(true); + } + + @Test + public void testNamespaceExportImportWithFillItemDetail() throws FileNotFoundException { + // Test with fillItemDetail = false + testExportImportScenario(false); + } + + private void testExportImportScenario(boolean fillItemDetail) throws FileNotFoundException { + File temporaryFolder = Files.newTemporaryFolder(); temporaryFolder.deleteOnExit(); String filePath = temporaryFolder + File.separator + "export.zip"; @@ -146,10 +158,10 @@ public void testNamespaceExportImport() throws FileNotFoundException { when(permissionValidator.isAppAdmin(any())).thenReturn(true); when(clusterService.findClusters(env, appId1)).thenReturn(app1Clusters); when(clusterService.findClusters(env, appId2)).thenReturn(app2Clusters); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, true, false)).thenReturn(app1Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, true, false)).thenReturn(app1Cluster2Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, true, false)).thenReturn(app2Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, true, false)).thenReturn(app2Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, fillItemDetail, false)).thenReturn(app1Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, fillItemDetail, false)).thenReturn(app1Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, fillItemDetail, false)).thenReturn(app2Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, fillItemDetail, false)).thenReturn(app2Cluster2Namespace); FileOutputStream fileOutputStream = new FileOutputStream(filePath); From 0f33867b93e1580c4156a6f877dc2ea7f1302777 Mon Sep 17 00:00:00 2001 From: yangzl Date: Mon, 7 Oct 2024 22:21:55 +0800 Subject: [PATCH 3/8] feat: openapi query namespace support not fill item --- .../ServerNamespaceOpenApiService.java | 8 ++++---- .../v1/controller/NamespaceController.java | 12 ++++++----- .../controller/ConfigsExportController.java | 2 +- .../portal/service/ConfigsExportService.java | 2 +- .../portal/service/NamespaceService.java | 20 +++++++++++-------- .../service/ConfigsExportServiceTest.java | 8 ++++---- .../portal/service/NamespaceServiceTest.java | 2 +- pom.xml | 4 ++-- 8 files changed, 32 insertions(+), 26 deletions(-) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java index cc2cf13f829..5ae1ebbdf6f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java @@ -58,9 +58,9 @@ public ServerNamespaceOpenApiService( @Override public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, - String namespaceName) { + String namespaceName, boolean fillItemDetail) { NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf - (env), clusterName, namespaceName, false); + (env), clusterName, namespaceName, fillItemDetail, false); if (namespaceBO == null) { return null; } @@ -68,10 +68,10 @@ public OpenNamespaceDTO getNamespace(String appId, String env, String clusterNam } @Override - public List getNamespaces(String appId, String env, String clusterName) { + public List getNamespaces(String appId, String env, String clusterName, boolean fillItemDetail) { return OpenApiBeanUtils .batchTransformFromNamespaceBOs(namespaceService.findNamespaceBOs(appId, Env - .valueOf(env), clusterName, false)); + .valueOf(env), clusterName, fillItemDetail, false)); } @Override diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java index bbe3ba8e422..69e88fb4cb9 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java @@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; @@ -81,15 +82,16 @@ public OpenAppNamespaceDTO createNamespace(@PathVariable String appId, @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces") public List findNamespaces(@PathVariable String appId, @PathVariable String env, - @PathVariable String clusterName) { - return this.namespaceOpenApiService.getNamespaces(appId, env, clusterName); + @PathVariable String clusterName, + @RequestParam(defaultValue="true") boolean fillItemDetail) { + return this.namespaceOpenApiService.getNamespaces(appId, env, clusterName, fillItemDetail); } @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}") public OpenNamespaceDTO loadNamespace(@PathVariable String appId, @PathVariable String env, - @PathVariable String clusterName, @PathVariable String - namespaceName) { - return this.namespaceOpenApiService.getNamespace(appId, env, clusterName, namespaceName); + @PathVariable String clusterName, @PathVariable String namespaceName, + @RequestParam(defaultValue="true") boolean fillItemDetail) { + return this.namespaceOpenApiService.getNamespace(appId, env, clusterName, namespaceName, fillItemDetail); } @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock") diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java index 1d3c7d79c2d..fc6ae086f4d 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java @@ -93,7 +93,7 @@ public void exportItems(@PathVariable String appId, @PathVariable String env, } NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf - (env), clusterName, namespaceName, false); + (env), clusterName, namespaceName, true, false); //generate a file. res.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + fileName); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java index aa524105169..1dc32fd4586 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java @@ -235,7 +235,7 @@ private void exportNamespaces(final Env env, final App exportApp, final ClusterD ZipOutputStream zipOutputStream) { String clusterName = exportCluster.getName(); - List namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName, false); + List namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName, true, false); if (CollectionUtils.isEmpty(namespaceBOS)) { return; diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java index 183a58b891e..3d3e56c0a3a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java @@ -186,7 +186,7 @@ public NamespaceDTO loadNamespaceBaseInfo(String appId, Env env, String clusterN /** * load cluster all namespace info with items */ - public List findNamespaceBOs(String appId, Env env, String clusterName, boolean includeDeletedItems) { + public List findNamespaceBOs(String appId, Env env, String clusterName, boolean fillItemDetail, boolean includeDeletedItems) { List namespaces = namespaceAPI.findNamespaceByCluster(appId, env, clusterName); if (namespaces == null || namespaces.size() == 0) { @@ -200,7 +200,7 @@ public List findNamespaceBOs(String appId, Env env, String clusterN executorService.submit(() -> { NamespaceBO namespaceBO; try { - namespaceBO = transformNamespace2BO(env, namespace, includeDeletedItems); + namespaceBO = transformNamespace2BO(env, namespace, fillItemDetail, includeDeletedItems); namespaceBOs.add(namespaceBO); } catch (Exception e) { LOGGER.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}", @@ -229,7 +229,7 @@ public List findNamespaceBOs(String appId, Env env, String clusterN } public List findNamespaceBOs(String appId, Env env, String clusterName) { - return findNamespaceBOs(appId, env, clusterName, true); + return findNamespaceBOs(appId, env, clusterName, true, true); } public List findNamespaces(String appId, Env env, String clusterName) { @@ -250,17 +250,17 @@ public List getPublicAppNamespaceAllNamespaces(Env env, String pub } public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName, - String namespaceName, boolean includeDeletedItems) { + String namespaceName, boolean fillItemDetail, boolean includeDeletedItems) { NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName); if (namespace == null) { throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName); } - return transformNamespace2BO(env, namespace, includeDeletedItems); + return transformNamespace2BO(env, namespace, fillItemDetail, includeDeletedItems); } public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName, String namespaceName) { - return loadNamespaceBO(appId, env, clusterName, namespaceName, true); + return loadNamespaceBO(appId, env, clusterName, namespaceName, true, true); } public boolean publicAppNamespaceHasAssociatedNamespace(String publicNamespaceName, Env env) { @@ -293,7 +293,7 @@ public Map> getNamespacesPublishInfo(String appId) return result; } - private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boolean includeDeletedItems) { + private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boolean fillItemDetail, boolean includeDeletedItems) { NamespaceBO namespaceBO = new NamespaceBO(); namespaceBO.setBaseInfo(namespace); @@ -306,6 +306,10 @@ private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boole List itemBOs = new LinkedList<>(); namespaceBO.setItems(itemBOs); + if (!fillItemDetail) { + return namespaceBO; + } + //latest Release ReleaseDTO latestRelease; Map releaseItems = new HashMap<>(); @@ -347,7 +351,7 @@ private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boole } private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace) { - return transformNamespace2BO(env, namespace, true); + return transformNamespace2BO(env, namespace, true, true); } private void fillAppNamespaceProperties(NamespaceBO namespace) { diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java index 05391706e3f..c7b0ba3f874 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java @@ -146,10 +146,10 @@ public void testNamespaceExportImport() throws FileNotFoundException { when(permissionValidator.isAppAdmin(any())).thenReturn(true); when(clusterService.findClusters(env, appId1)).thenReturn(app1Clusters); when(clusterService.findClusters(env, appId2)).thenReturn(app2Clusters); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, false)).thenReturn(app1Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, false)).thenReturn(app1Cluster2Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, false)).thenReturn(app2Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, false)).thenReturn(app2Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, true, false)).thenReturn(app1Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, true, false)).thenReturn(app1Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, true, false)).thenReturn(app2Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, true, false)).thenReturn(app2Cluster2Namespace); FileOutputStream fileOutputStream = new FileOutputStream(filePath); diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java index 8efecccb82e..7f14639223a 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java @@ -265,7 +265,7 @@ public void testLoadNamespaceBO() { assertThat(namespaceBO1.getItems().size()).isEqualTo(3); assertThat(namespaceKey1).isEqualTo(Arrays.asList("k1", "k2", "k3")); - NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, false); + NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true, false); List namespaceKey2 = namespaceBO2.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList()); assertThat(namespaceBO2.getItemModifiedCnt()).isEqualTo(2); assertThat(namespaceBO2.getItems().size()).isEqualTo(2); diff --git a/pom.xml b/pom.xml index 465a1c01343..31929d5d2bc 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ 2.4.0-SNAPSHOT 1.8 UTF-8 - 2.2.0 + 2.4.0-SNAPSHOT 2.7.11 2021.0.5 @@ -649,4 +649,4 @@ - \ No newline at end of file + From ad860c84ec2d1edb9f03061e49ffcd625d57742d Mon Sep 17 00:00:00 2001 From: yangzl Date: Mon, 21 Oct 2024 23:02:36 +0800 Subject: [PATCH 4/8] =?UTF-8?q?fix=EF=BC=9Aadd=20unit=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConfigsExportServiceTest.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java index c7b0ba3f874..381441f13a6 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java @@ -83,6 +83,18 @@ public class ConfigsExportServiceTest extends AbstractUnitTest { @Test public void testNamespaceExportImport() throws FileNotFoundException { + // Test with fillItemDetail = true + testExportImportScenario(true); + } + + @Test + public void testNamespaceExportImportWithFillItemDetail() throws FileNotFoundException { + // Test with fillItemDetail = false + testExportImportScenario(false); + } + + private void testExportImportScenario(boolean fillItemDetail) throws FileNotFoundException { + File temporaryFolder = Files.newTemporaryFolder(); temporaryFolder.deleteOnExit(); String filePath = temporaryFolder + File.separator + "export.zip"; @@ -146,10 +158,10 @@ public void testNamespaceExportImport() throws FileNotFoundException { when(permissionValidator.isAppAdmin(any())).thenReturn(true); when(clusterService.findClusters(env, appId1)).thenReturn(app1Clusters); when(clusterService.findClusters(env, appId2)).thenReturn(app2Clusters); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, true, false)).thenReturn(app1Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, true, false)).thenReturn(app1Cluster2Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, true, false)).thenReturn(app2Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, true, false)).thenReturn(app2Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, fillItemDetail, false)).thenReturn(app1Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, fillItemDetail, false)).thenReturn(app1Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, fillItemDetail, false)).thenReturn(app2Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, fillItemDetail, false)).thenReturn(app2Cluster2Namespace); FileOutputStream fileOutputStream = new FileOutputStream(filePath); From fce6ad13db5c85e431966ca2a6e8d22658da09ca Mon Sep 17 00:00:00 2001 From: yangzl Date: Sun, 27 Oct 2024 00:00:54 +0800 Subject: [PATCH 5/8] =?UTF-8?q?fix=EF=BC=9Aadd=20CHANGES.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 1 + .../portal/service/ConfigsExportServiceTest.java | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 81d5936d2bf..f24abbab8e6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Apollo 2.4.0 * [Feature add limit for items count per namespace](https://github.com/apolloconfig/apollo/pull/5227) * [Feature: Add ConfigService cache record stats function](https://github.com/apolloconfig/apollo/pull/5247) * [RefreshAdminServerAddressTask supports dynamic configuration of time interval](https://github.com/apolloconfig/apollo/pull/5248) +* [Feature: openapi query namespace support not fill item ](https://github.com/apolloconfig/apollo/pull/5249) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1) diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java index 381441f13a6..0dd544d6736 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java @@ -198,10 +198,12 @@ private void testExportImportScenario(boolean fillItemDetail) throws FileNotFoun verify(clusterService, times(4)).createCluster(any(), any()); - verify(namespaceService, times(6)).createNamespace(any(), any()); - verify(roleInitializationService,times(6)).initNamespaceRoles(any(), any(), anyString()); - verify(roleInitializationService,times(6)).initNamespaceEnvRoles(any(), any(), anyString()); - verify(itemService, times(12)).createItem(any(), any(), any(), any(), any()); + if(fillItemDetail){ + verify(namespaceService, times(6)).createNamespace(any(), any()); + verify(roleInitializationService,times(6)).initNamespaceRoles(any(), any(), anyString()); + verify(roleInitializationService,times(6)).initNamespaceEnvRoles(any(), any(), anyString()); + verify(itemService, times(12)).createItem(any(), any(), any(), any(), any()); + } } private App genApp(String name, String appId, String orgId, String orgName) { From 9a02b6f61505878a2d25c8226111379e00250ff3 Mon Sep 17 00:00:00 2001 From: yangzl Date: Sun, 27 Oct 2024 11:18:18 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix=EF=BC=9Aadd=20unit=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 2 +- .../portal/service/NamespaceServiceTest.java | 66 +++++++++++++++++-- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f24abbab8e6..d2c7f5cd21e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,7 +15,7 @@ Apollo 2.4.0 * [Feature add limit for items count per namespace](https://github.com/apolloconfig/apollo/pull/5227) * [Feature: Add ConfigService cache record stats function](https://github.com/apolloconfig/apollo/pull/5247) * [RefreshAdminServerAddressTask supports dynamic configuration of time interval](https://github.com/apolloconfig/apollo/pull/5248) -* [Feature: openapi query namespace support not fill item ](https://github.com/apolloconfig/apollo/pull/5249) +* [Feature: openapi query namespace support not fill item](https://github.com/apolloconfig/apollo/pull/5249) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1) diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java index 7f14639223a..1c8eb33ccd0 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java @@ -227,6 +227,24 @@ public void testDeleteEmptyNamespace() { @Test public void testLoadNamespaceBO() { + boolean fillItemDetail = true; + NamespaceBO namespaceBO = loadNamespaceBO(fillItemDetail); + + List namespaceKey2 = namespaceBO.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList()); + assertThat(namespaceBO.getItemModifiedCnt()).isEqualTo(2); + assertThat(namespaceBO.getItems().size()).isEqualTo(2); + assertThat(namespaceKey2).isEqualTo(Arrays.asList("k1", "k2")); + } + + @Test + public void testLoadNamespaceBOWithoutItemDetail() { + boolean fillItemDetail = false; + NamespaceBO namespaceBO = loadNamespaceBO(fillItemDetail); + + assertThat(namespaceBO.getItems().size()).isEqualTo(0); + } + + private NamespaceBO loadNamespaceBO(boolean fillItemDetail) { String branchName = "branch"; NamespaceDTO namespaceDTO = createNamespace(testAppId, branchName, testNamespaceName); when(namespaceAPI.loadNamespace(any(), any(), any(), any())).thenReturn(namespaceDTO); @@ -265,11 +283,49 @@ public void testLoadNamespaceBO() { assertThat(namespaceBO1.getItems().size()).isEqualTo(3); assertThat(namespaceKey1).isEqualTo(Arrays.asList("k1", "k2", "k3")); - NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true, false); - List namespaceKey2 = namespaceBO2.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList()); - assertThat(namespaceBO2.getItemModifiedCnt()).isEqualTo(2); - assertThat(namespaceBO2.getItems().size()).isEqualTo(2); - assertThat(namespaceKey2).isEqualTo(Arrays.asList("k1", "k2")); + return namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, fillItemDetail, false); + } + + @Test + public void testFindPublicNamespaceForAssociatedNamespace() { + String branchName = "branch"; + NamespaceDTO namespaceDTO = createNamespace(testAppId, branchName, testNamespaceName); + when(namespaceAPI.findPublicNamespaceForAssociatedNamespace(any(), any(), any(), any())).thenReturn(namespaceDTO); + + ReleaseDTO releaseDTO = new ReleaseDTO(); + releaseDTO.setConfigurations("{\"k1\":\"k1\",\"k2\":\"k2\", \"k3\":\"\"}"); + when(releaseService.loadLatestRelease(any(), any(), any(), any())).thenReturn(releaseDTO); + + List itemDTOList = Lists.newArrayList(); + ItemDTO itemDTO1 = new ItemDTO(); + itemDTO1.setId(1); + itemDTO1.setNamespaceId(1); + itemDTO1.setKey("k1"); + itemDTO1.setValue(String.valueOf(1)); + itemDTOList.add(itemDTO1); + + ItemDTO itemDTO2 = new ItemDTO(); + itemDTO2.setId(2); + itemDTO2.setNamespaceId(2); + itemDTO2.setKey("k2"); + itemDTO2.setValue(String.valueOf(2)); + itemDTOList.add(itemDTO2); + when(itemService.findItems(any(), any(), any(), any())).thenReturn(itemDTOList); + + List deletedItemDTOList = Lists.newArrayList(); + ItemDTO deletedItemDTO = new ItemDTO(); + deletedItemDTO.setId(3); + deletedItemDTO.setNamespaceId(3); + deletedItemDTO.setKey("k3"); + deletedItemDTOList.add(deletedItemDTO); + when(itemService.findDeletedItems(any(), any(), any(), any())).thenReturn(deletedItemDTOList); + + NamespaceBO namespaceBO = namespaceService.findPublicNamespaceForAssociatedNamespace(testEnv, testAppId, testClusterName, testNamespaceName); + + List namespaceKey2 = namespaceBO.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList()); + assertThat(namespaceBO.getItemModifiedCnt()).isEqualTo(3); + assertThat(namespaceBO.getItems().size()).isEqualTo(3); + assertThat(namespaceKey2).isEqualTo(Arrays.asList("k1", "k2", "k3")); } private AppNamespace createAppNamespace(String appId, String name, boolean isPublic) { From 9c3815944aad4a5d6b995459c7c5a9841303b715 Mon Sep 17 00:00:00 2001 From: yangzl Date: Sun, 27 Oct 2024 11:42:42 +0800 Subject: [PATCH 7/8] refactor: Refactor the test method --- .../portal/service/NamespaceServiceTest.java | 69 +++++++------------ 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java index 1c8eb33ccd0..458d3ced59f 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java @@ -245,37 +245,10 @@ public void testLoadNamespaceBOWithoutItemDetail() { } private NamespaceBO loadNamespaceBO(boolean fillItemDetail) { - String branchName = "branch"; - NamespaceDTO namespaceDTO = createNamespace(testAppId, branchName, testNamespaceName); - when(namespaceAPI.loadNamespace(any(), any(), any(), any())).thenReturn(namespaceDTO); - - ReleaseDTO releaseDTO = new ReleaseDTO(); - releaseDTO.setConfigurations("{\"k1\":\"k1\",\"k2\":\"k2\", \"k3\":\"\"}"); - when(releaseService.loadLatestRelease(any(), any(), any(), any())).thenReturn(releaseDTO); - - List itemDTOList = Lists.newArrayList(); - ItemDTO itemDTO1 = new ItemDTO(); - itemDTO1.setId(1); - itemDTO1.setNamespaceId(1); - itemDTO1.setKey("k1"); - itemDTO1.setValue(String.valueOf(1)); - itemDTOList.add(itemDTO1); - - ItemDTO itemDTO2 = new ItemDTO(); - itemDTO2.setId(2); - itemDTO2.setNamespaceId(2); - itemDTO2.setKey("k2"); - itemDTO2.setValue(String.valueOf(2)); - itemDTOList.add(itemDTO2); - when(itemService.findItems(any(), any(), any(), any())).thenReturn(itemDTOList); - - List deletedItemDTOList = Lists.newArrayList(); - ItemDTO deletedItemDTO = new ItemDTO(); - deletedItemDTO.setId(3); - deletedItemDTO.setNamespaceId(3); - deletedItemDTO.setKey("k3"); - deletedItemDTOList.add(deletedItemDTO); - when(itemService.findDeletedItems(any(), any(), any(), any())).thenReturn(deletedItemDTOList); + when(namespaceAPI.loadNamespace(any(), any(), any(), any())).thenReturn(createNamespace(testAppId, "branch", testNamespaceName)); + when(releaseService.loadLatestRelease(any(), any(), any(), any())).thenReturn(createReleaseDTO()); + when(itemService.findItems(any(), any(), any(), any())).thenReturn(createItems()); + when(itemService.findDeletedItems(any(), any(), any(), any())).thenReturn(createDeletedItems()); NamespaceBO namespaceBO1 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName); List namespaceKey1 = namespaceBO1.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList()); @@ -288,14 +261,26 @@ private NamespaceBO loadNamespaceBO(boolean fillItemDetail) { @Test public void testFindPublicNamespaceForAssociatedNamespace() { - String branchName = "branch"; - NamespaceDTO namespaceDTO = createNamespace(testAppId, branchName, testNamespaceName); - when(namespaceAPI.findPublicNamespaceForAssociatedNamespace(any(), any(), any(), any())).thenReturn(namespaceDTO); + when(namespaceAPI.findPublicNamespaceForAssociatedNamespace(any(), any(), any(), any())).thenReturn(createNamespace(testAppId, "branch", testNamespaceName)); + when(releaseService.loadLatestRelease(any(), any(), any(), any())).thenReturn(createReleaseDTO()); + when(itemService.findItems(any(), any(), any(), any())).thenReturn(createItems()); + when(itemService.findDeletedItems(any(), any(), any(), any())).thenReturn(createDeletedItems()); + + NamespaceBO namespaceBO = namespaceService.findPublicNamespaceForAssociatedNamespace(testEnv, testAppId, testClusterName, testNamespaceName); + + List namespaceKey2 = namespaceBO.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList()); + assertThat(namespaceBO.getItemModifiedCnt()).isEqualTo(3); + assertThat(namespaceBO.getItems().size()).isEqualTo(3); + assertThat(namespaceKey2).isEqualTo(Arrays.asList("k1", "k2", "k3")); + } + private ReleaseDTO createReleaseDTO() { ReleaseDTO releaseDTO = new ReleaseDTO(); releaseDTO.setConfigurations("{\"k1\":\"k1\",\"k2\":\"k2\", \"k3\":\"\"}"); - when(releaseService.loadLatestRelease(any(), any(), any(), any())).thenReturn(releaseDTO); + return releaseDTO; + } + private List createItems() { List itemDTOList = Lists.newArrayList(); ItemDTO itemDTO1 = new ItemDTO(); itemDTO1.setId(1); @@ -310,22 +295,18 @@ public void testFindPublicNamespaceForAssociatedNamespace() { itemDTO2.setKey("k2"); itemDTO2.setValue(String.valueOf(2)); itemDTOList.add(itemDTO2); - when(itemService.findItems(any(), any(), any(), any())).thenReturn(itemDTOList); + return itemDTOList; + } + + private List createDeletedItems() { List deletedItemDTOList = Lists.newArrayList(); ItemDTO deletedItemDTO = new ItemDTO(); deletedItemDTO.setId(3); deletedItemDTO.setNamespaceId(3); deletedItemDTO.setKey("k3"); deletedItemDTOList.add(deletedItemDTO); - when(itemService.findDeletedItems(any(), any(), any(), any())).thenReturn(deletedItemDTOList); - - NamespaceBO namespaceBO = namespaceService.findPublicNamespaceForAssociatedNamespace(testEnv, testAppId, testClusterName, testNamespaceName); - - List namespaceKey2 = namespaceBO.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList()); - assertThat(namespaceBO.getItemModifiedCnt()).isEqualTo(3); - assertThat(namespaceBO.getItems().size()).isEqualTo(3); - assertThat(namespaceKey2).isEqualTo(Arrays.asList("k1", "k2", "k3")); + return deletedItemDTOList; } private AppNamespace createAppNamespace(String appId, String name, boolean isPublic) { From 093e12d038e8ed45b384e88b6e35c29a76d6025b Mon Sep 17 00:00:00 2001 From: yangzl Date: Mon, 28 Oct 2024 00:17:26 +0800 Subject: [PATCH 8/8] style(apollo-portal): Format Code --- .../apollo/openapi/v1/controller/NamespaceController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java index 69e88fb4cb9..a3cf2ce5054 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java @@ -83,21 +83,21 @@ public OpenAppNamespaceDTO createNamespace(@PathVariable String appId, @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces") public List findNamespaces(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, - @RequestParam(defaultValue="true") boolean fillItemDetail) { + @RequestParam(defaultValue = "true") boolean fillItemDetail) { return this.namespaceOpenApiService.getNamespaces(appId, env, clusterName, fillItemDetail); } @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}") public OpenNamespaceDTO loadNamespace(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable String namespaceName, - @RequestParam(defaultValue="true") boolean fillItemDetail) { + @RequestParam(defaultValue = "true") boolean fillItemDetail) { return this.namespaceOpenApiService.getNamespace(appId, env, clusterName, namespaceName, fillItemDetail); } @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock") public OpenNamespaceLockDTO getNamespaceLock(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable - String namespaceName) { + String namespaceName) { return this.namespaceOpenApiService.getNamespaceLock(appId, env, clusterName, namespaceName); }