Skip to content

Commit

Permalink
Add a couple of tests for MID-5846
Browse files Browse the repository at this point in the history
(Fortunately, all of them pass. So this issue seems to be already
fixed.)
  • Loading branch information
mederly committed Mar 31, 2020
1 parent ac56df8 commit 0f44c91
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 27 deletions.
Expand Up @@ -15,6 +15,7 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.asserter.UserAsserter;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
Expand All @@ -25,6 +26,7 @@

import java.io.File;
import java.util.Arrays;
import java.util.Collections;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -196,15 +198,25 @@ public void test200ImportFromResourceAssociations() throws Exception {
SearchResultList<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, null, task, result);
display("Users after import", users);

PrismObject<UserType> userHermanAfter = findUserByUsername(USER_HERMAN_USERNAME);
display("User after", userHermanAfter);
userHermanOid = userHermanAfter.getOid();
assertUser(userHermanAfter, userHermanAfter.getOid(), USER_HERMAN_USERNAME, USER_HERMAN_FULL_NAME, null, null);
assertAssignedRole(userHermanAfter, ROLE_AUTODIDACTIC_OID);
assertAssignedRole(userHermanAfter, ROLE_AUTOGRAPHIC_OID);
assertAssignedRole(userHermanAfter, ROLE_AUTOTESTERS_OID);
assertAssignedRole(userHermanAfter, ROLE_AUTOCRATIC_OID);
assertAssignments(userHermanAfter, 4);
UserAsserter<Void> userAsserter = assertUserAfterByUsername(USER_HERMAN_USERNAME);
userHermanOid = userAsserter.getOid();
PrismObject<UserType> userAfter = userAsserter.getObject();
assertUser(userAfter, userHermanOid, USER_HERMAN_USERNAME, USER_HERMAN_FULL_NAME, null, null);
userAsserter
.assignments()
.forRole(ROLE_AUTODIDACTIC_OID)
.assertOriginMappingName("Assignment from title") // MID-5846
.end()
.forRole(ROLE_AUTOGRAPHIC_OID)
.assertOriginMappingName("Assignment from title") // MID-5846
.end()
.forRole(ROLE_AUTOTESTERS_OID)
.assertOriginMappingName("Assignment from group") // MID-5846
.end()
.forRole(ROLE_AUTOCRATIC_OID)
.assertOriginMappingName("Assignment from group") // MID-5846
.end()
.assertAssignments(4);

assertEquals("Unexpected number of users", getNumberOfUsers() + 1, users.size());
}
Expand Down Expand Up @@ -246,7 +258,7 @@ public void test301removeUserFromAutoGroup() throws Exception {
craticGroup.removeMember(USER_HERMAN_USERNAME);

DummyAccount hermanAccount = getDummyAccount(RESOURCE_DUMMY_AUTOGREEN_NAME, USER_HERMAN_USERNAME);
hermanAccount.removeAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, Arrays.asList("didactic"));
hermanAccount.removeAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, Collections.singletonList("didactic"));

assertNoDummyGroupMember(RESOURCE_DUMMY_AUTOGREEN_NAME, GROUP_DUMMY_CRATIC_NAME, USER_HERMAN_USERNAME);

Expand Down
Expand Up @@ -20,6 +20,8 @@

import com.evolveum.midpoint.prism.path.ItemPath;

import com.evolveum.midpoint.test.TestResource;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -78,6 +80,11 @@ public class TestMappingInbound extends AbstractMappingTest {
private static final ItemName VALUE = new ItemName(NS_PIRACY, "value");

private static final String DUMMY_ACCOUNT_ATTRIBUTE_CONTROLLER_NAME = "controllerName";
private static final String DUMMY_ACCOUNT_ATTRIBUTE_ROLE_NAME = "roleName";
private static final String DUMMY_ACCOUNT_ATTRIBUTE_ARCHETYPE_NAME = "archetypeName";

private static final TestResource ROLE_SIMPLE = new TestResource(TEST_DIR, "role-simple.xml", "dc2b28f4-3aab-4212-8ab7-c4f5fc0c511a");
private static final TestResource ARCHETYPE_PIRATE = new TestResource(TEST_DIR, "archetype-pirate.xml", "0bb1d8df-501d-4648-9d36-c8395df95183");

private ProtectedStringType mancombLocker;
private String userLeelooOid;
Expand All @@ -87,6 +94,9 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
super.initSystem(initTask, initResult);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

repoAdd(ROLE_SIMPLE, initResult);
repoAdd(ARCHETYPE_PIRATE, initResult);

initDummyResource(RESOURCE_DUMMY_TEA_GREEN_NAME, RESOURCE_DUMMY_TEA_GREEN_FILE, RESOURCE_DUMMY_TEA_GREEN_OID,
controller -> {
controller.extendSchemaPirate();
Expand All @@ -99,6 +109,10 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
DUMMY_ACCOUNT_ATTRIBUTE_TREASON_RISK_NAME, Integer.class, false, false);
controller.addAttrDef(controller.getDummyResource().getAccountObjectClass(),
DUMMY_ACCOUNT_ATTRIBUTE_CONTROLLER_NAME, String.class, false, false);
controller.addAttrDef(controller.getDummyResource().getAccountObjectClass(),
DUMMY_ACCOUNT_ATTRIBUTE_ROLE_NAME, String.class, false, true);
controller.addAttrDef(controller.getDummyResource().getAccountObjectClass(),
DUMMY_ACCOUNT_ATTRIBUTE_ARCHETYPE_NAME, String.class, false, false);
controller.setSyncStyle(DummySyncStyle.SMART);
},
initTask, initResult);
Expand All @@ -122,7 +136,7 @@ public void test010SanitySchema() throws Exception {
displayDumpable("Parsed resource schema (tea-green)", returnedSchema);
ObjectClassComplexTypeDefinition accountDef = getDummyResourceController(RESOURCE_DUMMY_TEA_GREEN_NAME)
.assertDummyResourceSchemaSanityExtended(returnedSchema, resourceType, false,
DummyResourceContoller.PIRATE_SCHEMA_NUMBER_OF_DEFINITIONS + 4); // MID-5197
DummyResourceContoller.PIRATE_SCHEMA_NUMBER_OF_DEFINITIONS + 6); // MID-5197

