@Test
public void testApprovedWithNonDirectAccess() {

    final AuthorizerConfigurationContext configurationContext = createMockConfigContext();
    setup(mock(NiFiRegistryProperties.class), mock(UserGroupProvider.class), configurationContext);
    final String systemResource = "/system";
    final RequestAction action = RequestAction.WRITE;
    final String user = "admin";
    // the incoming NiFi request to test
    final AuthorizationRequest request = new AuthorizationRequest.Builder()
            .resource(new MockResource(systemResource, systemResource))
            .action(action)
            .identity(user)
            .resourceContext(new HashMap<>())
            .accessAttempt(false)
            .anonymous(false)
            .build();
    // the expected Ranger resource and request that are created
    final RangerAccessResourceImpl resource = new RangerAccessResourceImpl();
    resource.setValue(RangerAuthorizer.RANGER_NIFI_REG_RESOURCE_NAME, systemResource);
    final RangerAccessRequestImpl expectedRangerRequest = new RangerAccessRequestImpl();
    expectedRangerRequest.setResource(resource);
    expectedRangerRequest.setAction(request.getAction().name());
    expectedRangerRequest.setAccessType(request.getAction().name());
    expectedRangerRequest.setUser(request.getIdentity());
    // no result processor should be provided used non-direct access
    when(rangerBasePlugin.isAccessAllowed(
            argThat(new RangerAccessRequestMatcher(expectedRangerRequest)))
    ).thenReturn(allowedResult);
    final AuthorizationResult result = authorizer.authorize(request);
    assertEquals(AuthorizationResult.approved().getResult(), result.getResult());
}