Skip to content

Commit

Permalink
Improving the village story test. Possible fix for absolute expressio…
Browse files Browse the repository at this point in the history
…ns (MID-1829)
  • Loading branch information
semancik committed Apr 15, 2014
1 parent 9d6a056 commit 409e5c6
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 18 deletions.
Expand Up @@ -273,11 +273,11 @@ private static <T,C extends Containerable> EqualsFilter<PrismPropertyDefinition<
// }

XNode valueXnode = xmap.get(KEY_FILTER_EQUALS_VALUE);

ItemDefinition itemDefinition = locateItemDefinition(valueXnode, itemPath, pcd, prismContext);

ItemDefinition itemDefinition = locateItemDefinition(valueXnode, itemPath, pcd, prismContext);

if (valueXnode != null) {

Item item = parseItem(valueXnode, itemName, itemDefinition, prismContext);
return EqualsFilter.createEqual(itemPath, (PrismProperty) item, matchingRule);

Expand Down
Expand Up @@ -886,6 +886,9 @@ public <T extends Containerable> ItemDefinition locateItemDefinition(

private ItemDefinition resolveDynamicItemDefinition(ItemDefinition parentDefinition, QName elementName,
XNode xnode) throws SchemaException {
if (xnode == null) {
return null;
}
QName typeName = xnode.getTypeQName();
if (typeName == null) {
if (xnode instanceof ListXNode) {
Expand Down
Expand Up @@ -124,6 +124,11 @@ protected List<V> transformSingleValue(ExpressionVariables variables, PlusMinusZ
ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result)
throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("transformSingleValue in {}\nvariables:\n{}\nvalueDestination: {}\nuseNew: {}",
new Object[]{contextDescription, variables.debugDump(1), valueDestination, useNew});
}

QName targetTypeQName = getExpressionEvaluatorType().getTargetType();
if (targetTypeQName == null) {
targetTypeQName = getDefaultTargetType();
Expand Down
Expand Up @@ -190,8 +190,14 @@ private PrismValueDeltaSetTriple<V> evaluateAbsoluteExpression(Collection<Source

if (hasDeltas(sources) || hasDelas(variables)) {

Collection<V> outputSetOld = evaluateScriptExpression(sources, variables, contextDescription, false, params, task, result);
Collection<V> outputSetNew = evaluateScriptExpression(sources, variables, contextDescription, true, params, task, result);
Collection<V> outputSetOld = null;
if (!params.isSkipEvaluationMinus()) {
outputSetOld = evaluateScriptExpression(sources, variables, contextDescription, false, params, task, result);
}
Collection<V> outputSetNew = null;
if (!params.isSkipEvaluationPlus()) {
outputSetNew = evaluateScriptExpression(sources, variables, contextDescription, true, params, task, result);
}

outputTriple = PrismValueDeltaSetTriple.diffPrismValueDeltaSetTriple(outputSetOld, outputSetNew);

Expand Down
Expand Up @@ -144,13 +144,13 @@ public <O extends ObjectType> void processAssignmentsProjections(LensContext<O>
// We can do this only for FocusType.
return;
}
processAssignmentsAccounts((LensContext<? extends FocusType>)context, now, task, result);
processAssignmentsProjectionsWithFocus((LensContext<? extends FocusType>)context, now, task, result);
}

/**
* Processing user-account assignments (including roles). Specific user-account method.
*/
public <F extends FocusType> void processAssignmentsAccounts(LensContext<F> context, XMLGregorianCalendar now,
private <F extends FocusType> void processAssignmentsProjectionsWithFocus(LensContext<F> context, XMLGregorianCalendar now,
Task task, OperationResult result) throws SchemaException,
ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, CommunicationException, ConfigurationException, SecurityViolationException {

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2014 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -109,7 +109,7 @@ public void test001OutboundEmpty() throws Exception {
context.recompute();

// WHEN
assignmentProcessor.processAssignmentsAccounts(context, getNow(), task, result);
assignmentProcessor.processAssignmentsProjections(context, getNow(), task, result);

// THEN
display("outbound processor result", result);
Expand Down Expand Up @@ -140,7 +140,7 @@ public void test002ModifyUser() throws Exception {
assertFocusModificationSanity(context);

// WHEN
assignmentProcessor.processAssignmentsAccounts(context, getNow(), task, result);
assignmentProcessor.processAssignmentsProjections(context, getNow(), task, result);

// THEN
display("Output context", context);
Expand Down Expand Up @@ -201,7 +201,7 @@ public void test011AddAssignmentAddAccountDirect() throws Exception {
assertFocusModificationSanity(context);

// WHEN
assignmentProcessor.processAssignmentsAccounts(context, getNow(), task, result);
assignmentProcessor.processAssignmentsProjections(context, getNow(), task, result);

// THEN
display("Output context", context);
Expand Down Expand Up @@ -243,7 +243,7 @@ public void test012AddAssignmentAddAccountDirectAssignmentWithAttrs() throws Exc
assertFocusModificationSanity(context);

// WHEN
assignmentProcessor.processAssignmentsAccounts(context, getNow(), task, result);
assignmentProcessor.processAssignmentsProjections(context, getNow(), task, result);

// THEN
display("Output context", context);
Expand Down Expand Up @@ -312,7 +312,7 @@ public void test021AddAssignmentModifyAccountAssignment() throws Exception {
assertFocusModificationSanity(context);

// WHEN
assignmentProcessor.processAssignmentsAccounts(context, getNow(), task, result);
assignmentProcessor.processAssignmentsProjections(context, getNow(), task, result);

// THEN
display("Output context", context);
Expand Down Expand Up @@ -412,7 +412,7 @@ public void test031DeleteAssignmentModifyAccount() throws Exception {
assertFocusModificationSanity(context);

// WHEN
assignmentProcessor.processAssignmentsAccounts(context, getNow(), task, result);
assignmentProcessor.processAssignmentsProjections(context, getNow(), task, result);

// THEN
display("Output context", context.dump(true));
Expand Down Expand Up @@ -501,7 +501,7 @@ public void test032ModifyUserLegalizeAccount() throws Exception {
assertFocusModificationSanity(context);

// WHEN
assignmentProcessor.processAssignmentsAccounts(context, getNow(), task, result);
assignmentProcessor.processAssignmentsProjections(context, getNow(), task, result);

context.recompute();
// THEN
Expand Down
Expand Up @@ -148,6 +148,8 @@ public class TestVillage extends AbstractStoryTest {
private static final String DUMMY_ACCOUNT_ATTRIBUTE_SRC_FIRST_NAME = "firstname";
private static final String DUMMY_ACCOUNT_ATTRIBUTE_SRC_LAST_NAME = "lastname";
private static final String DUMMY_ACCOUNT_ATTRIBUTE_SRC_TYPE = "type";
private static final String DUMMY_ACCOUNT_ATTRIBUTE_SRC_LOC = "loc";
private static final String DUMMY_ACCOUNT_ATTRIBUTE_SRC_ORG = "org";

public static final File ROLE_BASIC_FILE = new File(TEST_DIR, "role-basic.xml");
public static final String ROLE_BASIC_OID = "10000000-0000-0000-0000-000000000601";
Expand All @@ -159,11 +161,15 @@ public class TestVillage extends AbstractStoryTest {
private static final String ACCOUNT_HERMAN_USERNAME = "ht";
private static final String ACCOUNT_HERMAN_FIST_NAME = "Herman";
private static final String ACCOUNT_HERMAN_LAST_NAME = "Toothrot";
private static final String ACCOUNT_HERMAN_LOC = "Monkey Island";
private static final String ACCOUNT_HERMAN_ORG = "Gov";
private static final String USER_HERMAN_NAME = ACCOUNT_HERMAN_FIST_NAME+"."+ACCOUNT_HERMAN_LAST_NAME;

private static final String ACCOUNT_LEMONHEAD_USERNAME = "lemonhead";
private static final String ACCOUNT_LEMONHEAD_FIST_NAME = "Lemonhead";
private static final String ACCOUNT_LEMONHEAD_LAST_NAME = "Canibal";
private static final String ACCOUNT_LEMONHEAD_LOC = "Monkey Island";
private static final String ACCOUNT_LEMONHEAD_ORG = "Exec";
private static final String USER_LEMONHEAD_NAME = ACCOUNT_LEMONHEAD_FIST_NAME+"."+ACCOUNT_LEMONHEAD_LAST_NAME;

private static final String ACCOUNT_SHARPTOOTH_USERNAME = "sharptooth";
Expand Down Expand Up @@ -238,6 +244,8 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
dummyResourceCtlSrc.addAttrDef(dummyAdAccountObjectClass, DUMMY_ACCOUNT_ATTRIBUTE_SRC_FIRST_NAME, String.class, false, false);
dummyResourceCtlSrc.addAttrDef(dummyAdAccountObjectClass, DUMMY_ACCOUNT_ATTRIBUTE_SRC_LAST_NAME, String.class, false, false);
dummyResourceCtlSrc.addAttrDef(dummyAdAccountObjectClass, DUMMY_ACCOUNT_ATTRIBUTE_SRC_TYPE, String.class, false, false);
dummyResourceCtlSrc.addAttrDef(dummyAdAccountObjectClass, DUMMY_ACCOUNT_ATTRIBUTE_SRC_LOC, String.class, false, false);
dummyResourceCtlSrc.addAttrDef(dummyAdAccountObjectClass, DUMMY_ACCOUNT_ATTRIBUTE_SRC_ORG, String.class, false, false);
dummyResourceSrc = dummyResourceCtlSrc.getDummyResource();
resourceDummySrc = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_SOURCE_FILE, RESOURCE_DUMMY_SOURCE_OID, initTask, initResult);
resourceDummySrcType = resourceDummySrc.asObjectable();
Expand Down Expand Up @@ -286,6 +294,8 @@ public void test100AddSrcAccountHerman() throws Exception {
DummyAccount newAccount = new DummyAccount(ACCOUNT_HERMAN_USERNAME);
newAccount.addAttributeValue(DUMMY_ACCOUNT_ATTRIBUTE_SRC_FIRST_NAME, ACCOUNT_HERMAN_FIST_NAME);
newAccount.addAttributeValue(DUMMY_ACCOUNT_ATTRIBUTE_SRC_LAST_NAME, ACCOUNT_HERMAN_LAST_NAME);
newAccount.addAttributeValue(DUMMY_ACCOUNT_ATTRIBUTE_SRC_LOC, ACCOUNT_HERMAN_LOC);
newAccount.addAttributeValue(DUMMY_ACCOUNT_ATTRIBUTE_SRC_ORG, ACCOUNT_HERMAN_ORG);

// WHEN
dummyResourceSrc.addAccount(newAccount);
Expand All @@ -297,11 +307,21 @@ public void test100AddSrcAccountHerman() throws Exception {
display("User", user);
assertUser(user, user.getOid(), USER_HERMAN_NAME, ACCOUNT_HERMAN_FIST_NAME+" "+ACCOUNT_HERMAN_LAST_NAME,
ACCOUNT_HERMAN_FIST_NAME, ACCOUNT_HERMAN_LAST_NAME);
assertLocGov(user, ACCOUNT_HERMAN_LOC, ACCOUNT_HERMAN_ORG);
assertLinks(user, 1);
assertAccount(user, RESOURCE_DUMMY_SOURCE_OID);
assertAssignments(user, 0);
}

private void assertLocGov(PrismObject<UserType> user, String expLoc, String expOrg) {
UserType userType = user.asObjectable();
PrismAsserts.assertEqualsPolyString("Wrong locality in "+user, expLoc, userType.getLocality());
PrismAsserts.assertEqualsCollectionUnordered("Wrong organization in "+user, userType.getOrganization(),
PrismTestUtil.createPolyStringType(expOrg));
PrismAsserts.assertEqualsCollectionUnordered("Wrong organizationalUnit in "+user, userType.getOrganizationalUnit(),
PrismTestUtil.createPolyStringType(expOrg+":"+expLoc));
}

@Test
public void test102HermanAssignBasicRole() throws Exception {
final String TEST_NAME = "test102HermanAssignBasicRole";
Expand All @@ -316,6 +336,7 @@ public void test102HermanAssignBasicRole() throws Exception {
// THEN
PrismObject<UserType> userAfter = getUser(user.getOid());
assertUserLdap(userAfter, ACCOUNT_HERMAN_FIST_NAME, ACCOUNT_HERMAN_LAST_NAME);
assertLocGov(userAfter, ACCOUNT_HERMAN_LOC, ACCOUNT_HERMAN_ORG);
}

@Test
Expand All @@ -328,6 +349,8 @@ public void test110AddSrcAccountLemonhead() throws Exception {
newAccount.addAttributeValue(DUMMY_ACCOUNT_ATTRIBUTE_SRC_FIRST_NAME, ACCOUNT_LEMONHEAD_FIST_NAME);
newAccount.addAttributeValue(DUMMY_ACCOUNT_ATTRIBUTE_SRC_LAST_NAME, ACCOUNT_LEMONHEAD_LAST_NAME);
newAccount.addAttributeValue(DUMMY_ACCOUNT_ATTRIBUTE_SRC_TYPE, ROLE_BASIC_NAME);
newAccount.addAttributeValue(DUMMY_ACCOUNT_ATTRIBUTE_SRC_LOC, ACCOUNT_LEMONHEAD_LOC);
newAccount.addAttributeValue(DUMMY_ACCOUNT_ATTRIBUTE_SRC_ORG, ACCOUNT_LEMONHEAD_ORG);

// WHEN
dummyResourceSrc.addAccount(newAccount);
Expand All @@ -336,6 +359,7 @@ public void test110AddSrcAccountLemonhead() throws Exception {
// THEN
PrismObject<UserType> userAfter = findUserByUsername(USER_LEMONHEAD_NAME);
assertUserLdap(userAfter, ACCOUNT_LEMONHEAD_FIST_NAME, ACCOUNT_LEMONHEAD_LAST_NAME);
assertLocGov(userAfter, ACCOUNT_LEMONHEAD_LOC, ACCOUNT_LEMONHEAD_ORG);
}

private void assertUserLdap(PrismObject<UserType> userAfter, String firstName, String lastName) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException {
Expand Down
6 changes: 3 additions & 3 deletions testing/story/src/test/resources/logback-test.xml
Expand Up @@ -46,14 +46,14 @@
<logger name="com.evolveum.midpoint.model.lens.ChangeExecutor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.lens.ShadowConstraintsChecker" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.lens.LensUtil" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.expr" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.expr" level="TRACE" />
<logger name="com.evolveum.midpoint.model.util" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.sync" level="TRACE" />
<logger name="com.evolveum.midpoint.model.sync.CorrelationConfirmationEvaluator" level="TRACE" />
<logger name="com.evolveum.midpoint.provisioning" level="DEBUG" />
<logger name="com.evolveum.midpoint.expression" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.expression" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.expression.Expression" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.expression" level="TRACE" />
<logger name="com.evolveum.midpoint.model.common.expression.Expression" level="TRACE" />
<logger name="com.evolveum.midpoint.model.common.mapping" level="TRACE" />
<logger name="com.evolveum.midpoint.common.monitor" level="DEBUG" />
<logger name="com.evolveum.midpoint.notifications" level="DEBUG" />
Expand Down
26 changes: 26 additions & 0 deletions testing/story/src/test/resources/village/object-template-user.xml
Expand Up @@ -48,6 +48,7 @@
</mapping>

<mapping>
<name>full name</name>
<source>
<path>$user/givenName</path>
</source>
Expand Down Expand Up @@ -95,4 +96,29 @@
</target>
</mapping>


<mapping>
<name>OU</name>
<source>
<path>locality</path>
</source>
<source>
<path>organization</path>
</source>
<expression>
<script>
<code>
organization + ':' + locality
</code>
</script>
</expression>
<target>
<path>organizationalUnit</path>
</target>
<condition>
<script>
<code>organization != null &amp;&amp; locality != null</code>
</script>
</condition>
</mapping>
</objectTemplate>
16 changes: 16 additions & 0 deletions testing/story/src/test/resources/village/resource-dummy-source.xml
Expand Up @@ -97,6 +97,22 @@
</target>
</inbound>
</attribute>
<attribute>
<ref>ri:loc</ref>
<inbound>
<target>
<path>locality</path>
</target>
</inbound>
</attribute>
<attribute>
<ref>ri:org</ref>
<inbound>
<target>
<path>organization</path>
</target>
</inbound>
</attribute>

<activation>
<administrativeStatus>
Expand Down
25 changes: 25 additions & 0 deletions testing/story/src/test/resources/village/role-basic.xml
Expand Up @@ -18,6 +18,8 @@
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-2a"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-2a"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-2"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-2"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-2"
xmlns:piracy="http://midpoint.evolveum.com/xml/ns/samples/piracy">
<name>Basic</name>

Expand All @@ -26,6 +28,29 @@
<!-- OpenDJ resource -->
<resourceRef oid="10000000-0000-0000-0000-000000000003" type="c:ResourceType"/>
<kind>account</kind>
<association>
<ref>ri:group</ref>
<outbound>
<expression>
<associationTargetSearch>
<filter>
<q:equal>
<q:path>
declare namespace icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-2";
attributes/icfs:name
</q:path>
<expression>
<script>
<code>'cn='+user.getOrganizationalUnit()+',ou=groups,dc=example,dc=com'</code>
</script>
</expression>
</q:equal>
</filter>
<searchOnResource>true</searchOnResource>
</associationTargetSearch>
</expression>
</outbound>
</association>
</construction>
</inducement>

Expand Down

0 comments on commit 409e5c6

Please sign in to comment.