use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TestPreviewChanges method test210GuybrushAddAccount.
@Test
public void test210GuybrushAddAccount() throws Exception {
final String TEST_NAME = "test210GuybrushAddAccount";
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_JACK_DUMMY_FILE);
ObjectDelta<ShadowType> accountDelta = ObjectDelta.createAddDelta(account);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDelta);
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();
assertNull("Unexpected model focus context", focusContext);
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);
// Decision does not matter now
// assertEquals("Wrong policy decision", SynchronizationPolicyDecision.ADD, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertEquals(ChangeType.ADD, accountPrimaryDelta.getChangeType());
PrismObject<ShadowType> accountToAddPrimary = accountPrimaryDelta.getObjectToAdd();
assertNotNull("No object in account primary add delta", accountToAddPrimary);
assertEquals(getDummyResourceController().getAccountObjectClass(), accountToAddPrimary.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
PrismReference resourceRef = accountToAddPrimary.findReference(ShadowType.F_RESOURCE_REF);
assertEquals(getDummyResourceObject().getOid(), resourceRef.getOid());
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
PrismAsserts.assertModifications(accountSecondaryDelta, 1);
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TestPreviewChanges method assertAddAccount.
private void assertAddAccount(ModelContext<UserType> modelContext, boolean expectFullNameDelta) {
assertNotNull("Null model context", modelContext);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Null model focus context", focusContext);
assertNull("Unexpected focus primary delta: " + focusContext.getPrimaryDelta(), focusContext.getPrimaryDelta());
assertSideEffectiveDeltasOnly(focusContext.getSecondaryDelta(), "focus secondary delta", ActivationStatusType.ENABLED);
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.ADD, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertEquals(ChangeType.ADD, accountPrimaryDelta.getChangeType());
PrismObject<ShadowType> accountToAddPrimary = accountPrimaryDelta.getObjectToAdd();
assertNotNull("No object in account primary add delta", accountToAddPrimary);
assertEquals(getDummyResourceController().getAccountObjectClass(), accountToAddPrimary.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
PrismReference resourceRef = accountToAddPrimary.findReference(ShadowType.F_RESOURCE_REF);
assertEquals(getDummyResourceObject().getOid(), resourceRef.getOid());
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType());
PropertyDelta<String> fullNameDelta = accountSecondaryDelta.findPropertyDelta(dummyResourceCtl.getAttributeFullnamePath());
if (expectFullNameDelta) {
assertNotNull("No full name delta in account secondary delta", fullNameDelta);
PrismAsserts.assertReplace(fullNameDelta, "Jack Sparrow");
PrismAsserts.assertOrigin(fullNameDelta, OriginType.OUTBOUND);
} else {
assertNull("Unexpected full name delta in account secondary delta", fullNameDelta);
}
PrismObject<ShadowType> accountNew = accContext.getObjectNew();
IntegrationTestTools.assertIcfsNameAttribute(accountNew, "jack");
IntegrationTestTools.assertAttribute(accountNew, dummyResourceCtl.getAttributeFullnameQName(), "Jack Sparrow");
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TaskQuartzImpl method setOwner.
@Override
public void setOwner(PrismObject<UserType> owner) {
if (isPersistent()) {
throw new IllegalStateException("setOwner method can be called only on transient tasks!");
}
PrismReference ownerRef;
try {
ownerRef = taskPrism.findOrCreateReference(TaskType.F_OWNER_REF);
} catch (SchemaException e) {
// This should not happen
throw new IllegalStateException("Internal schema error: " + e.getMessage(), e);
}
ownerRef.getValue().setObject(owner);
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TaskQuartzImpl method setObjectTransient.
@Override
public void setObjectTransient(PrismObject object) {
if (object == null) {
PrismReference objectRef = taskPrism.findReference(TaskType.F_OBJECT_REF);
if (objectRef != null) {
taskPrism.getValue().remove(objectRef);
}
} else {
PrismReference objectRef;
try {
objectRef = taskPrism.findOrCreateReference(TaskType.F_OBJECT_REF);
} catch (SchemaException e) {
// This should not happen
throw new IllegalStateException("Internal schema error: " + e.getMessage(), e);
}
objectRef.getValue().setObject(object);
}
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TaskQuartzImpl method setObjectRefTransient.
public void setObjectRefTransient(ObjectReferenceType objectRefType) {
PrismReference objectRef;
try {
objectRef = taskPrism.findOrCreateReference(TaskType.F_OBJECT_REF);
} catch (SchemaException e) {
// This should not happen
throw new IllegalStateException("Internal schema error: " + e.getMessage(), e);
}
objectRef.getValue().setOid(objectRefType.getOid());
objectRef.getValue().setTargetType(objectRefType.getType());
}
Aggregations