Search in sources :

Example 51 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class FocusAsserter method singleLink.

public ShadowReferenceAsserter<? extends FocusAsserter<F, RA>> singleLink() {
    PrismReference linkRef = getObject().findReference(FocusType.F_LINK_REF);
    if (linkRef == null) {
        fail("Expected single link, but is no linkRef in " + desc());
        // not reached
        return null;
    }
    assertEquals("Wrong number of links in " + desc(), 1, linkRef.size());
    ShadowReferenceAsserter<FocusAsserter<F, RA>> asserter = new ShadowReferenceAsserter<>(linkRef.getAnyValue(), null, this, "link in " + desc());
    copySetupTo(asserter);
    return asserter;
}
Also used : PrismReference(com.evolveum.midpoint.prism.PrismReference)

Example 52 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class TestClockwork method assertJackAccountShadow.

private void assertJackAccountShadow(LensContext<UserType> context) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    Collection<LensProjectionContext> accountContexts = context.getProjectionContexts();
    assertEquals(1, accountContexts.size());
    LensProjectionContext accContext = accountContexts.iterator().next();
    String accountOid = accContext.getOid();
    assertNotNull("No OID in account context " + accContext, accountOid);
    PrismObject<ShadowType> newAccount = getShadowModel(accountOid);
    assertEquals(DEFAULT_INTENT, newAccount.findProperty(ShadowType.F_INTENT).getRealValue());
    getDummyResourceType();
    assertEquals(new QName(MidPointConstants.NS_RI, "AccountObjectClass"), newAccount.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
    PrismReference resourceRef = newAccount.findReference(ShadowType.F_RESOURCE_REF);
    assertEquals(getDummyResourceType().getOid(), resourceRef.getOid());
    PrismContainer<?> attributes = newAccount.findContainer(ShadowType.F_ATTRIBUTES);
    assertEquals("jack", attributes.findProperty(SchemaTestConstants.ICFS_NAME).getRealValue());
    getDummyResourceType();
    assertEquals("Jack Sparrow", attributes.findProperty(new ItemName(MidPointConstants.NS_RI, "fullname")).getRealValue());
}
Also used : QName(javax.xml.namespace.QName) PrismReference(com.evolveum.midpoint.prism.PrismReference) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 53 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class TestProjectorRoleEntitlement method test100AddEntitlementToPirateDirect.

/**
 * Add direct entitlement assignment to role "pirate". The entitlement projection
 * context should appear in the lens context.
 */
@Test
public void test100AddEntitlementToPirateDirect() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    LensContext<RoleType> context = createLensContext(RoleType.class);
    fillContextWithFocus(context, RoleType.class, ROLE_PIRATE_OID, result);
    // We want "shadow" so the fullname will be computed by outbound expression
    addModificationToContextAddProjection(context, RoleType.class, ENTITLEMENT_SHADOW_PIRATE_DUMMY_FILE);
    displayDumpable("Input context", context);
    assertFocusModificationSanity(context);
    // WHEN
    projector.project(context, "test", task, result);
    // THEN
    displayDumpable("Output context", context);
    assertNull("Unexpected focus primary changes " + context.getFocusContext().getPrimaryDelta(), context.getFocusContext().getPrimaryDelta());
    assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "focus secondary delta", ActivationStatusType.ENABLED);
    assertFalse("No projection contexts", context.getProjectionContexts().isEmpty());
    Collection<LensProjectionContext> accountContexts = context.getProjectionContexts();
    assertEquals(1, accountContexts.size());
    LensProjectionContext projContext = accountContexts.iterator().next();
    assertEquals("Wrong policy decision", SynchronizationPolicyDecision.ADD, projContext.getSynchronizationPolicyDecision());
    ObjectDelta<ShadowType> accountPrimaryDelta = projContext.getPrimaryDelta();
    assertEquals(ChangeType.ADD, accountPrimaryDelta.getChangeType());
    PrismObject<ShadowType> accountToAddPrimary = accountPrimaryDelta.getObjectToAdd();
    assertNotNull("No object in projection primary add delta", accountToAddPrimary);
    PrismProperty<Object> intentProperty = accountToAddPrimary.findProperty(ShadowType.F_INTENT);
    assertNotNull("No intent type in projection primary add delta", intentProperty);
    assertEquals("group", intentProperty.getRealValue());
    getDummyResourceType();
    assertEquals(new QName(MidPointConstants.NS_RI, "GroupObjectClass"), accountToAddPrimary.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
    PrismReference resourceRef = accountToAddPrimary.findReference(ShadowType.F_RESOURCE_REF);
    assertEquals(getDummyResourceType().getOid(), resourceRef.getOid());
    accountToAddPrimary.checkConsistence();
    ObjectDelta<ShadowType> projSecondaryDelta = projContext.getSecondaryDelta();
    assertEquals(ChangeType.MODIFY, projSecondaryDelta.getChangeType());
    PropertyDelta<String> groupDescriptionDelta = projSecondaryDelta.findPropertyDelta(getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION));
    assertNotNull("No group description delta", groupDescriptionDelta);
    PrismAsserts.assertReplace(groupDescriptionDelta, "Bloody pirates");
    PrismAsserts.assertOrigin(groupDescriptionDelta, OriginType.OUTBOUND);
    PrismObject<ShadowType> projectionNew = projContext.getObjectNew();
    IntegrationTestTools.assertIcfsNameAttribute(projectionNew, "pirate");
    IntegrationTestTools.assertAttribute(projectionNew, getDummyResourceController().getAttributeQName(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION), "Bloody pirates");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismReference(com.evolveum.midpoint.prism.PrismReference) PrismObject(com.evolveum.midpoint.prism.PrismObject) Test(org.testng.annotations.Test)

