use of com.sequenceiq.authorization.service.list.ResourceFilteringService in project cloudbreak by hortonworks.
the class UtilAuthorizationServiceTest method testHasRightsOnResources.
@Test
public void testHasRightsOnResources() {
CheckRightOnResourcesV4Request request = new CheckRightOnResourcesV4Request();
request.setRight(RightV4.DH_DESCRIBE);
request.setResourceCrns(List.of(DATAHUB_CRN));
when(entitlementService.listFilteringEnabled(eq("1234"))).thenReturn(true);
doAnswer(invocation -> ((List<String>) invocation.getArgument(1)).stream().map(crn -> new Resource(crn, Optional.empty())).collect(Collectors.toList())).when(authorizationResourceProvider).findResources(anyString(), anyList());
doAnswer(invocation -> ((Function<Predicate<String>, List<CheckResourceRightV4Response>>) invocation.getArgument(3)).apply(crn -> true)).when(resourceFilteringService).filter(any(), any(), anyList(), any());
CheckRightOnResourcesV4Response response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkRightOnResources(request));
assertEquals(RightV4.DH_DESCRIBE, response.getRight());
assertEquals(1, response.getResponses().size());
CheckResourceRightV4Response checkResourceRightV4Response = response.getResponses().get(0);
assertTrue(checkResourceRightV4Response.isResult());
assertEquals(DATAHUB_CRN, checkResourceRightV4Response.getResourceCrn());
}
Aggregations