Skip to content

Commit

Permalink
Test for conditional normal user template mappings with several sources
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Aug 8, 2016
1 parent 0908aac commit f31607d
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
Expand Up @@ -162,9 +162,11 @@ public void test101ModifyUserEmployeeTypePirate() throws Exception {
deltas.add(userDelta);

// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);

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

Expand Down Expand Up @@ -1044,6 +1046,103 @@ private void assertOnDemandOrgAssigned(String orgName, PrismObject<UserType> use
assertHasOrg(user, org.getOid());
}

/**
* Setting employee type to THIEF is just one part of the condition to assign
* the Thief role. The role should not be assigned now.
*/
@Test
public void test170ModifyUserGuybrushEmployeeTypeThief() throws Exception {
final String TEST_NAME = "test170ModifyUserGuybrushEmployeeTypeThief";
TestUtil.displayTestTile(this, TEST_NAME);

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

PrismObject<UserType> userBefore = getUser(USER_GUYBRUSH_OID);
display("User before", userBefore);
assertAssignedNoRole(userBefore);

// WHEN
TestUtil.displayWhen(TEST_NAME);
modifyUserReplace(USER_GUYBRUSH_OID, UserType.F_EMPLOYEE_TYPE, task, result, "THIEF");

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

PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, null, task, result);
display("User after", userAfter);

assertAssignedNoRole(userAfter);
}

/**
* Setting honorificPrefix satisfies the condition to assign
* the Thief role.
*/
@Test
public void test172ModifyUserGuybrushHonorificPrefix() throws Exception {
final String TEST_NAME = "test172ModifyUserGuybrushHonorificPrefix";
TestUtil.displayTestTile(this, TEST_NAME);

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

PrismObject<UserType> userBefore = getUser(USER_GUYBRUSH_OID);
display("User before", userBefore);
assertAssignedNoRole(userBefore);

// WHEN
TestUtil.displayWhen(TEST_NAME);
modifyUserReplace(USER_GUYBRUSH_OID, UserType.F_HONORIFIC_PREFIX, task, result,
PrismTestUtil.createPolyString("Thf."));

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

PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, null, task, result);
display("User after", userAfter);

assertAssignedRole(userAfter, ROLE_THIEF_OID);
}

/**
* Removing honorificPrefix should make the condition false again, which should cause
* that Thief role is unassigned.
*/
@Test
public void test174ModifyUserGuybrushHonorificPrefixNone() throws Exception {
final String TEST_NAME = "test174ModifyUserGuybrushHonorificPrefixNone";
TestUtil.displayTestTile(this, TEST_NAME);

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

PrismObject<UserType> userBefore = getUser(USER_GUYBRUSH_OID);
display("User before", userBefore);
assertAssignedRole(userBefore, ROLE_THIEF_OID);

// WHEN
TestUtil.displayWhen(TEST_NAME);
modifyUserReplace(USER_GUYBRUSH_OID, UserType.F_HONORIFIC_PREFIX, task, result);

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

PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, null, task, result);
display("User after", userAfter);

assertAssignedNoRole(userAfter);
}

@Test
public void test200AddUserRapp() throws Exception {
final String TEST_NAME = "test200AddUserRapp";
Expand Down
Expand Up @@ -188,6 +188,39 @@
</condition>
</mapping>

<!-- similar mapping with assignmentTargetSearch and more sources -->
<mapping>
<trace>false</trace>
<authoritative>true</authoritative>
<source>
<path>employeeType</path>
</source>
<source>
<path>honorificPrefix</path>
</source>
<expression>
<assignmentTargetSearch>
<targetType>RoleType</targetType>
<filter>
<q:equal>
<q:path>name</q:path>
<q:value>Thief</q:value>
</q:equal>
</filter>
</assignmentTargetSearch>
</expression>
<target>
<path>assignment</path>
</target>
<condition>
<trace>false</trace>
<script>
<trace>false</trace>
<code>employeeType == 'THIEF' &amp;&amp; basic.stringify(honorificPrefix) == 'Thf.'</code>
</script>
</condition>
</mapping>

<!-- This is quite a stupid way how to add the same role for many values of user property.
A single mapping with a condition that has an '||' operator internally will be more efficient.
But this is using this way to check for situation in which the same value is added and removed at the same time. -->
Expand Down

0 comments on commit f31607d

Please sign in to comment.