Skip to content

Commit

Permalink
Test for MID-1783 - and it passes!
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed May 23, 2014
1 parent bc63069 commit 31649f0
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 2 deletions.
Expand Up @@ -158,9 +158,12 @@ public class AbstractConfiguredModelIntegrationTest extends AbstractModelIntegra
protected static final String ROLE_CAPTAIN_OID = "12345678-d34d-b33f-f00d-55555555cccc";

// Excludes role "pirate"
protected static final String ROLE_JUDGE_FILENAME = COMMON_DIR_NAME + "/role-judge.xml";
protected static final File ROLE_JUDGE_FILE = new File(COMMON_DIR, "role-judge.xml");
protected static final String ROLE_JUDGE_OID = "12345111-1111-2222-1111-121212111111";

protected static final File ROLE_EMPTY_FILE = new File(COMMON_DIR, "role-empty.xml");
protected static final String ROLE_EMPTY_OID = "12345111-1111-2222-1111-121212111112";

protected static final File USER_JACK_FILE = new File(COMMON_DIR_NAME, "user-jack.xml");
protected static final String USER_JACK_OID = "c0c010c0-d34d-b33f-f00d-111111111111";
protected static final String USER_JACK_USERNAME = "jack";
Expand Down
Expand Up @@ -232,7 +232,8 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
repoAddObjectFromFile(ROLE_PIRATE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_NICE_PIRATE_FILENAME, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_CAPTAIN_FILENAME, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_JUDGE_FILENAME, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_JUDGE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_EMPTY_FILE, RoleType.class, initResult);

// Orgstruct
if (doAddOrgstruct()) {
Expand Down
Expand Up @@ -1183,5 +1183,138 @@ public void test703JackModifyJudgeDeleteInducementHonorabilityRecompute() throws
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, false);
assertDummyAccountAttribute(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Honorable");
}

@Test
public void test709JackUnAssignRoleJudge() throws Exception {
final String TEST_NAME = "test709JackUnAssignRoleJudge";
TestUtil.displayTestTile(this, TEST_NAME);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User jack before", userBefore);

// WHEN
TestUtil.displayWhen(TEST_NAME);
unassignRole(USER_JACK_OID, ROLE_JUDGE_OID, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertAssignedNoRole(USER_JACK_OID, task, result);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}

@Test
public void test710JackAssignRoleEmpty() throws Exception {
final String TEST_NAME = "test710JackAssignRoleEmpty";
TestUtil.displayTestTile(this, TEST_NAME);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User jack before", userBefore);

// WHEN
TestUtil.displayWhen(TEST_NAME);
assignRole(USER_JACK_OID, ROLE_EMPTY_OID, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertAssignedRole(USER_JACK_OID, ROLE_EMPTY_OID, task, result);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}

@Test
public void test712JackModifyEmptyRoleAddInducementPirateRecompute() throws Exception {
final String TEST_NAME = "test712JackModifyEmptyRoleAddInducementPirateRecompute";
TestUtil.displayTestTile(this, TEST_NAME);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User jack before", userBefore);

modifyRoleAddInducementTarget(ROLE_EMPTY_OID, ROLE_PIRATE_OID);

// WHEN
TestUtil.displayWhen(TEST_NAME);
recomputeUser(USER_JACK_OID, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertAssignedRole(USER_JACK_OID, ROLE_EMPTY_OID, task, result);

assertDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "cutlass");
}

@Test
public void test714JackModifyEmptyRoleDeleteInducementPirateRecompute() throws Exception {
final String TEST_NAME = "test714JackModifyEmptyRoleDeleteInducementPirateRecompute";
TestUtil.displayTestTile(this, TEST_NAME);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User jack before", userBefore);

modifyRoleDeleteInducementTarget(ROLE_EMPTY_OID, ROLE_PIRATE_OID);

// WHEN
TestUtil.displayWhen(TEST_NAME);
recomputeUser(USER_JACK_OID, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertAssignedRole(USER_JACK_OID, ROLE_EMPTY_OID, task, result);

assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}

@Test
public void test719JackUnAssignRoleEmpty() throws Exception {
final String TEST_NAME = "test719JackUnAssignRoleEmpty";
TestUtil.displayTestTile(this, TEST_NAME);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User jack before", userBefore);

// WHEN
TestUtil.displayWhen(TEST_NAME);
unassignRole(USER_JACK_OID, ROLE_EMPTY_OID, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertAssignedNoRole(USER_JACK_OID, task, result);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}

}
23 changes: 23 additions & 0 deletions model/model-intest/src/test/resources/common/role-empty.xml
@@ -0,0 +1,23 @@
<!--
~ Copyright (c) 2014 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<role oid="12345111-1111-2222-1111-121212111112"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004"
xmlns:piracy="http://midpoint.evolveum.com/xml/ns/samples/piracy">
<name>Empty</name>
</role>

0 comments on commit 31649f0

Please sign in to comment.