Skip to content

Commit

Permalink
Reworked CriticalRolesCertificationTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 6, 2016
1 parent beb6d90 commit 7f61765
Show file tree
Hide file tree
Showing 6 changed files with 771 additions and 183 deletions.
Expand Up @@ -144,6 +144,10 @@ public class AbstractCertificationTest extends AbstractModelIntegrationTest {

public static final File ROLE_COO_FILE = new File(COMMON_DIR, "role-coo.xml");
protected static final String ROLE_COO_OID = "00000000-d34d-b33f-f00d-000000000002";

public static final File ROLE_CTO_FILE = new File(COMMON_DIR, "role-cto.xml");
protected static final String ROLE_CTO_OID = "00000000-d34d-b33f-f00d-000000000003";

protected static final File ROLE_INDUCEMENT_CERT_DEF_FILE = new File(COMMON_DIR, "certification-of-role-inducements.xml");

protected DummyResource dummyResource;
Expand Down Expand Up @@ -182,6 +186,7 @@ public class AbstractCertificationTest extends AbstractModelIntegrationTest {

protected RoleType roleCeo;
protected RoleType roleCoo;
protected RoleType roleCto;
protected RoleType roleSuperuser;

protected UserType userAdministrator;
Expand Down Expand Up @@ -211,6 +216,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
roleSuperuser = repoAddObjectFromFile(ROLE_SUPERUSER_FILE, RoleType.class, initResult).asObjectable();
roleCeo = repoAddObjectFromFile(ROLE_CEO_FILE, RoleType.class, initResult).asObjectable();
roleCoo = repoAddObjectFromFile(ROLE_COO_FILE, RoleType.class, initResult).asObjectable();
roleCto = repoAddObjectFromFile(ROLE_CTO_FILE, RoleType.class, initResult).asObjectable();
repoAddObjectFromFile(ROLE_REVIEWER_FILE, RoleType.class, initResult).asObjectable();
repoAddObjectFromFile(ROLE_EROOT_USER_ASSIGNMENT_CAMPAIGN_OWNER_FILE, RoleType.class, initResult).asObjectable();

Expand Down Expand Up @@ -365,10 +371,10 @@ protected void assertDefinitionAndOwner(AccessCertificationCampaignType campaign
campaign.getDefinitionRef());
}

protected void assertCaseReviewers(AccessCertificationCaseType _case, AccessCertificationResponseType currentResponse,
int currentResponseStage, List<String> reviewerOidList) {
assertEquals("wrong current response", currentResponse, _case.getCurrentStageOutcome());
assertEquals("wrong current response stage number", currentResponseStage, _case.getCurrentStageNumber());
protected void assertCaseReviewers(AccessCertificationCaseType _case, AccessCertificationResponseType currentStageOutcome,
int currentStage, List<String> reviewerOidList) {
assertEquals("wrong current stage outcome", currentStageOutcome, _case.getCurrentStageOutcome());
assertEquals("wrong current stage number", currentStage, _case.getCurrentStageNumber());
Set<String> realReviewerOids = new HashSet<>();
for (ObjectReferenceType ref : _case.getCurrentReviewerRef()) {
realReviewerOids.add(ref.getOid());
Expand Down Expand Up @@ -397,8 +403,9 @@ protected void recordDecision(String campaignOid, AccessCertificationCaseType _c
}
}

// TODO remove redundant check on outcomes (see checkCaseOutcome)
protected void assertSingleDecision(AccessCertificationCaseType _case, AccessCertificationResponseType response, String comment, int stageNumber, String reviewerOid, AccessCertificationResponseType aggregatedResponse, boolean checkHistory) {
// TODO remove redundant check on outcomes (see assertCaseOutcome)
protected void assertSingleDecision(AccessCertificationCaseType _case, AccessCertificationResponseType response, String comment,
int stageNumber, String reviewerOid, AccessCertificationResponseType currentStageOutcome, boolean checkHistory) {
List<AccessCertificationDecisionType> currentDecisions = getCurrentDecisions(_case, stageNumber, false);
assertEquals("wrong # of decisions for stage " + stageNumber, 1, currentDecisions.size());
AccessCertificationDecisionType storedDecision = currentDecisions.get(0);
Expand All @@ -409,9 +416,24 @@ protected void assertSingleDecision(AccessCertificationCaseType _case, AccessCer
if (response != null) {
assertApproximateTime("timestamp", new Date(), storedDecision.getTimestamp());
}
assertEquals("wrong current response", aggregatedResponse, _case.getCurrentStageOutcome());
assertEquals("wrong current stage outcome", currentStageOutcome, _case.getCurrentStageOutcome());
if (checkHistory) {
assertHistoricOutcome(_case, stageNumber, aggregatedResponse);
assertHistoricOutcome(_case, stageNumber, currentStageOutcome);
}
}

protected void assertReviewerDecision(AccessCertificationCaseType _case, AccessCertificationResponseType response, String comment,
int stageNumber, String reviewerOid, AccessCertificationResponseType currentStageOutcome, boolean checkHistory) {
AccessCertificationDecisionType storedDecision = getDecisionForReviewer(_case, stageNumber, reviewerOid);
assertNotNull("No decision for reviewer " + reviewerOid + " in stage " + stageNumber, storedDecision);
assertEquals("wrong response", response, storedDecision.getResponse());
assertEquals("wrong comment", comment, storedDecision.getComment());
if (response != null) {
assertApproximateTime("timestamp", new Date(), storedDecision.getTimestamp());
}
assertEquals("wrong current stage outcome", currentStageOutcome, _case.getCurrentStageOutcome());
if (checkHistory) {
assertHistoricOutcome(_case, stageNumber, currentStageOutcome);
}
}

Expand Down Expand Up @@ -450,6 +472,15 @@ public List<AccessCertificationDecisionType> getCurrentDecisions(AccessCertifica
return currentDecisions;
}

public AccessCertificationDecisionType getDecisionForReviewer(AccessCertificationCaseType _case, int stageNumber, String reviewerOid) {
for (AccessCertificationDecisionType decision : _case.getDecision()) {
if (decision.getStageNumber() == stageNumber && decision.getReviewerRef().getOid().equals(reviewerOid)) {
return decision;
}
}
return null;
}

protected void assertNoDecision(AccessCertificationCaseType _case, int stage, AccessCertificationResponseType aggregatedResponse, boolean checkHistory) {
List<AccessCertificationDecisionType> currentDecisions = getCurrentDecisions(_case, stage, true);
assertEquals("wrong # of decisions", 0, currentDecisions.size());
Expand Down Expand Up @@ -525,8 +556,8 @@ private AccessCertificationResponseType checkCaseStageOutcome(AccessCertificatio
}

// completedStage - if null, checks the stage outcome in the history list
protected void checkCaseOutcome(List<AccessCertificationCaseType> caseList, String subjectOid, String targetOid,
AccessCertificationResponseType stageOutcome, AccessCertificationResponseType overallOutcome, Integer completedStage) {
protected void assertCaseOutcome(List<AccessCertificationCaseType> caseList, String subjectOid, String targetOid,
AccessCertificationResponseType stageOutcome, AccessCertificationResponseType overallOutcome, Integer completedStage) {
AccessCertificationCaseType ccase = findCase(caseList, subjectOid, targetOid);
assertEquals("Wrong stage outcome in " + ccase, stageOutcome, ccase.getCurrentStageOutcome());
assertEquals("Wrong overall outcome in " + ccase, overallOutcome, ccase.getOverallOutcome());
Expand All @@ -536,6 +567,11 @@ protected void checkCaseOutcome(List<AccessCertificationCaseType> caseList, Stri
}
}

protected void assertPercentComplete(String campaignOid, int expCasesComplete, int expCasesDecided, int expDecisionsDone) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
AccessCertificationCampaignType campaign = getCampaignWithCases(campaignOid);
assertPercentComplete(campaign, expCasesComplete, expCasesDecided, expDecisionsDone);
}

protected void assertPercentComplete(AccessCertificationCampaignType campaign, int expCasesComplete, int expCasesDecided, int expDecisionsDone) {
int casesCompletePercentage = Math.round(CertCampaignTypeUtil.getCasesCompletedPercentage(campaign));
System.out.println("Cases completed = " + casesCompletePercentage + " %");
Expand Down
Expand Up @@ -282,12 +282,12 @@ public void test021OpenFirstStageAllowed() throws Exception {
checkAllCases(campaign.getCase(), campaignOid);
List<AccessCertificationCaseType> caseList = campaign.getCase();
// no responses -> NO_RESPONSE in all cases
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_SUPERUSER_OID, NO_RESPONSE, NO_RESPONSE, null);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_COO_OID, NO_RESPONSE, NO_RESPONSE, null);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_CEO_OID, NO_RESPONSE, NO_RESPONSE, null);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE, null);
checkCaseOutcome(caseList, USER_JACK_OID, ROLE_CEO_OID, NO_RESPONSE, NO_RESPONSE, null);
checkCaseOutcome(caseList, USER_JACK_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE, null);
assertCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_SUPERUSER_OID, NO_RESPONSE, NO_RESPONSE, null);
assertCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_COO_OID, NO_RESPONSE, NO_RESPONSE, null);
assertCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_CEO_OID, NO_RESPONSE, NO_RESPONSE, null);
assertCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE, null);
assertCaseOutcome(caseList, USER_JACK_OID, ROLE_CEO_OID, NO_RESPONSE, NO_RESPONSE, null);
assertCaseOutcome(caseList, USER_JACK_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE, null);

