### Question:
DatabaseAccessPolicyProvider extends AbstractConfigurableAccessPolicyProvider { @Override public Set<AccessPolicy> getAccessPolicies() throws AuthorizationAccessException { final String sql = "SELECT * FROM APP_POLICY"; final List<DatabaseAccessPolicy> databasePolicies = jdbcTemplate.query(sql, new DatabaseAccessPolicyRowMapper()); final Map<String,Set<String>> policyToUsers = new HashMap<>(); jdbcTemplate.query("SELECT * FROM APP_POLICY_USER", (rs) -> { final String policyIdentifier = rs.getString("POLICY_IDENTIFIER"); final String userIdentifier = rs.getString("USER_IDENTIFIER"); final Set<String> userIdentifiers = policyToUsers.computeIfAbsent(policyIdentifier, (k) -> new HashSet<>()); userIdentifiers.add(userIdentifier); }); final Map<String,Set<String>> policyToGroups = new HashMap<>(); jdbcTemplate.query("SELECT * FROM APP_POLICY_GROUP", (rs) -> { final String policyIdentifier = rs.getString("POLICY_IDENTIFIER"); final String groupIdentifier = rs.getString("GROUP_IDENTIFIER"); final Set<String> groupIdentifiers = policyToGroups.computeIfAbsent(policyIdentifier, (k) -> new HashSet<>()); groupIdentifiers.add(groupIdentifier); }); final Set<AccessPolicy> policies = new HashSet<>(); databasePolicies.forEach(p -> { final Set<String> userIdentifiers = policyToUsers.get(p.getIdentifier()); final Set<String> groupIdentifiers = policyToGroups.get(p.getIdentifier()); policies.add(mapTopAccessPolicy(p, userIdentifiers, groupIdentifiers)); }); return policies; }  @AuthorizerContext void setDataSource(final DataSource dataSource); @AuthorizerContext void setIdentityMapper(final IdentityMapper identityMapper); @Override void doOnConfigured(final AuthorizerConfigurationContext configurationContext); @Override void preDestruction(); @Override String getFingerprint(); @Override void inheritFingerprint(String fingerprint); @Override void checkInheritability(String proposedFingerprint); @Override AccessPolicy addAccessPolicy(final AccessPolicy accessPolicy); @Override AccessPolicy updateAccessPolicy(final AccessPolicy accessPolicy); @Override Set<AccessPolicy> getAccessPolicies(); @Override AccessPolicy getAccessPolicy(final String identifier); @Override AccessPolicy getAccessPolicy(final String resourceIdentifier, RequestAction action); @Override AccessPolicy deleteAccessPolicy(final AccessPolicy accessPolicy);  }### Answer:
@Test public void testOnConfiguredCreatesInitialPolicies() { assertEquals(0, getPolicyCount()); configure(ADMIN_USER.getIdentity(), NIFI_IDENTITIES, NIFI_GROUP.getName()); final Set<AccessPolicy> policies = policyProvider.getAccessPolicies(); assertNotNull(policies); assertEquals(18, policies.size()); }
@Test public void testOnConfiguredWhenOnlyInitialAdmin() { assertEquals(0, getPolicyCount()); configure(ADMIN_USER.getIdentity(), null); final Set<AccessPolicy> policies = policyProvider.getAccessPolicies(); assertNotNull(policies); assertEquals(18, policies.size()); policies.forEach(p -> { assertNotNull(p.getUsers()); assertEquals(1, p.getUsers().size()); assertTrue(p.getUsers().contains(ADMIN_USER.getIdentifier())); }); }
@Test public void testOnConfiguredWhenOnlyInitialNiFiIdentities() { assertEquals(0, getPolicyCount()); configure(null, NIFI_IDENTITIES); final Set<AccessPolicy> policies = policyProvider.getAccessPolicies(); assertNotNull(policies); assertEquals(4, policies.size()); policies.forEach(p -> { assertNotNull(p.getUsers()); assertEquals(3, p.getUsers().size()); assertFalse(p.getUsers().contains(ADMIN_USER.getIdentifier())); }); }
@Test public void testOnConfiguredWhenOnlyNiFiGroupName() { assertEquals(0, getPolicyCount()); configure(null, null, NIFI_GROUP.getName()); final Set<AccessPolicy> policies = policyProvider.getAccessPolicies(); assertNotNull(policies); assertEquals(4, policies.size()); policies.forEach(p -> { assertNotNull(p.getGroups()); assertEquals(1, p.getGroups().size()); assertTrue(p.getGroups().contains(NIFI_GROUP.getIdentifier())); }); }