Skip to content

Commit

Permalink
Reviewed RoleInducementCertificationTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 6, 2016
1 parent 06e4320 commit aa5f68e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 110 deletions.
Expand Up @@ -305,7 +305,15 @@ protected void assertApproximateTime(String itemName, Date expected, XMLGregoria
Math.abs(actualAsDate.getTime() - expected.getTime()) < 600000); // 10 minutes
}

protected void assertAfterCampaignStart(AccessCertificationCampaignType campaign, AccessCertificationDefinitionType definition, int cases) {
protected void assertAfterCampaignCreate(AccessCertificationCampaignType campaign, AccessCertificationDefinitionType definition) {
assertEquals("Unexpected certification cases", 0, campaign.getCase().size());
assertStateAndStage(campaign, CREATED, 0);
assertEquals("Unexpected # of stages", definition.getStageDefinition().size(), campaign.getStageDefinition().size());
assertDefinitionAndOwner(campaign, definition);
assertNull("Unexpected start time", campaign.getStart());
assertNull("Unexpected end time", campaign.getEnd());
}
protected void assertAfterCampaignStart(AccessCertificationCampaignType campaign, AccessCertificationDefinitionType definition, int cases) throws ConfigurationException, ObjectNotFoundException, SchemaException, CommunicationException, SecurityViolationException {
assertStateAndStage(campaign, IN_REVIEW_STAGE, 1);
assertDefinitionAndOwner(campaign, definition);
assertApproximateTime("start time", new Date(), campaign.getStart());
Expand All @@ -318,17 +326,27 @@ protected void assertAfterCampaignStart(AccessCertificationCampaignType campaign
assertNotNull("stage 1 deadline", stage.getDeadline()); // too lazy to compute exact datetime
assertNull("unexpected stage 1 end", stage.getEnd());
assertEquals("Wrong number of certification cases", cases, campaign.getCase().size());
}

protected void assertAfterCampaignCreate(AccessCertificationCampaignType campaign, AccessCertificationDefinitionType definition) {
assertEquals("Unexpected certification cases", 0, campaign.getCase().size());
assertStateAndStage(campaign, CREATED, 0);
assertEquals("Unexpected # of stages", definition.getStageDefinition().size(), campaign.getStageDefinition().size());
assertDefinitionAndOwner(campaign, definition);
assertNull("Unexpected start time", campaign.getStart());
assertNull("Unexpected end time", campaign.getEnd());
PrismObject<AccessCertificationDefinitionType> def = getObject(AccessCertificationDefinitionType.class, definition.getOid());
assertApproximateTime("last campaign started", new Date(), def.asObjectable().getLastCampaignStartedTimestamp());
assertNull("unexpected last campaign closed", def.asObjectable().getLastCampaignClosedTimestamp());
}

protected void assertAfterStageOpen(AccessCertificationCampaignType campaign, AccessCertificationDefinitionType definition, int stageNumber) throws ConfigurationException, ObjectNotFoundException, SchemaException, CommunicationException, SecurityViolationException {
assertStateAndStage(campaign, IN_REVIEW_STAGE, stageNumber);
assertDefinitionAndOwner(campaign, definition);
assertApproximateTime("start time", new Date(), campaign.getStart());
assertNull("Unexpected end time", campaign.getEnd());
assertEquals("wrong # of defined stages", definition.getStageDefinition().size(), campaign.getStageDefinition().size());
assertEquals("wrong # of stages", stageNumber, campaign.getStage().size());
AccessCertificationStageType stage = CertCampaignTypeUtil.findStage(campaign, stageNumber);
assertEquals("wrong stage #", stageNumber, stage.getNumber());
assertApproximateTime("stage start", new Date(), stage.getStart());
assertNotNull("stage deadline", stage.getDeadline()); // too lazy to compute exact datetime
assertNull("unexpected stage end", stage.getEnd());
}


protected void assertStateAndStage(AccessCertificationCampaignType campaign, AccessCertificationCampaignStateType state, int stage) {
assertEquals("Unexpected campaign state", state, campaign.getState());
assertEquals("Unexpected stage number", stage, campaign.getStageNumber());
Expand Down Expand Up @@ -379,6 +397,7 @@ 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) {
List<AccessCertificationDecisionType> currentDecisions = getCurrentDecisions(_case, stageNumber, false);
assertEquals("wrong # of decisions for stage " + stageNumber, 1, currentDecisions.size());
Expand Down Expand Up @@ -410,7 +429,7 @@ protected void assertHistoricOutcome(AccessCertificationCaseType aCase, int stag
assertTrue("No outcome stored for stage #" + stageNumber + " in " + aCase, found);
}

protected void assertCaseOutcomes(AccessCertificationCaseType aCase, AccessCertificationResponseType... outcomes) {
protected void assertCaseHistoricOutcomes(AccessCertificationCaseType aCase, AccessCertificationResponseType... outcomes) {
for (int stage = 0; stage < outcomes.length; stage++) {
assertHistoricOutcome(aCase, stage+1, outcomes[stage]);
}
Expand Down Expand Up @@ -479,7 +498,7 @@ protected void assertAfterStageClose(AccessCertificationCampaignType campaign, A
assertNull("Unexpected end time", campaign.getEnd());
assertEquals("wrong # of stages", stageNumber, campaign.getStage().size());
AccessCertificationStageType stage = CertCampaignTypeUtil.getCurrentStage(campaign);
assertEquals("wrong stage #", 1, stage.getNumber());
assertEquals("wrong stage #", stageNumber, stage.getNumber());
assertApproximateTime("stage 1 start", new Date(), stage.getStart());
assertApproximateTime("stage 1 end", new Date(), stage.getStart());

Expand All @@ -504,4 +523,16 @@ private void checkCaseOutcomes(AccessCertificationCaseType aCase, AccessCertific
private AccessCertificationResponseType checkCaseStageOutcome(AccessCertificationCaseType aCase, int stageNumber) {
return CertCampaignTypeUtil.getStageOutcome(aCase, stageNumber).getOutcome();
}

// 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) {
AccessCertificationCaseType ccase = findCase(caseList, subjectOid, targetOid);
assertEquals("Wrong stage outcome in " + ccase, stageOutcome, ccase.getCurrentStageOutcome());
assertEquals("Wrong overall outcome in " + ccase, overallOutcome, ccase.getOverallOutcome());

if (completedStage != null) {
assertHistoricOutcome(ccase, completedStage, stageOutcome);
}
}
}
Expand Up @@ -36,10 +36,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationDecisionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationStageType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;
Expand All @@ -53,7 +50,6 @@
import static com.evolveum.midpoint.test.IntegrationTestTools.display;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType.CLOSED;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType.IN_REMEDIATION;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType.REVIEW_STAGE_DONE;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.F_ACTIVATION;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.F_TARGET_REF;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType.ACCEPT;
Expand Down Expand Up @@ -658,19 +654,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);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_COO_OID, NO_RESPONSE, NO_RESPONSE);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ROLE_CEO_OID, NO_RESPONSE, NO_RESPONSE);
checkCaseOutcome(caseList, USER_ADMINISTRATOR_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE);
checkCaseOutcome(caseList, USER_JACK_OID, ROLE_CEO_OID, REVOKE, REVOKE);
checkCaseOutcome(caseList, USER_JACK_OID, ORG_EROOT_OID, NO_RESPONSE, NO_RESPONSE);
}

private void checkCaseOutcome(List<AccessCertificationCaseType> caseList, String subjectOid, String targetOid,
AccessCertificationResponseType stageOutcome, AccessCertificationResponseType overallOutcome) {
AccessCertificationCaseType ccase = findCase(caseList, subjectOid, targetOid);
assertEquals("Wrong stage outcome in " + ccase, stageOutcome, ccase.getCurrentStageOutcome());
assertEquals("Wrong overall outcome in " + ccase, overallOutcome, ccase.getOverallOutcome());
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);
}

@Test
Expand Down

0 comments on commit aa5f68e

Please sign in to comment.