@Test public void testGetRepoToContainedGroupMap() { Repository repo1 = mock(Repository.class); when(repo1.getName()).thenReturn("repo1"); when(repo1.optionalFacet(GroupFacet.class)).thenReturn(Optional.empty()); Repository repo2 = mock(Repository.class); when(repo2.getName()).thenReturn("repo2"); when(repo2.optionalFacet(GroupFacet.class)).thenReturn(Optional.empty()); Repository group = mock(Repository.class); when(group.getName()).thenReturn("group"); GroupFacet groupFacet = mock(GroupFacet.class); when(groupFacet.leafMembers()).thenReturn(Arrays.asList(repo1)); when(group.optionalFacet(GroupFacet.class)).thenReturn(Optional.of(groupFacet)); List<Repository> repositories = Arrays.asList(repo1, repo2, group); Map<String, List<String>> repoToContainedGroups = underTest.getRepoToContainedGroupMap(repositories); assertThat(repoToContainedGroups.size(), is(3)); assertThat(repoToContainedGroups.get("repo1").size(), is(2)); assertThat(repoToContainedGroups.get("repo1").get(0), is("repo1")); assertThat(repoToContainedGroups.get("repo1").get(1), is("group")); assertThat(repoToContainedGroups.get("repo2").size(), is(1)); assertThat(repoToContainedGroups.get("repo2").get(0), is("repo2")); assertThat(repoToContainedGroups.get("group").size(), is(1)); assertThat(repoToContainedGroups.get("group").get(0), is("group")); }
@VisibleForTesting Map<String, List<String>> getRepoToContainedGroupMap(List<Repository> repositories) { Map<String, List<String>> repoToContainedGroupMap = new HashMap<>(); for (Repository repository : repositories) { List<String> groupNames = new ArrayList<>(); groupNames.add(repository.getName()); groupNames.addAll(repositories.stream().filter(groupRepository -> { Optional<GroupFacet> groupFacet = groupRepository.optionalFacet(GroupFacet.class); return groupFacet.isPresent() && groupFacet.get().leafMembers().stream() .anyMatch(leafMember -> repository.getName().equals(leafMember.getName())); }).map(groupRepository -> groupRepository.getName()).collect(Collectors.toSet())); repoToContainedGroupMap.put(repository.getName(), groupNames); } return repoToContainedGroupMap; }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @VisibleForTesting Map<String, List<String>> getRepoToContainedGroupMap(List<Repository> repositories) { Map<String, List<String>> repoToContainedGroupMap = new HashMap<>(); for (Repository repository : repositories) { List<String> groupNames = new ArrayList<>(); groupNames.add(repository.getName()); groupNames.addAll(repositories.stream().filter(groupRepository -> { Optional<GroupFacet> groupFacet = groupRepository.optionalFacet(GroupFacet.class); return groupFacet.isPresent() && groupFacet.get().leafMembers().stream() .anyMatch(leafMember -> repository.getName().equals(leafMember.getName())); }).map(groupRepository -> groupRepository.getName()).collect(Collectors.toSet())); repoToContainedGroupMap.put(repository.getName(), groupNames); } return repoToContainedGroupMap; } }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @VisibleForTesting Map<String, List<String>> getRepoToContainedGroupMap(List<Repository> repositories) { Map<String, List<String>> repoToContainedGroupMap = new HashMap<>(); for (Repository repository : repositories) { List<String> groupNames = new ArrayList<>(); groupNames.add(repository.getName()); groupNames.addAll(repositories.stream().filter(groupRepository -> { Optional<GroupFacet> groupFacet = groupRepository.optionalFacet(GroupFacet.class); return groupFacet.isPresent() && groupFacet.get().leafMembers().stream() .anyMatch(leafMember -> repository.getName().equals(leafMember.getName())); }).map(groupRepository -> groupRepository.getName()).collect(Collectors.toSet())); repoToContainedGroupMap.put(repository.getName(), groupNames); } return repoToContainedGroupMap; } @Inject  BrowseServiceImpl(@Named(GroupType.NAME) final Type groupType,
                           final ComponentEntityAdapter componentEntityAdapter,
                           final VariableResolverAdapterManager variableResolverAdapterManager,
                           final ContentPermissionChecker contentPermissionChecker,
                           final AssetEntityAdapter assetEntityAdapter,
                           final BrowseAssetIterableFactory browseAssetIterableFactory,
                           final BrowseAssetsSqlBuilder browseAssetsSqlBuilder,
                           final BrowseComponentsSqlBuilder browseComponentsSqlBuilder,
                           final BucketStore bucketStore,
                           final RepositoryManager repositoryManager); }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @VisibleForTesting Map<String, List<String>> getRepoToContainedGroupMap(List<Repository> repositories) { Map<String, List<String>> repoToContainedGroupMap = new HashMap<>(); for (Repository repository : repositories) { List<String> groupNames = new ArrayList<>(); groupNames.add(repository.getName()); groupNames.addAll(repositories.stream().filter(groupRepository -> { Optional<GroupFacet> groupFacet = groupRepository.optionalFacet(GroupFacet.class); return groupFacet.isPresent() && groupFacet.get().leafMembers().stream() .anyMatch(leafMember -> repository.getName().equals(leafMember.getName())); }).map(groupRepository -> groupRepository.getName()).collect(Collectors.toSet())); repoToContainedGroupMap.put(repository.getName(), groupNames); } return repoToContainedGroupMap; } @Inject  BrowseServiceImpl(@Named(GroupType.NAME) final Type groupType,
                           final ComponentEntityAdapter componentEntityAdapter,
                           final VariableResolverAdapterManager variableResolverAdapterManager,
                           final ContentPermissionChecker contentPermissionChecker,
                           final AssetEntityAdapter assetEntityAdapter,
                           final BrowseAssetIterableFactory browseAssetIterableFactory,
                           final BrowseAssetsSqlBuilder browseAssetsSqlBuilder,
                           final BrowseComponentsSqlBuilder browseComponentsSqlBuilder,
                           final BucketStore bucketStore,
                           final RepositoryManager repositoryManager); @Override PageResult<Component> browseComponents(final Repository repository,
                                                  final QueryOptions queryOptions); @Override PageResult<Asset> browseComponentAssets(final Repository repository, final String componentId); @Override PageResult<Asset> browseComponentAssets(final Repository repository, final Component component); @Override PageResult<Asset> browseAssets(final Repository repository,
                                          final QueryOptions queryOptions); @Override PageResult<Asset> previewAssets(final RepositorySelector repositorySelector,
                                           final List<Repository> repositories,
                                           final String jexlExpression,
                                           final QueryOptions queryOptions); @Override Asset getAssetById(final ORID assetId, final Repository repository); @Override Component getComponentById(final ORID componentId, final Repository repository); @Override Map<EntityId, String> getRepositoryBucketNames(final Repository repository); @Override Asset getAssetById(final EntityId assetId, final Repository repository); }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @VisibleForTesting Map<String, List<String>> getRepoToContainedGroupMap(List<Repository> repositories) { Map<String, List<String>> repoToContainedGroupMap = new HashMap<>(); for (Repository repository : repositories) { List<String> groupNames = new ArrayList<>(); groupNames.add(repository.getName()); groupNames.addAll(repositories.stream().filter(groupRepository -> { Optional<GroupFacet> groupFacet = groupRepository.optionalFacet(GroupFacet.class); return groupFacet.isPresent() && groupFacet.get().leafMembers().stream() .anyMatch(leafMember -> repository.getName().equals(leafMember.getName())); }).map(groupRepository -> groupRepository.getName()).collect(Collectors.toSet())); repoToContainedGroupMap.put(repository.getName(), groupNames); } return repoToContainedGroupMap; } @Inject  BrowseServiceImpl(@Named(GroupType.NAME) final Type groupType,
                           final ComponentEntityAdapter componentEntityAdapter,
                           final VariableResolverAdapterManager variableResolverAdapterManager,
                           final ContentPermissionChecker contentPermissionChecker,
                           final AssetEntityAdapter assetEntityAdapter,
                           final BrowseAssetIterableFactory browseAssetIterableFactory,
                           final BrowseAssetsSqlBuilder browseAssetsSqlBuilder,
                           final BrowseComponentsSqlBuilder browseComponentsSqlBuilder,
                           final BucketStore bucketStore,
                           final RepositoryManager repositoryManager); @Override PageResult<Component> browseComponents(final Repository repository,
                                                  final QueryOptions queryOptions); @Override PageResult<Asset> browseComponentAssets(final Repository repository, final String componentId); @Override PageResult<Asset> browseComponentAssets(final Repository repository, final Component component); @Override PageResult<Asset> browseAssets(final Repository repository,
                                          final QueryOptions queryOptions); @Override PageResult<Asset> previewAssets(final RepositorySelector repositorySelector,
                                           final List<Repository> repositories,
                                           final String jexlExpression,
                                           final QueryOptions queryOptions); @Override Asset getAssetById(final ORID assetId, final Repository repository); @Override Component getComponentById(final ORID componentId, final Repository repository); @Override Map<EntityId, String> getRepositoryBucketNames(final Repository repository); @Override Asset getAssetById(final EntityId assetId, final Repository repository);  }