Skip to content

Commit

Permalink
Focus iteration tests (still work in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 27, 2014
1 parent 3c547ea commit 267dfad
Show file tree
Hide file tree
Showing 6 changed files with 370 additions and 6 deletions.
Expand Up @@ -289,7 +289,7 @@ private <F extends FocusType> void applyUserTemplate(LensContext<F> context, XML
ObjectDelta<F> userSecondaryDelta = focusContext.getProjectionWaveSecondaryDelta();
ObjectDelta<F> userPrimaryDelta = focusContext.getProjectionWavePrimaryDelta();
ObjectDeltaObject<F> userOdo = focusContext.getObjectDeltaObject();
PrismObjectDefinition<F> userDefinition = getFocusDefinition(focusContext.getObjectTypeClass());
PrismObjectDefinition<F> focusDefinition = getFocusDefinition(focusContext.getObjectTypeClass());
Collection<ItemDelta<? extends PrismValue>> itemDeltas = null;
XMLGregorianCalendar nextRecomputeTime = null;

Expand Down Expand Up @@ -318,11 +318,11 @@ private <F extends FocusType> void applyUserTemplate(LensContext<F> context, XML
ItemDelta<? extends PrismValue> apropriItemDelta = null;

ItemDelta<? extends PrismValue> itemDelta = LensUtil.consolidateTripleToDelta(itemPath, (DeltaSetTriple)outputTriple,
userDefinition.findItemDefinition(itemPath), apropriItemDelta, userOdo.getNewObject(), null,
true, true, false, "user template "+userTemplate, true);
focusDefinition.findItemDefinition(itemPath), apropriItemDelta, userOdo.getNewObject(), null,
true, true, false, "object template "+userTemplate, true);

itemDelta.simplify();
itemDelta.validate("user template "+userTemplate);
itemDelta.validate("object template "+userTemplate);
itemDeltas.add(itemDelta);
}

Expand All @@ -342,8 +342,13 @@ private <F extends FocusType> void applyUserTemplate(LensContext<F> context, XML
for (ItemDelta<? extends PrismValue> itemDelta: itemDeltas) {
previewDelta.addModification(itemDelta.clone());
}
if (previewBase == null) {
previewBase = focusDefinition.instantiate();
}
LOGGER.trace("previewDelta={}, previewBase={}", previewDelta, previewBase);
previewObjectNew = previewDelta.computeChangedObject(previewBase);
}
LOGGER.trace("previewObjectNew={}, itemDeltas={}", previewObjectNew, itemDeltas);

if (previewObjectNew == null) {
// this must be delete
Expand All @@ -367,7 +372,8 @@ private <F extends FocusType> void applyUserTemplate(LensContext<F> context, XML
LOGGER.trace("Current focus satisfies uniqueness constraints. Iteration {}, token '{}'", iteration, iterationToken);
break;
}
LOGGER.trace("Current focus does not satisfy constraints. Conflicting object: {}", checker.getConflictingObject());
LOGGER.trace("Current focus does not satisfy constraints. Conflicting object: {}; iteration={}, maxIterations={}",
new Object[]{checker.getConflictingObject(), iteration, maxIterations});

// Next iteration
iteration++;
Expand Down
Expand Up @@ -15,6 +15,8 @@
*/
package com.evolveum.midpoint.model.intest;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static com.evolveum.midpoint.test.IntegrationTestTools.display;

import java.io.File;
Expand All @@ -28,6 +30,7 @@

import com.evolveum.icf.dummy.resource.DummyAccount;
import com.evolveum.icf.dummy.resource.DummyResource;
import com.evolveum.icf.dummy.resource.DummySyncStyle;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
Expand All @@ -38,6 +41,11 @@
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.ResourceType;
Expand Down Expand Up @@ -67,10 +75,21 @@ public class TestIteration extends AbstractInitializedModelIntegrationTest {
protected static final String RESOURCE_DUMMY_VIOLET_NAME = "violet";
protected static final String RESOURCE_DUMMY_VIOLET_NAMESPACE = MidPointConstants.NS_RI;

protected static final File RESOURCE_DUMMY_DARK_VIOLET_FILE = new File(TEST_DIR, "resource-dummy-dark-violet.xml");
protected static final String RESOURCE_DUMMY_DARK_VIOLET_OID = "10000000-0000-0000-0000-0000000da204";
protected static final String RESOURCE_DUMMY_DARK_VIOLET_NAME = "darkViolet";
protected static final String RESOURCE_DUMMY_DARK_VIOLET_NAMESPACE = MidPointConstants.NS_RI;

protected static final File RESOURCE_DUMMY_MAGENTA_FILE = new File(TEST_DIR, "resource-dummy-magenta.xml");
protected static final String RESOURCE_DUMMY_MAGENTA_OID = "10000000-0000-0000-0000-00000000a304";
protected static final String RESOURCE_DUMMY_MAGENTA_NAME = "magenta";
protected static final String RESOURCE_DUMMY_MAGENTA_NAMESPACE = MidPointConstants.NS_RI;

protected static final File TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_FILE = new File(TEST_DIR, "task-dumy-dark-violet-livesync.xml");
protected static final String TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_OID = "10000000-0000-0000-5555-555500da0204";

protected static final File USER_TEMPLATE_ITERATION_FILE = new File(TEST_DIR, "user-template-iteration.xml");
protected static final String USER_TEMPLATE_ITERATION_OID = "10000000-0000-0000-0000-0000000d0002";

private static final String USER_LECHUCK_NAME = "lechuck";
private static final String ACCOUNT_CHARLES_NAME = "charles";
Expand All @@ -81,6 +100,11 @@ public class TestIteration extends AbstractInitializedModelIntegrationTest {
private static final String DESCRIPTION_RUM = "Where's the rum?";

private static final String USER_JACK_RENAMED_NAME = "cptjack";

private static final String ACCOUNT_LECHUCK_USERNAME = "lechuck";
private static final String ACCOUNT_LECHUCK_FULLNAME = "LeChuck";
private static final String ACCOUNT_CHARLES_USERNAME = "charles";
private static final String ACCOUNT_SHINETOP_USERNAME = "charles";

protected static DummyResource dummyResourcePink;
protected static DummyResourceContoller dummyResourceCtlPink;
Expand All @@ -92,6 +116,11 @@ public class TestIteration extends AbstractInitializedModelIntegrationTest {
protected ResourceType resourceDummyVioletType;
protected PrismObject<ResourceType> resourceDummyViolet;

protected static DummyResource dummyResourceDarkViolet;
protected static DummyResourceContoller dummyResourceCtlDarkViolet;
protected ResourceType resourceDummyDarkVioletType;
protected PrismObject<ResourceType> resourceDummyDarkViolet;

protected static DummyResource dummyResourceMagenta;
protected static DummyResourceContoller dummyResourceCtlMagenta;
protected ResourceType resourceDummyMagentaType;
Expand All @@ -115,13 +144,23 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
resourceDummyVioletType = resourceDummyViolet.asObjectable();
dummyResourceCtlViolet.setResource(resourceDummyViolet);

dummyResourceCtlDarkViolet = DummyResourceContoller.create(RESOURCE_DUMMY_DARK_VIOLET_NAME, resourceDummyViolet);
dummyResourceCtlDarkViolet.extendSchemaPirate();
dummyResourceDarkViolet = dummyResourceCtlDarkViolet.getDummyResource();
resourceDummyDarkViolet = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_DARK_VIOLET_FILE, RESOURCE_DUMMY_DARK_VIOLET_OID, initTask, initResult);
resourceDummyDarkVioletType = resourceDummyDarkViolet.asObjectable();
dummyResourceCtlDarkViolet.setResource(resourceDummyDarkViolet);
dummyResourceDarkViolet.setSyncStyle(DummySyncStyle.SMART);

dummyResourceCtlMagenta = DummyResourceContoller.create(RESOURCE_DUMMY_MAGENTA_NAME, resourceDummyMagenta);
dummyResourceCtlMagenta.extendSchemaPirate();
dummyResourceMagenta = dummyResourceCtlMagenta.getDummyResource();
resourceDummyMagenta = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_MAGENTA_FILE, RESOURCE_DUMMY_MAGENTA_OID, initTask, initResult);
resourceDummyMagentaType = resourceDummyMagenta.asObjectable();
dummyResourceCtlMagenta.setResource(resourceDummyMagenta);

addObject(USER_TEMPLATE_ITERATION_FILE);

assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
}

Expand Down Expand Up @@ -1004,4 +1043,86 @@ public void test600JackRename() throws Exception {
dummyAuditService.asserHasDelta(ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}

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

// WHEN
importObjectFromFile(TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_FILE);

// THEN
waitForTaskStart(TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_OID, false);
}

/*
* Create account with fullname LeChuck. User with name LeChuck should be created (no conflict yet).
*/
@Test
public void test710DarkVioletAddLeChuck() throws Exception {
final String TEST_NAME = "test710DarkVioletAddLeChuck";
TestUtil.displayTestTile(this, TEST_NAME);

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

DummyAccount account = new DummyAccount(ACCOUNT_LECHUCK_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, ACCOUNT_LECHUCK_FULLNAME);

// WHEN
TestUtil.displayWhen(TEST_NAME);

display("Adding dummy account", account.debugDump());
dummyResourceDarkViolet.addAccount(account);

waitForTaskNextRun(TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_OID, true);

// THEN
TestUtil.displayThen(TEST_NAME);
assertUserNick(ACCOUNT_LECHUCK_FULLNAME, ACCOUNT_LECHUCK_FULLNAME);
}

/*
* Create account with fullname LeChuck. User with name LeChuck.1 should be created (conflict).
*/
@Test(enabled=false) // Waiting for repo support
public void test712DarkVioletAddCharles() throws Exception {
final String TEST_NAME = "test712DarkVioletAddCharles";
TestUtil.displayTestTile(this, TEST_NAME);

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

DummyAccount account = new DummyAccount(ACCOUNT_CHARLES_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, ACCOUNT_LECHUCK_FULLNAME);

// WHEN
TestUtil.displayWhen(TEST_NAME);

display("Adding dummy account", account.debugDump());
dummyResourceDarkViolet.addAccount(account);

waitForTaskNextRun(TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_OID, true);

// THEN
TestUtil.displayThen(TEST_NAME);
assertUserNick(ACCOUNT_LECHUCK_FULLNAME, ACCOUNT_LECHUCK_FULLNAME);
assertUserNick(ACCOUNT_LECHUCK_FULLNAME, ACCOUNT_LECHUCK_FULLNAME+".1");
}

private void assertUserNick(String accountFullName, String expectedUserName) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException {
PrismObject<UserType> user = findUserByUsername(expectedUserName);
assertNotNull("No user for "+accountFullName, user);
display("Created user for "+accountFullName, user);
assertEquals("Wrong nickname in user created for "+accountFullName, accountFullName, user.asObjectable().getNickName().getOrig());
}

// TODO: add jack, is should conflict
}
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<!-- This is resource similar to violet but it works in the inbound direction -->

<resource oid="10000000-0000-0000-0000-0000000da204"
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:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-2"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-2"
xmlns:piracy="http://midpoint.evolveum.com/xml/ns/samples/piracy"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<name>Dummy Resource Dark Violet</name>
<connectorRef type="c:ConnectorType">
<filter>
<q:and>
<q:equal>
<q:path>connectorType</q:path>
<q:value>com.evolveum.icf.dummy.connector.DummyConnector</q:value>
</q:equal>
<q:equal>
<q:path>connectorVersion</q:path>
<q:value>2.0</q:value>
</q:equal>
</q:and>
</filter>
</connectorRef>
<connectorConfiguration xmlns:icfi="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.icf.dummy/com.evolveum.icf.dummy.connector.DummyConnector"
xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-2">

<icfc:configurationProperties>
<icfi:instanceId>darkViolet</icfi:instanceId> <!-- Default instance. -->
<icfi:requireExplicitEnable>true</icfi:requireExplicitEnable>
</icfc:configurationProperties>

</connectorConfiguration>

<schemaHandling>
<objectType>
<kind>account</kind>
<intent>default</intent>
<displayName>Default Account</displayName>
<default>true</default>
<objectClass>ri:AccountObjectClass</objectClass>
<attribute>
<ref>ri:fullname</ref>
<displayName>Full Name</displayName>
<inbound>
<target>
<path>nickName</path>
</target>
</inbound>
</attribute>
</objectType>
</schemaHandling>

<synchronization>
<objectSynchronization>
<enabled>true</enabled>
<objectTemplateRef oid="10000000-0000-0000-0000-0000000d0002"/>
<reaction>
<situation>linked</situation>
<synchronize>true</synchronize>
</reaction>
<reaction>
<situation>deleted</situation>
<synchronize>true</synchronize>
<action>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-2#deleteFocus</handlerUri>
</action>
</reaction>
<reaction>
<situation>unlinked</situation>
<synchronize>true</synchronize>
<action>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-2#link</handlerUri>
</action>
</reaction>
<reaction>
<situation>unmatched</situation>
<synchronize>true</synchronize>
<action>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/action-2#addFocus</handlerUri>
</action>
</reaction>
</objectSynchronization>
</synchronization>

</resource>
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2013 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.
-->

<task oid="10000000-0000-0000-5555-555500da0204"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-2a"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-2a"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<name>Live Sync: Dark Violet Dummy Resource</name>

<taskIdentifier>10000000-0000-0000-5555-555500da0404</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/live-sync/handler-2</handlerUri>
<objectRef oid="10000000-0000-0000-0000-0000000da204" type="c:ResourceType"/>
<recurrence>recurring</recurrence>
<binding>tight</binding>
<schedule>
<interval>1</interval>
</schedule>

</task>

0 comments on commit 267dfad

Please sign in to comment.