NamespaceService { public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName) { List<NamespaceDTO> namespaces = namespaceAPI.findNamespaceByCluster(appId, env, clusterName); if (namespaces == null || namespaces.size() == 0) { throw new BadRequestException("namespaces not exist"); } List<NamespaceBO> namespaceBOs = new LinkedList<>(); for (NamespaceDTO namespace : namespaces) { NamespaceBO namespaceBO; try { namespaceBO = transformNamespace2BO(env, namespace); namespaceBOs.add(namespaceBO); } catch (Exception e) { logger.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}", appId, env, clusterName, namespace.getNamespaceName(), e); throw e; } } return namespaceBOs; } NamespaceService(
      final PortalConfig portalConfig,
      final PortalSettings portalSettings,
      final UserInfoHolder userInfoHolder,
      final AdminServiceAPI.NamespaceAPI namespaceAPI,
      final ItemService itemService,
      final ReleaseService releaseService,
      final AppNamespaceService appNamespaceService,
      final InstanceService instanceService,
      final @Lazy NamespaceBranchService branchService,
      final RolePermissionService rolePermissionService); NamespaceDTO createNamespace(Env env, NamespaceDTO namespace); @Transactional void deleteNamespace(String appId, Env env, String clusterName, String namespaceName); NamespaceDTO loadNamespaceBaseInfo(String appId, Env env, String clusterName,
      String namespaceName); List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName); List<NamespaceDTO> findNamespaces(String appId, Env env, String clusterName); List<NamespaceDTO> getPublicAppNamespaceAllNamespaces(Env env, String publicNamespaceName,
      int page,
      int size); NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName,
      String namespaceName); boolean namespaceHasInstances(String appId, Env env, String clusterName,
      String namespaceName); boolean publicAppNamespaceHasAssociatedNamespace(String publicNamespaceName, Env env); NamespaceBO findPublicNamespaceForAssociatedNamespace(Env env, String appId,
      String clusterName, String namespaceName); Map<String, Map<String, Boolean>> getNamespacesPublishInfo(String appId); void assignNamespaceRoleToOperator(String appId, String namespaceName, String operator);  }
@Test public void testFindNamespace() { AppNamespace applicationAppNamespace = mock(AppNamespace.class); AppNamespace hermesAppNamespace = mock(AppNamespace.class); NamespaceDTO application = new NamespaceDTO(); application.setId(1); application.setClusterName(testClusterName); application.setAppId(testAppId); application.setNamespaceName(testNamespaceName); NamespaceDTO hermes = new NamespaceDTO(); hermes.setId(2); hermes.setClusterName("default"); hermes.setAppId(testAppId); hermes.setNamespaceName("hermes"); List<NamespaceDTO> namespaces = Arrays.asList(application, hermes); ReleaseDTO someRelease = new ReleaseDTO(); someRelease.setConfigurations("{\"a\":\"123\",\"b\":\"123\"}"); ItemDTO i1 = new ItemDTO("a", "123", "", 1); ItemDTO i2 = new ItemDTO("b", "1", "", 2); ItemDTO i3 = new ItemDTO("", "", "#dddd", 3); ItemDTO i4 = new ItemDTO("c", "1", "", 4); List<ItemDTO> someItems = Arrays.asList(i1, i2, i3, i4); when(applicationAppNamespace.getFormat()).thenReturn(ConfigFileFormat.Properties.getValue()); when(hermesAppNamespace.getFormat()).thenReturn(ConfigFileFormat.XML.getValue()); when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)) .thenReturn(applicationAppNamespace); when(appNamespaceService.findPublicAppNamespace("hermes")).thenReturn(hermesAppNamespace); when(namespaceAPI.findNamespaceByCluster(testAppId, Env.DEV, testClusterName)).thenReturn(namespaces); when(releaseService.loadLatestRelease(testAppId, Env.DEV, testClusterName, testNamespaceName)).thenReturn(someRelease); when(releaseService.loadLatestRelease(testAppId, Env.DEV, testClusterName, "hermes")).thenReturn(someRelease); when(itemService.findItems(testAppId, Env.DEV, testClusterName, testNamespaceName)).thenReturn(someItems); List<NamespaceBO> namespaceVOs = namespaceService.findNamespaceBOs(testAppId, Env.DEV, testClusterName); assertEquals(2, namespaceVOs.size()); NamespaceBO namespaceVO = namespaceVOs.get(0); assertEquals(4, namespaceVO.getItems().size()); assertEquals("a", namespaceVO.getItems().get(0).getItem().getKey()); assertEquals(2, namespaceVO.getItemModifiedCnt()); assertEquals(testAppId, namespaceVO.getBaseInfo().getAppId()); assertEquals(testClusterName, namespaceVO.getBaseInfo().getClusterName()); assertEquals(testNamespaceName, namespaceVO.getBaseInfo().getNamespaceName()); }