ResourceAttributeDefinition<ProtectedStringType> lockerDef = accountDef.findAttributeDefinition(DUMMY_ACCOUNT_ATTRIBUTE_LOCKER_NAME);
assertNotNull("No locker attribute definition", lockerDef);
Expand Down Expand Up @@ -153,6 +167,8 @@ public void test110AddDummyTeaGreenAccountMancomb() throws Exception {
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Melee Island");
account.addAttributeValues(DUMMY_ACCOUNT_ATTRIBUTE_LOCKER_NAME, LOCKER_BIG_SECRET); // MID-5197
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "water");
account.addAttributeValues(DUMMY_ACCOUNT_ATTRIBUTE_ROLE_NAME, "simple");
account.addAttributeValues(DUMMY_ACCOUNT_ATTRIBUTE_ARCHETYPE_NAME, "pirate");

/// WHEN
when();
Expand All @@ -172,20 +188,32 @@ public void test110AddDummyTeaGreenAccountMancomb() throws Exception {
assertShadowOperationalData(accountMancomb, SynchronizationSituationType.LINKED, null);

UserAsserter<Void> mancombUserAsserter = assertUserAfterByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME);
// @formatter:off
mancombLocker = mancombUserAsserter
.links()
.single()
.assertOid(accountMancomb.getOid())
.end()
.end()
.single()
.assertOid(accountMancomb.getOid())
.end()
.end()
.assertAdministrativeStatus(ActivationStatusType.ENABLED)
.assignments()
.forRole(ROLE_SIMPLE.oid)
.assertSubtype("auto-role")
.assertOriginMappingName("Role by name") // MID-5846
.end()
.forArchetype(ARCHETYPE_PIRATE.oid)
.assertSubtype("auto-archetype")
.assertOriginMappingName("Archetype by name") // MID-5846
.end()
.end()
.extension()
.property(PIRACY_LOCKER)
.singleValue()
.protectedString()
.assertIsEncrypted()
.assertCompareCleartext(LOCKER_BIG_SECRET)
.getProtectedString();
.property(PIRACY_LOCKER)
.singleValue()
.protectedString()
.assertIsEncrypted()
.assertCompareCleartext(LOCKER_BIG_SECRET)
.getProtectedString();
// @formatter:on

