SecurityMetadata extends AbstractMetadataBundle { protected Set<String> getApiPrivileges(boolean incDestructive) { Set<String> privileges = new HashSet<String>(); for (Privilege privilege : userService.getAllPrivileges()) { if (privilege.getPrivilege().startsWith("App: ") || privilege.getPrivilege().startsWith("Emr: ")) { continue; } boolean isDestructive = privilege.getPrivilege().startsWith("Delete ") || privilege.getPrivilege().startsWith("Purge "); if (!incDestructive && isDestructive) { continue; } privileges.add(privilege.getPrivilege()); } return privileges; }  @Override void install();  }
@Test public void getApiPrivileges_shouldGetAllApiPrivileges() { Set<String> all = securityMetadata.getApiPrivileges(true); Assert.assertThat(all.contains("View Patients"), is(true)); Assert.assertThat(all.contains("Edit Orders"), is(true)); Assert.assertThat(all.contains("Delete Users"), is(true)); Set<String> nonDeletes = securityMetadata.getApiPrivileges(false); Assert.assertThat(nonDeletes.contains("View Patients"), is(true)); Assert.assertThat(nonDeletes.contains("Edit Orders"), is(true)); Assert.assertThat(nonDeletes.contains("Delete Users"), is(false)); }