@Test
  public void testGetContainedAttributes() {
    Principal principal = identityService.getPrincipal("p1");

    EntityDefault entity = identityService.getEntityDefault(principal.getEntityId());
    assertNotNull("Entity Must not be null", entity);
    EntityTypeContactInfoDefault eet = entity.getEntityType("PERSON");
    assertNotNull("PERSON EntityTypeData must not be null", eet);
    assertNotNull(
        "EntityEntityType's default email address must not be null", eet.getDefaultEmailAddress());
    assertEquals("*****@*****.**", eet.getDefaultEmailAddress().getEmailAddressUnmasked());
  }
 @Test
 public void testGetPrincipalByPrincipalName() {
   Principal principal = identityService.getPrincipalByPrincipalName("kuluser");
   assertNotNull("principal must not be null", principal);
   assertEquals(
       "Principal ID did not match expected result", "KULUSER", principal.getPrincipalId());
 }
  protected void finalizeOnlineReviewDocument(
      ProtocolOnlineReviewDocumentBase protocolOnlineReviewDocument,
      ProtocolSubmissionBase submission,
      String annotation) {

    try {

      final String principalId =
          identityManagementService
              .getPrincipalByPrincipalName(KRADConstants.SYSTEM_USER)
              .getPrincipalId();
      WorkflowDocument workflowDocument =
          WorkflowDocumentFactory.loadDocument(
              principalId, protocolOnlineReviewDocument.getDocumentNumber());
      ProtocolOnlineReviewBase review = protocolOnlineReviewDocument.getProtocolOnlineReview();
      review.addActionPerformed(
          "Finalize:"
              + workflowDocument.getStatus().getCode()
              + ":"
              + review.getProtocolOnlineReviewStatusCode());

      if (workflowDocument.isEnroute()
          || workflowDocument.isInitiated()
          || workflowDocument.isSaved()) {
        workflowDocument.superUserBlanketApprove(annotation);
      }
    } catch (Exception e) {
      String errorMessage =
          String.format(
              "Workflow exception generated while executing superUserApprove on document %s in finalizeOnlineReviewDocument. Message:%s",
              protocolOnlineReviewDocument.getDocumentNumber(), e.getMessage());
      LOG.error(errorMessage);
      throw new RuntimeException(errorMessage, e);
    }
  }
  protected void cancelOnlineReviewDocument(
      ProtocolOnlineReviewDocumentBase protocolOnlineReviewDocument,
      ProtocolSubmissionBase submission,
      String annotation) {
    try {

      final String principalId =
          identityManagementService
              .getPrincipalByPrincipalName(KRADConstants.SYSTEM_USER)
              .getPrincipalId();
      WorkflowDocument workflowDocument =
          WorkflowDocumentFactory.loadDocument(
              principalId, protocolOnlineReviewDocument.getDocumentNumber());

      if (workflowDocument.isEnroute()
          || workflowDocument.isInitiated()
          || workflowDocument.isSaved()) {
        workflowDocument.superUserCancel(
            String.format(
                "Review Cancelled from assign reviewers action by %s",
                GlobalVariables.getUserSession().getPrincipalId()));
      }
    } catch (Exception e) {
      String errorMessage =
          String.format(
              "Exception generated while executing superUserCancel on document %s in removeOnlineReviewDocument. Message: %s",
              protocolOnlineReviewDocument.getDocumentNumber(), e.getMessage());
      LOG.error(errorMessage);
      throw new RuntimeException(errorMessage, e);
    }
  }
 /** Test the getPersonsInRole() service method. */
 @Test
 public void testGetPersonsInRole() throws Exception {
   ProposalDevelopmentDocument doc = createProposal("Proposal-9", "000001");
   PrincipalContract userChew = identityManagementService.getPrincipalByPrincipalName("chew");
   kraAuthService.addDocumentLevelRole(userChew.getPrincipalId(), RoleConstants.AGGREGATOR, doc);
   List<String> persons = kraAuthService.getPrincipalsInRole(RoleConstants.AGGREGATOR, doc);
   assertEquals(2, persons.size());
 }
 /** Test the hasRole() service method. */
 @Test
 public void testHasRole() throws Exception {
   ProposalDevelopmentDocument doc = createProposal("Proposal-7", "000001");
   PrincipalContract userChew = identityManagementService.getPrincipalByPrincipalName("chew");
   kraAuthService.addDocumentLevelRole(
       userChew.getPrincipalId(), RoleConstants.BUDGET_CREATOR, doc);
   assertTrue(
       kraAuthService.hasDocumentLevelRole(
           userChew.getPrincipalId(), RoleConstants.BUDGET_CREATOR, doc));
 }
 @Test
 public void testGetPrincipals() {
   List<String> principalIds = new ArrayList<String>();
   principalIds.add("KULUSER");
   List<Principal> validPrincipals = identityService.getPrincipals(principalIds);
   assertNotNull("validPrincipals must not be null", validPrincipals);
   assertEquals(
       "validPrincipals name did not match expected result",
       "kuluser",
       validPrincipals.get(0).getPrincipalName());
 }
 @Test
 public void testGetEntityWithNameChangeDate() {
   String principalName = "testuser7";
   Entity info = identityService.getEntityByPrincipalName(principalName);
   List<EntityName> names = info.getNames();
   for (EntityName name : names) {
     assertNotNull(
         "nameChangeDate should have been set for PrincipalName " + principalName,
         name.getNameChangedDate());
   }
 }
 /** Test the hasPermission() service method. */
 @Test
 public void testHasPermission() throws Exception {
   PrincipalContract userChew = identityManagementService.getPrincipalByPrincipalName("chew");
   ProposalDevelopmentDocument doc = createProposal("Proposal-6", "000001");
   kraAuthService.addDocumentLevelRole(
       userChew.getPrincipalId(), RoleConstants.NARRATIVE_WRITER, doc);
   assertTrue(
       kraAuthService.hasPermission(
           userChew.getPrincipalId(), doc, PermissionConstants.MODIFY_NARRATIVE));
   assertFalse(
       kraAuthService.hasPermission(
           userChew.getPrincipalId(), doc, PermissionConstants.MODIFY_BUDGET));
 }
 @Test
 public void testGetDefaultEntityByPrincipalId() {
   String principalId = "KULUSER";
   EntityDefault info = identityService.getEntityDefaultByPrincipalId(principalId);
   assertNotNull("entity must not be null", info);
   assertNotNull("entity principals must not be null", info.getPrincipals());
   assertEquals("entity must have exactly 1 principal", 1, info.getPrincipals().size());
   for (Principal principalInfo : info.getPrincipals()) {
     assertEquals("Wrong principal id", principalId, principalInfo.getPrincipalId());
   }
   assertTrue(
       "entity external identifiers must not be null",
       (info.getExternalIdentifiers() == null) || info.getExternalIdentifiers().isEmpty());
 }
 @Test
 public void testGetEntityByPrincipalName() {
   String principalName = "kuluser";
   Entity info = identityService.getEntityByPrincipalName(principalName);
   assertNotNull("entity must not be null", info);
   assertNotNull("entity principals must not be null", info.getPrincipals());
   assertEquals("entity must have exactly 1 principal", 1, info.getPrincipals().size());
   for (Principal principalInfo : info.getPrincipals()) {
     assertEquals("Wrong principal name", principalName, principalInfo.getPrincipalName());
   }
   assertTrue(
       "entity external identifiers must not be null",
       (info.getExternalIdentifiers() == null) || info.getExternalIdentifiers().isEmpty());
   assertTrue(
       "entity residencies must not be null",
       (info.getResidencies() == null) || info.getResidencies().isEmpty());
 }
 @Test
 public void testLookupEntityInfo() {
   String principalIdToTest = "p1";
   List<Entity> results =
       identityService.findEntities(setUpEntityLookupCriteria(principalIdToTest)).getResults();
   assertNotNull("Lookup results should never be null", results);
   assertEquals("Lookup result count is invalid", 1, results.size());
   for (Entity kimEntityInfo : results) {
     assertEquals(
         "Entity should have only one principal for this test",
         1,
         kimEntityInfo.getPrincipals().size());
     assertEquals(
         "Principal Ids should match",
         principalIdToTest,
         kimEntityInfo.getPrincipals().get(0).getPrincipalId());
   }
 }
 public String getCurrentUser() {
   return ((Principal) identityService.getPrincipal(getUserIdentifier())).getPrincipalName();
 }
 @Test
 public void testGetPrincipalByPrincipalNameNotFound() {
   Principal principal = identityService.getPrincipalByPrincipalName("DoesNotExist");
   assertNull("principal should not be found", principal);
 }