Skip to content

Commit

Permalink
"Clever HR" test passing (MID-6080)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed May 20, 2020
1 parent 511d2d0 commit 0018422
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 26 deletions.
Expand Up @@ -97,8 +97,10 @@ public class TestMultiAccount extends AbstractInitializedModelIntegrationTest {
protected static final String ACCOUNT_ODRADE_FIRST_NAME = "Darwi";
protected static final String ACCOUNT_ODRADE_LAST_NAME = "Odrade";
protected static final String ACCOUNT_ODRADE_PERSONAL_NUMBER = "54321";
protected static final String ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR = "MS007";
protected static final String ACCOUNT_ODRADE_CONTRACT_NUMBER_APPRENTICE = "A007";
protected static final String ACCOUNT_ODRADE_CONTRACT_NUMBER_GUARDIAN = "G007";
protected static final String ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR = "MS007";
protected static final String OU_MOTHER_SCHOOL = "Mother School";
protected static final String OU_MOTHER_SUPERIOR_OFFICE = "Mother Superior Office";
protected static final String OU_SECURITY = "Security";

Expand All @@ -109,6 +111,7 @@ public class TestMultiAccount extends AbstractInitializedModelIntegrationTest {
private static final String PLANET_KAITAIN = "Kaitain";
private static final String PLANET_IX = "Ix";
private static final String PLANET_GINAZ = "Ginaz";
private static final String PLANET_WALLACH_IX = "Wallach IX";
private static final String PLANET_CHAPTERHOUSE = "Chapterhouse";
private static final String PLANET_ARRAKIS = "Arrakis";

Expand Down Expand Up @@ -660,19 +663,19 @@ public void test400ImportAccountsFromCleverHr() throws Exception {
* Import the first account. Nothing special here yet.
*/
@Test
public void test410ImportOdrade() throws Exception {
public void test410ImportOdradeApprentice() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();

DummyAccount account = new DummyAccount(ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR);
DummyAccount account = new DummyAccount(ACCOUNT_ODRADE_CONTRACT_NUMBER_APPRENTICE);
account.setEnabled(true);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_FIRST_NAME, ACCOUNT_ODRADE_FIRST_NAME);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_LAST_NAME, ACCOUNT_ODRADE_LAST_NAME);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_PERSONAL_NUMBER, ACCOUNT_ODRADE_PERSONAL_NUMBER);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_LOCATION, PLANET_CHAPTERHOUSE);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_LOCATION, PLANET_WALLACH_IX);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_PRIMARY, Collections.singleton(Boolean.TRUE));
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_OU, OU_MOTHER_SUPERIOR_OFFICE);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_OU, OU_MOTHER_SCHOOL);
getDummyResource(RESOURCE_DUMMY_CLEVER_HR_NAME).addAccount(account);

