use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test200ModifyUserGuybrushDeleteAccount.
@Test
public void test200ModifyUserGuybrushDeleteAccount() throws Exception {
final String TEST_NAME = "test200ModifyUserGuybrushDeleteAccount";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_GUYBRUSH_DUMMY_FILE);
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_GUYBRUSH_OID, prismContext);
PrismReferenceValue accountRefVal = new PrismReferenceValue();
accountRefVal.setObject(account);
ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
userDelta.addModification(accountDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
display("Input deltas: ", deltas);
// WHEN
TestUtil.displayWhen(TEST_NAME);
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
display("Preview context", modelContext);
assertNotNull("Null model context", modelContext);
result.computeStatus();
TestUtil.assertSuccess(result);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Null model focus context", focusContext);
assertNull("Unexpected focus primary delta: " + focusContext.getPrimaryDelta(), focusContext.getPrimaryDelta());
assertSideEffectiveDeltasOnly("focus secondary delta", focusContext.getSecondaryDelta());
Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
assertNotNull("Null model projection context list", projectionContexts);
assertEquals("Unexpected number of projection contexts", 1, projectionContexts.size());
ModelProjectionContext accContext = projectionContexts.iterator().next();
assertNotNull("Null model projection context", accContext);
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.DELETE, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertEquals(ChangeType.DELETE, accountPrimaryDelta.getChangeType());
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test630AddUserRogers.
// testing multiple resources with dependencies (dummy -> dummy lemon)
@Test
public void test630AddUserRogers() throws Exception {
final String TEST_NAME = "test630AddUserRogers";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
PrismObject<UserType> user = PrismTestUtil.parseObject(USER_ROGERS_FILE);
ObjectDelta<UserType> userDelta = ObjectDelta.createAddDelta(user);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
// THEN
display("Preview context", modelContext);
assertNotNull("Null model context", modelContext);
result.computeStatus();
TestUtil.assertSuccess(result);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Null model focus context", focusContext);
ObjectDelta<UserType> userPrimaryDelta = focusContext.getPrimaryDelta();
assertNotNull("No focus primary delta: " + userPrimaryDelta, userPrimaryDelta);
PrismAsserts.assertIsAdd(userPrimaryDelta);
ObjectDelta<UserType> userSecondaryDelta = focusContext.getSecondaryDelta();
// inbound from ship (explicitly specified) to organizationalUnit (dummy resource)
// inbound from gossip (computed via outbound) to description (lemon resource)
assertEffectualDeltas(userSecondaryDelta, "focus secondary delta", ActivationStatusType.ENABLED, 2);
PrismObject<UserType> finalUser = user.clone();
userSecondaryDelta.applyTo(finalUser);
PrismAsserts.assertOrigEqualsPolyStringCollectionUnordered("Wrong organizationalUnit attribute", finalUser.asObjectable().getOrganizationalUnit(), "The crew of The Sea Monkey");
assertEquals("Wrong description attribute", "Rum Rogers Sr. must be the best pirate the has ever seen", finalUser.asObjectable().getDescription());
Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
assertNotNull("Null model projection context list", projectionContexts);
assertEquals("Unexpected number of projection contexts", 2, projectionContexts.size());
// DEFAULT dummy resource: normal mappings
ModelProjectionContext accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null));
assertNotNull("Null model projection context (default)", accContext);
assertEquals("Wrong policy decision (default)", SynchronizationPolicyDecision.ADD, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertNotNull("No account primary delta (default)", accountPrimaryDelta);
PrismAsserts.assertIsAdd(accountPrimaryDelta);
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertNotNull("No account secondary delta (default)", accountSecondaryDelta);
// administrativeStatus (ENABLED), enableTimestamp, name, drink, quote, iteration, iterationToken, password/value
PrismAsserts.assertModifications(accountSecondaryDelta, 9);
PrismAsserts.assertNoItemDelta(accountSecondaryDelta, getAttributePath(getDummyResourceObject(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME));
// LEMON dummy resource
accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_LEMON_OID, ShadowKindType.ACCOUNT, null));
assertNotNull("Null model projection context (lemon)", accContext);
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.ADD, accContext.getSynchronizationPolicyDecision());
accountPrimaryDelta = accContext.getPrimaryDelta();
assertNotNull("No account primary delta (default)", accountPrimaryDelta);
PrismAsserts.assertIsAdd(accountPrimaryDelta);
accountSecondaryDelta = accContext.getSecondaryDelta();
assertNotNull("No account secondary delta (lemon)", accountSecondaryDelta);
// administrativeStatus (ENABLED), enableTimestamp, ship (from organizationalUnit), name, gossip, water, iteration, iterationToken, password/value
PrismAsserts.assertModifications(accountSecondaryDelta, 10);
PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_LEMON_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME), "The crew of The Sea Monkey");
PrismAsserts.assertPropertyReplace(accountSecondaryDelta, new ItemPath(ShadowType.F_ATTRIBUTES, SchemaConstants.ICFS_NAME), "rogers");
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_LEMON_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME), "Rum Rogers Sr. must be the best pirate the has ever seen");
PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_LEMON_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WATER_NAME), "pirate Rum Rogers Sr. drinks only rum!");
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestVisualizer method fillDeltas.
protected void fillDeltas(ModelContext<UserType> modelContext, List<ObjectDelta<? extends ObjectType>> primaryDeltas, List<ObjectDelta<? extends ObjectType>> secondaryDeltas) throws SchemaException {
if (modelContext != null) {
if (modelContext.getFocusContext() != null) {
addIgnoreNull(primaryDeltas, modelContext.getFocusContext().getPrimaryDelta());
addIgnoreNull(secondaryDeltas, modelContext.getFocusContext().getSecondaryDelta());
}
for (ModelProjectionContext projCtx : modelContext.getProjectionContexts()) {
addIgnoreNull(primaryDeltas, projCtx.getPrimaryDelta());
addIgnoreNull(secondaryDeltas, projCtx.getExecutableDelta());
}
}
display("primary deltas", primaryDeltas);
display("secondary deltas", secondaryDeltas);
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class ModelEvent method getAllExecutedDeltas.
public List<ObjectDeltaOperation> getAllExecutedDeltas() {
List<ObjectDeltaOperation> retval = new ArrayList<ObjectDeltaOperation>();
retval.addAll(getFocusContext().getExecutedDeltas());
for (Object o : modelContext.getProjectionContexts()) {
ModelProjectionContext modelProjectionContext = (ModelProjectionContext) o;
retval.addAll(modelProjectionContext.getExecutedDeltas());
}
return retval;
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertResolvedResourceRefs.
protected <F extends ObjectType> void assertResolvedResourceRefs(ModelContext<F> context) {
for (ModelProjectionContext projectionContext : context.getProjectionContexts()) {
assertResolvedResourceRefs(projectionContext.getObjectOld(), "objectOld in " + projectionContext);
assertResolvedResourceRefs(projectionContext.getObjectNew(), "objectNew in " + projectionContext);
assertResolvedResourceRefs(projectionContext.getPrimaryDelta(), "primaryDelta in " + projectionContext);
assertResolvedResourceRefs(projectionContext.getSecondaryDelta(), "secondaryDelta in " + projectionContext);
}
}
Aggregations