assertPercentComplete(campaign, 0, 0, 0);
}
Expand Down Expand Up @@ -674,12 +674,12 @@ public void test152CloseFirstStageAllow() throws Exception {
assertAfterStageClose(campaign, certificationDefinition, 1);
List<AccessCertificationCaseType> caseList = campaign.getCase();
checkAllCases(caseList, campaignOid);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_SUPERUSER_OID, ACCEPT, ACCEPT, 1);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_COO_OID, NO_RESPONSE, NO_RESPONSE, 1);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_CEO_OID, NO_RESPONSE, NO_RESPONSE, 1);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE, 1);
checkCaseOutcome(caseList, USER_JACK_OID, ROLE_CEO_OID, REVOKE, REVOKE, 1);
checkCaseOutcome(caseList, USER_JACK_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE, 1);
assertCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_SUPERUSER_OID, ACCEPT, ACCEPT, 1);
assertCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_COO_OID, NO_RESPONSE, NO_RESPONSE, 1);
assertCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_CEO_OID, NO_RESPONSE, NO_RESPONSE, 1);
assertCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE, 1);
assertCaseOutcome(caseList, USER_JACK_OID, ROLE_CEO_OID, REVOKE, REVOKE, 1);
assertCaseOutcome(caseList, USER_JACK_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE, 1);

assertPercentComplete(campaign, Math.round(200.0f/7.0f), Math.round(200.0f/7.0f), Math.round(200.0f/7.0f)); // 1 reviewer per case (always administrator)
}
Expand Down

0 comments on commit 7f61765

Please sign in to comment.