@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 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 testGetPrincipalByPrincipalNameNotFound() {
   Principal principal = identityService.getPrincipalByPrincipalName("DoesNotExist");
   assertNull("principal should not be found", principal);
 }