// Preconditions
Expand All @@ -689,14 +692,14 @@ public void test410ImportOdrade() throws Exception {
.displayWithProjections()
.assertGivenName(ACCOUNT_ODRADE_FIRST_NAME)
.assertFamilyName(ACCOUNT_ODRADE_LAST_NAME)
.assertEmployeeNumber(ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR)
.assertLocality(PLANET_CHAPTERHOUSE)
.assertOrganizationalUnits(OU_MOTHER_SUPERIOR_OFFICE)
.assertEmployeeNumber(ACCOUNT_ODRADE_CONTRACT_NUMBER_APPRENTICE)
.assertLocality(PLANET_WALLACH_IX)
.assertOrganizationalUnits(OU_MOTHER_SCHOOL)
.singleLink()
.resolveTarget()
.assertKind(ShadowKindType.ACCOUNT)
.assertIntent(SchemaConstants.INTENT_DEFAULT)
.assertTag(ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR);
.assertTag(ACCOUNT_ODRADE_CONTRACT_NUMBER_APPRENTICE);

assertUsers(getNumberOfUsers() + 3);

Expand Down Expand Up @@ -737,14 +740,13 @@ public void test420ImportOdradeGuardian() throws Exception {
.displayWithProjections()
.assertGivenName(ACCOUNT_ODRADE_FIRST_NAME)
.assertFamilyName(ACCOUNT_ODRADE_LAST_NAME)
// TODO
.assertLocality(PLANET_CHAPTERHOUSE)
// .assertEmployeeNumber(ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR)
.assertOrganizationalUnits(OU_MOTHER_SUPERIOR_OFFICE, OU_SECURITY)
.assertLocality(PLANET_WALLACH_IX)
.assertEmployeeNumber(ACCOUNT_ODRADE_CONTRACT_NUMBER_APPRENTICE)
.assertOrganizationalUnits(OU_MOTHER_SCHOOL, OU_SECURITY)
.links()
.assertLinks(2)
.by()
.tag(ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR)
.tag(ACCOUNT_ODRADE_CONTRACT_NUMBER_APPRENTICE)
.find()
.resolveTarget()
.assertKind(ShadowKindType.ACCOUNT)
Expand All @@ -764,6 +766,77 @@ public void test420ImportOdradeGuardian() throws Exception {

}

/**
* Promote Odrade to Mother Superior. The primary contract is changed in this case.
* User object should reflect data from the new primary contract.
*/
@Test
public void test430ImportOdradeMotherSuperior() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();

getDummyResource(RESOURCE_DUMMY_CLEVER_HR_NAME)
.getAccountByUsername(ACCOUNT_ODRADE_CONTRACT_NUMBER_APPRENTICE)
.replaceAttributeValue(CLEVER_HR_ATTRIBUTE_PRIMARY, Boolean.FALSE);

DummyAccount account = new DummyAccount(ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR);
account.setEnabled(true);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_FIRST_NAME, ACCOUNT_ODRADE_FIRST_NAME);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_LAST_NAME, ACCOUNT_ODRADE_LAST_NAME);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_PERSONAL_NUMBER, ACCOUNT_ODRADE_PERSONAL_NUMBER);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_LOCATION, PLANET_CHAPTERHOUSE);
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_PRIMARY, Collections.singleton(Boolean.TRUE));
account.addAttributeValues(CLEVER_HR_ATTRIBUTE_OU, OU_MOTHER_SUPERIOR_OFFICE);
getDummyResource(RESOURCE_DUMMY_CLEVER_HR_NAME).addAccount(account);

// Preconditions
assertUsers(getNumberOfUsers() + 3);

// WHEN
when();
importCleverHrAccounts(task, result);

// THEN
then();

assertUserAfterByUsername(USER_ODRADE_USERNAME)
.displayWithProjections()
.assertGivenName(ACCOUNT_ODRADE_FIRST_NAME)
.assertFamilyName(ACCOUNT_ODRADE_LAST_NAME)
.assertLocality(PLANET_CHAPTERHOUSE)
.assertEmployeeNumber(ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR)
.assertOrganizationalUnits(OU_MOTHER_SUPERIOR_OFFICE, OU_MOTHER_SCHOOL, OU_SECURITY)
.links()
.assertLinks(3)
.by()
.tag(ACCOUNT_ODRADE_CONTRACT_NUMBER_APPRENTICE)
.find()
.resolveTarget()
.assertKind(ShadowKindType.ACCOUNT)
.assertIntent(SchemaConstants.INTENT_DEFAULT)
.end()
.end()
.by()
.tag(ACCOUNT_ODRADE_CONTRACT_NUMBER_GUARDIAN)
.find()
.resolveTarget()
.assertKind(ShadowKindType.ACCOUNT)
.assertIntent(SchemaConstants.INTENT_DEFAULT)
.end()
.end()
.by()
.tag(ACCOUNT_ODRADE_CONTRACT_NUMBER_MOTHER_SUPERIOR)
.find()
.resolveTarget()
.assertKind(ShadowKindType.ACCOUNT)
.assertIntent(SchemaConstants.INTENT_DEFAULT)
.end()
.end();