Example 54 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class TestProjector method test100AddAccountToJackDirect.

@Test
public void test100AddAccountToJackDirect() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_JACK_OID, result);
    // We want "shadow" so the fullname will be computed by outbound expression
    addModificationToContextAddAccountFromFile(context, ACCOUNT_SHADOW_JACK_DUMMY_FILE);
    displayDumpable("Input context", context);
    assertFocusModificationSanity(context);
    rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);
    // WHEN
    when();
    projector.project(context, "test", task, result);
    // THEN
    then();
    displayDumpable("Output context", context);
    // Not loading anything. The account is already loaded in the context
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
    assertNull("Unexpected user primary changes " + context.getFocusContext().getPrimaryDelta(), context.getFocusContext().getPrimaryDelta());
    assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED);
    assertFalse("No account changes", context.getProjectionContexts().isEmpty());
    Collection<LensProjectionContext> accountContexts = context.getProjectionContexts();
    assertEquals(1, accountContexts.size());
    LensProjectionContext accContext = accountContexts.iterator().next();
    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);
    PrismProperty<Object> intentProperty = accountToAddPrimary.findProperty(ShadowType.F_INTENT);
    assertNotNull("No account type in account primary add delta", intentProperty);
    assertEquals(DEFAULT_INTENT, intentProperty.getRealValue());
    getDummyResourceType();
    assertEquals(new QName(MidPointConstants.NS_RI, "AccountObjectClass"), accountToAddPrimary.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
    PrismReference resourceRef = accountToAddPrimary.findReference(ShadowType.F_RESOURCE_REF);
    assertEquals(getDummyResourceType().getOid(), resourceRef.getOid());
    accountToAddPrimary.checkConsistence();
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType());
    PropertyDelta<String> fullNameDelta = accountSecondaryDelta.findPropertyDelta(getDummyResourceController().getAttributeFullnamePath());
    PrismAsserts.assertReplace(fullNameDelta, "Jack Sparrow");
    PrismAsserts.assertOrigin(fullNameDelta, OriginType.OUTBOUND);
    PrismObject<ShadowType> accountNew = accContext.getObjectNew();
    IntegrationTestTools.assertIcfsNameAttribute(accountNew, "jack");
    IntegrationTestTools.assertAttribute(accountNew, getDummyResourceController().getAttributeFullnameQName(), "Jack Sparrow");
    IntegrationTestTools.assertAttribute(accountNew, getDummyResourceController().getAttributeWeaponQName(), "mouth", "pistol");
    assertSerializable(context);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismReference(com.evolveum.midpoint.prism.PrismReference) PrismObject(com.evolveum.midpoint.prism.PrismObject) Test(org.testng.annotations.Test)

Example 55 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class ProjectionsLoadOperation method getLinkRefDelta.

@Nullable
private ReferenceDelta getLinkRefDelta(ObjectDelta<F> focusPrimaryDelta) {
    if (focusPrimaryDelta.getChangeType() == ChangeType.ADD) {
        PrismReference linkRef = focusPrimaryDelta.getObjectToAdd().findReference(FocusType.F_LINK_REF);
        if (linkRef == null) {
            // Adding new focus with no linkRef -> nothing to do
            return null;
        } else {
            ReferenceDelta linkRefDelta = linkRef.createDelta(FocusType.F_LINK_REF);
            linkRefDelta.addValuesToAdd(PrismValueCollectionsUtil.cloneValues(linkRef.getValues()));
            return linkRefDelta;
        }
    } else if (focusPrimaryDelta.getChangeType() == ChangeType.MODIFY) {
        return focusPrimaryDelta.findReferenceModification(FocusType.F_LINK_REF);
    } else {
        // delete, all existing account are already marked for delete
        return null;
    }
}
Also used : PrismReference(com.evolveum.midpoint.prism.PrismReference) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PrismReference (com.evolveum.midpoint.prism.PrismReference)55 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)18 Test (org.testng.annotations.Test)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 QName (javax.xml.namespace.QName)10 Task (com.evolveum.midpoint.task.api.Task)9 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)8 ArrayList (java.util.ArrayList)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)5 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)5 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)5 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)3 Item (com.evolveum.midpoint.prism.Item)3 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3