BrowseServiceImpl extends ComponentSupport implements BrowseService { @Override public PageResult<Asset> browseComponentAssets(final Repository repository, final String componentId) { checkNotNull(repository); checkNotNull(componentId); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); Component component = storageTx.findComponent(new DetachedEntityId(componentId)); if (component == null) { return new PageResult<>(0, Collections.emptyList()); } return browseComponentAssetsHelper(storageTx, repository, component); } } @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);  }
@Test public void testBrowseComponentAssets_all_authorized() { setupMocksForBrowserComponentAssets(true, true); PageResult<Asset> results = underTest.browseComponentAssets(mavenReleases, "componentOne"); assertThat(results.getTotal(), is(2l)); assertThat(results.getResults().get(0).name(), is(assetOne.name())); assertThat(results.getResults().get(1).name(), is(assetTwo.name())); }
@Test public void testBrowseComponentAssets_not_all_authorized() { setupMocksForBrowserComponentAssets(false, true); PageResult<Asset> results = underTest.browseComponentAssets(mavenReleases, "componentOne"); assertThat(results.getTotal(), is(1l)); assertThat(results.getResults().get(0).name(), is(assetTwo.name())); }
@Test public void testBrowseComponentAssets_none_authorized() { setupMocksForBrowserComponentAssets(false, false); PageResult<Asset> results = underTest.browseComponentAssets(mavenReleases, "componentOne"); assertThat(results.getTotal(), is(0l)); }