assertJpegPhoto(UserType.class, mancombUserAsserter.getOid(), "water".getBytes(StandardCharsets.UTF_8), result);
// assertUsers(6);
Expand Down
Expand Up @@ -96,6 +96,7 @@ public void test100ModifyUnitWorker() throws Exception {
.single()
.assertTargetOid(ROLE_UNIT_WORKER_OID)
.assertTargetType(RoleType.COMPLEX_TYPE)
.assertOriginMappingName("autoassign-worker") // MID-5846
.end()
.end()
.links()
Expand Down Expand Up @@ -155,11 +156,14 @@ public void test110ModifyUnitSleepwalker() throws Exception {
.targetOid(ROLE_UNIT_SLEEPER_OID)
.find()
.assertTargetType(RoleType.COMPLEX_TYPE)
.assertOriginMappingName("autoassign-sleeper") // MID-5846
.activation()
.assertValidTo(ROLE_SLEEPER_AUTOASSIGN_VALID_TO)
.end()
.end()
.assertRole(ROLE_UNIT_WALKER_OID)
.forRole(ROLE_UNIT_WALKER_OID)
.assertOriginMappingName("autoassign-walker") // MID-5846
.end()
.end()
.links()
.single();
Expand Down
11 changes: 11 additions & 0 deletions model/model-intest/src/test/resources/mapping/archetype-pirate.xml
@@ -0,0 +1,11 @@
<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<archetype xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="0bb1d8df-501d-4648-9d36-c8395df95183">
<name>pirate</name>
</archetype>
Expand Up @@ -80,6 +80,7 @@
<attribute>
<ref>ri:title</ref>
<inbound>
<name>Assignment from title</name>
<strength>strong</strength>
<expression>
<assignmentTargetSearch>
Expand Down Expand Up @@ -137,6 +138,7 @@
<association>
<ref>ri:group</ref>
<inbound>
<name>Assignment from group</name>
<authoritative>true</authoritative>
<strength>strong</strength>
<expression>
Expand Down Expand Up @@ -208,7 +210,6 @@
<valueAttribute>icfs:name</valueAttribute>
</association>


<activation>
<administrativeStatus>
<inbound/>
Expand Down Expand Up @@ -257,7 +258,6 @@
<objectClass>ri:CustomprivilegeObjectClass</objectClass>
</objectType>


</schemaHandling>

<projection>
Expand Down
Expand Up @@ -208,7 +208,83 @@ An authoritative resource, used to test for MID-2100 (inbound mappings acting bo
</condition>
</inbound>
</attribute>

<!-- MID-5846 -->
<attribute>
<ref>ri:roleName</ref>
<inbound>
<name>Role by name</name>
<strength>strong</strength>
<expression>
<assignmentTargetSearch>
<targetType>RoleType</targetType>
<filter>
<q:equal>
<q:path>name</q:path>
<expression>
<script>
<code>input</code>
</script>
</expression>
</q:equal>
</filter>
<assignmentProperties>
<subtype>auto-role</subtype>
</assignmentProperties>
</assignmentTargetSearch>
</expression>
<target>
<path>assignment</path>
<set>
<condition>
<script>
<code>assignment?.subtype?.contains('auto-role')</code>
</script>
</condition>
</set>
</target>
</inbound>
</attribute>
<!-- MID-5846 -->
<attribute>
<ref>ri:archetypeName</ref>
<inbound>
<name>Archetype by name</name>
<strength>strong</strength>
<expression>
<assignmentTargetSearch>
<targetType>ArchetypeType</targetType>
<filter>
<q:equal>
<q:path>name</q:path>
<expression>
<script>
<code>input</code>
</script>
</expression>
</q:equal>
</filter>
<assignmentProperties>
<subtype>auto-archetype</subtype>
</assignmentProperties>
</assignmentTargetSearch>
</expression>
<target>
<path>assignment</path>
<set>
<condition>
<script>
<code>assignment?.subtype?.contains('auto-archetype')</code>
</script>
</condition>
</set>
</target>
<condition>
<script>
<code>input != null</code>
</script>
</condition>
</inbound>
</attribute>
<iteration>
<maxIterations>5</maxIterations>
</iteration>
Expand Down
11 changes: 11 additions & 0 deletions model/model-intest/src/test/resources/mapping/role-simple.xml
@@ -0,0 +1,11 @@
<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<role xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="dc2b28f4-3aab-4212-8ab7-c4f5fc0c511a">
<name>simple</name>
</role>
Expand Up @@ -28,7 +28,7 @@
<enabled>true</enabled>
<focus>
<mapping>
<name>autoassign-worker</name>
<name>autoassign-sleeper</name>
<trace>true</trace>
<source>
<path>organizationalUnit</path>
Expand Down
Expand Up @@ -28,7 +28,7 @@
<enabled>true</enabled>
<focus>
<mapping>
<name>autoassign-worker</name>
<name>autoassign-walker</name>
<trace>true</trace>
<source>
<path>organizationalUnit</path>
Expand Down
Expand Up @@ -84,6 +84,15 @@ public AssignmentAsserter<R> assertSubtype(String expected) {
return this;
}

public AssignmentAsserter<R> assertOriginMappingName(String expected) {
assertEquals("Wrong origin mapping name", expected, getOriginMappingName());
return this;
}

private String getOriginMappingName() {
return assignment.getMetadata() != null ? assignment.getMetadata().getOriginMappingName() : null;
}

public ActivationAsserter<AssignmentAsserter<R>> activation() {
ActivationAsserter<AssignmentAsserter<R>> asserter = new ActivationAsserter<>(assignment.getActivation(), this, getDetails());
copySetupTo(asserter);
Expand Down
Expand Up @@ -97,6 +97,13 @@ public AssignmentAsserter<AssignmentsAsserter<F,FA,RA>> forRole(String roleOid)
.find();
}

public AssignmentAsserter<AssignmentsAsserter<F,FA,RA>> forArchetype(String archetypeOid) throws ObjectNotFoundException, SchemaException {
return by()
.targetOid(archetypeOid)
.targetType(ArchetypeType.COMPLEX_TYPE)
.find();
}

public AssignmentsAsserter<F,FA,RA> assertRole(String roleOid) throws ObjectNotFoundException, SchemaException {
by()
.targetOid(roleOid)
Expand Down

0 comments on commit 0f44c91

Please sign in to comment.