ComponentsResourceSupport extends ComponentSupport { List<FluentComponent> browse(final Repository browsedRepository, final String continuationToken) { List<FluentComponent> permittedComponents = new ArrayList<>(); String internalToken = toInternalToken(continuationToken); Continuation<FluentComponent> componentContinuation = getComponents(browsedRepository, internalToken); while (permittedComponents.size() < PAGE_SIZE && !componentContinuation.isEmpty()) { permittedComponents.addAll(removeComponentsNotPermitted(browsedRepository, componentContinuation)); componentContinuation = getComponents(browsedRepository, componentContinuation.nextContinuationToken()); } return trim(permittedComponents, PAGE_SIZE); } ComponentsResourceSupport(
      final ContentAuthHelper contentAuthHelper,
      final RepositoryManagerRESTAdapter repositoryManagerRESTAdapter);   }
@Test public void browseShouldBeEmptyWhenNoComponents() { when(componentContinuation.isEmpty()).thenReturn(true); List<FluentComponent> components = underTest.browse(repository, null); assertThat(components, empty()); verify(fluentComponents).browse(LIMIT, null); verify(contentAuthHelper, never()).checkPathPermissions(COMPONENT_NAME, A_FORMAT, REPOSITORY_NAME); }
@Test public void browseShouldBeEmptyWhenNoPermittedComponents() { when(componentContinuation.isEmpty()).thenReturn(false).thenReturn(true); when(contentAuthHelper.checkPathPermissions(COMPONENT_NAME, A_FORMAT, REPOSITORY_NAME)).thenReturn(false); List<FluentComponent> components = underTest.browse(repository, null); assertThat(components, empty()); verify(fluentComponents, times(2)).browse(LIMIT, null); verify(contentAuthHelper, times(NUMBER_OF_COMPONENTS)) .checkPathPermissions(COMPONENT_NAME, A_FORMAT, REPOSITORY_NAME); }
@Test public void browseShouldReturnPermittedComponents() { int numberOfComponentsNotPermitted = 4; int numberOfPermittedComponents = NUMBER_OF_COMPONENTS - numberOfComponentsNotPermitted; when(componentContinuation.isEmpty()).thenReturn(false).thenReturn(true); when(contentAuthHelper.checkPathPermissions(COMPONENT_NAME, A_FORMAT, REPOSITORY_NAME)) .thenReturn(false).thenReturn(false, false, false, true); List<FluentComponent> components = underTest.browse(repository, null); assertThat(components, hasSize(numberOfPermittedComponents)); verify(fluentComponents, times(2)).browse(LIMIT, null); verify(contentAuthHelper, times(NUMBER_OF_COMPONENTS)) .checkPathPermissions(COMPONENT_NAME, A_FORMAT, REPOSITORY_NAME); }
@Test public void shouldTrimNumberOfComponentsToLimit() { when(componentContinuation.isEmpty()).thenReturn(false); when(contentAuthHelper.checkPathPermissions(COMPONENT_NAME, A_FORMAT, REPOSITORY_NAME)).thenReturn(true); List<FluentComponent> components = underTest.browse(repository, null); assertThat(components, hasSize(AssetsResource.PAGE_SIZE)); verify(contentAuthHelper, times(NUMBER_OF_COMPONENTS)) .checkPathPermissions(COMPONENT_NAME, A_FORMAT, REPOSITORY_NAME); }