assertUsers(getNumberOfUsers() + 3);
}

private void assertEnvoyAccounts(String userOid, String username, String... planets) throws SchemaException, ObjectNotFoundException, ConfigurationException, CommunicationException, SecurityViolationException, ExpressionEvaluationException, InterruptedException, FileNotFoundException, ConnectException, SchemaViolationException, ConflictException {
UserAsserter<Void> asserter = assertUserAfter(userOid)
.displayWithProjections()
Expand Down
6 changes: 3 additions & 3 deletions model/model-intest/src/test/resources/logback-test.xml
Expand Up @@ -65,7 +65,7 @@
<logger name="com.evolveum.midpoint.model.impl.lens.projector.mappings.MappingEvaluator" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.FocusActivationProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.AssignmentHolderProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.InboundProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.InboundProcessor" level="TRACE" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.FocusConstraintsChecker" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.FocusPolicyProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.ObjectTemplateProcessor" level="DEBUG" />
Expand Down Expand Up @@ -105,8 +105,8 @@
<logger name="com.evolveum.midpoint.model.common.expression.evaluator.AssignmentExpressionEvaluator" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.expression.evaluator.AssociationExpressionEvaluator" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyGenerator" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.expression.script" level="TRACE" />
<logger name="com.evolveum.midpoint.model.common.expression" level="TRACE" />
<logger name="com.evolveum.midpoint.model.common.expression.script" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.expression" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.controller.ObjectMerger" level="DEBUG" />
<logger name="com.evolveum.midpoint.notifications" level="DEBUG" />
<logger name="com.evolveum.midpoint.security" level="DEBUG" />
Expand Down
Expand Up @@ -68,9 +68,15 @@
<inbound>
<target>
<path>employeeNumber</path>
<set>
<condition>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
</condition>
</set>
</target>
<condition>
<trace>true</trace>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
Expand All @@ -82,9 +88,28 @@
<inbound>
<target>
<path>$focus/givenName</path>
<set>
<condition>
<script>
<code>
if (basic.getAttributeValue(projection, "primary")) {
// Primary account. We want to remove all values, except those given by this mapping.
// Which means that we want range to be "all".
// Therefore we return true for every value of the target set,
// which means that all values will be part of the range.
return true
} else {
// Non-primary account. We want to keep all existing values of target property (givenName).
// Which means that we want range to be "none".
// Therefore we return false for every value, which means no value will be part of the range.
return false
}
</code>
</script>
</condition>
</set>
</target>
<condition>
<trace>true</trace>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
Expand All @@ -96,9 +121,18 @@
<inbound>
<target>
<path>$focus/familyName</path>
<set>
<condition>
<script>
<code>
// Same thing as above, just written in a simpler form.
basic.getAttributeValue(projection, "primary")
</code>
</script>
</condition>
</set>
</target>
<condition>
<trace>true</trace>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
Expand All @@ -108,16 +142,20 @@
<expression>
<trace>true</trace>
<script>
<!-- Why this does not work?
lastName.toLowerCase() + iterationToken -->
<code>input.toLowerCase()</code>
</script>
</expression>
<target>
<path>$focus/name</path>
<set>
<condition>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
</condition>
</set>
</target>
<condition>
<trace>true</trace>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
Expand All @@ -141,6 +179,13 @@
<strength>strong</strength>
<target>
<path>locality</path>
<set>
<condition>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
</condition>
</set>
</target>
<condition>
<trace>true</trace>
Expand Down Expand Up @@ -171,7 +216,6 @@
<administrativeStatus>
<inbound>
<condition>
<trace>true</trace>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
Expand All @@ -181,7 +225,6 @@
<validFrom>
<inbound>
<condition>
<trace>true</trace>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
Expand All @@ -191,7 +234,6 @@
<validTo>
<inbound>
<condition>
<trace>true</trace>
<script>
<code>basic.getAttributeValue(projection, "primary")</code>
</script>
Expand Down

0 comments on commit 0018422

Please sign in to comment.