Search in sources :

Example 51 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class ObjectTreeDeltas method fromObjectTreeDeltasType.

public static ObjectTreeDeltas fromObjectTreeDeltasType(ObjectTreeDeltasType deltasType, PrismContext prismContext) throws SchemaException {
    Validate.notNull(prismContext, "prismContext");
    if (deltasType == null) {
        return null;
    }
    ObjectTreeDeltas deltas = new ObjectTreeDeltas(prismContext);
    if (deltasType.getFocusPrimaryDelta() != null) {
        deltas.setFocusChange(DeltaConvertor.createObjectDelta(deltasType.getFocusPrimaryDelta(), prismContext));
    }
    for (ProjectionObjectDeltaType projectionObjectDeltaType : deltasType.getProjectionPrimaryDelta()) {
        ResourceShadowDiscriminator rsd = ResourceShadowDiscriminator.fromResourceShadowDiscriminatorType(projectionObjectDeltaType.getResourceShadowDiscriminator());
        ObjectDelta objectDelta = DeltaConvertor.createObjectDelta(projectionObjectDeltaType.getPrimaryDelta(), prismContext);
        deltas.addProjectionChange(rsd, objectDelta);
    }
    return deltas;
}
Also used : ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ProjectionObjectDeltaType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionObjectDeltaType)

Example 52 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class TestActivation method test150ModifyUserJackAssignYellowAccount.

/**
     * Assign yellow account.
     */
@Test
public void test150ModifyUserJackAssignYellowAccount() throws Exception {
    final String TEST_NAME = "test150ModifyUserJackAssignYellowAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestActivation.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_YELLOW_OID, null, true);
    deltas.add(accountAssignmentUserDelta);
    XMLGregorianCalendar start = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    XMLGregorianCalendar end = clock.currentTimeXMLGregorianCalendar();
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack);
    accountYellowOid = getLinkRefOid(userJack, RESOURCE_DUMMY_YELLOW_OID);
    // Check account in dummy resource
    assertDummyAccount(RESOURCE_DUMMY_YELLOW_NAME, "jack", "Jack Sparrow", true);
    // Check shadow
    PrismObject<ShadowType> accountShadowYellow = getShadowModel(accountYellowOid);
    assertAccountShadowModel(accountShadowYellow, accountYellowOid, ACCOUNT_JACK_DUMMY_USERNAME, getDummyResourceType(RESOURCE_DUMMY_YELLOW_NAME));
    assertAdministrativeStatusEnabled(accountShadowYellow);
    TestUtil.assertCreateTimestamp(accountShadowYellow, start, end);
    assertEnableTimestampShadow(accountShadowYellow, start, end);
    // Check user
    TestUtil.assertModifyTimestamp(userJack, start, end);
    assertAdministrativeStatusEnabled(userJack);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TestValidityRecomputeTask(com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractSynchronizationStoryTest(com.evolveum.midpoint.model.intest.sync.AbstractSynchronizationStoryTest)

Example 53 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class TestAudit method test300ConcurrentAudits.

/**
	 * We make concurrent modify operations to test audit service under higher load
	 */
@Test
public void test300ConcurrentAudits() throws Exception {
    final String TEST_NAME = "test300ConcurrentAudits";
    final int NUM_THREADS = 2;
    final int ITERATIONS = 300;
    final long TIMEOUT = 600000;
    if (isH2()) {
        display("Skipping " + TEST_NAME + " because of H2 database");
        return;
    }
    // creating objects
    List<String> oids = new ArrayList<>(NUM_THREADS);
    for (int i = 0; i < NUM_THREADS; i++) {
        UserType user = new UserType(prismContext);
        user.setName(PolyStringType.fromOrig("user-" + i));
        addObject(user.asPrismObject());
        oids.add(user.getOid());
    }
    display("OIDs", oids);
    // creating threads + starting them
    List<Thread> threads = new ArrayList<>(NUM_THREADS);
    List<Throwable> results = new ArrayList<>(NUM_THREADS);
    for (int i = 0; i < NUM_THREADS; i++) {
        final int index = i;
        Thread thread = new Thread(() -> {
            try {
                login(userAdministrator);
                Task threadTask = taskManager.createTaskInstance(TestAudit.class.getName() + "." + TEST_NAME);
                OperationResult threadResult = threadTask.getResult();
                for (int iteration = 0; iteration < ITERATIONS; iteration++) {
                    display("Executing iteration " + iteration + " on user " + index);
                    ObjectDelta delta = DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_FULL_NAME).replace(PolyString.fromOrig("User " + index + " iteration " + iteration)).asObjectDelta(oids.get(index));
                    executeChangesAssertSuccess(delta, null, threadTask, threadResult);
                }
                results.set(index, null);
            } catch (Throwable t) {
                System.err.println("Thread " + index + " got an exception " + t);
                LoggingUtils.logUnexpectedException(LOGGER, "Thread {} got an exception", t, index);
                results.set(index, t);
            }
        });
        //thread.setName("Worker " + i);
        threads.add(thread);
        // cleared on successful finish
        results.add(new IllegalStateException("Thread not finished"));
    }
    threads.forEach(Thread::start);
    // waiting for threads
    long deadline = System.currentTimeMillis() + TIMEOUT;
    for (int i = 0; i < NUM_THREADS; i++) {
        long waitTime = deadline - System.currentTimeMillis();
        if (waitTime > 0) {
            threads.get(i).join(waitTime);
        }
    }
    // checking results
    int fails = 0;
    for (int i = 0; i < NUM_THREADS; i++) {
        if (results.get(i) != null) {
            fails++;
            display("Thread " + i + " produced an exception: " + results.get(i));
        }
    }
    if (fails > 0) {
        fail(fails + " thread(s) failed: " + results.stream().filter(Objects::nonNull).collect(Collectors.toList()));
    }
// TODO check audit correctness
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 54 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class TestConsistencySimple method executeTest.

private void executeTest(final String TEST_NAME, FocusOperation focusOperation, ShadowOperation shadowOperation, ResourceObjectOperation resourceObjectOperation) throws Exception {
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestConsistencySimple.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    cleanUpBeforeTest(task, result);
    assignAccount(USER_JACK_OID, RESOURCE_DUMMY_OID, SchemaConstants.INTENT_DEFAULT, task, result);
    PrismObject<UserType> jack = getUser(USER_JACK_OID);
    display("Jack with account", jack);
    assertEquals("Unexpected # of accounts for jack", 1, jack.asObjectable().getLinkRef().size());
    ShadowType shadow = getObject(ShadowType.class, jack.asObjectable().getLinkRef().get(0).getOid()).asObjectable();
    display("Shadow", shadow);
    if (shadowOperation != ShadowOperation.KEEP) {
        @SuppressWarnings("unchecked") ObjectDelta<UserType> removeLinkRefDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_LINK_REF).replace().asObjectDelta(USER_JACK_OID);
        executeChanges(removeLinkRefDelta, ModelExecuteOptions.createRaw(), task, result);
        jack = getUser(USER_JACK_OID);
        assertEquals("Unexpected # of accounts for jack after linkRef removal", 0, jack.asObjectable().getLinkRef().size());
        if (shadowOperation == ShadowOperation.DELETE) {
            deleteObjectRaw(ShadowType.class, shadow.getOid(), task, result);
            assertNoObject(ShadowType.class, shadow.getOid());
        } else {
            if (shadowOperation == ShadowOperation.UNLINK_AND_TOMBSTONE) {
                @SuppressWarnings("unchecked") ObjectDelta<ShadowType> markAsDead = (ObjectDelta<ShadowType>) DeltaBuilder.deltaFor(ShadowType.class, prismContext).item(ShadowType.F_DEAD).replace(Boolean.TRUE).asObjectDelta(shadow.getOid());
                executeChanges(markAsDead, ModelExecuteOptions.createRaw(), task, result);
            }
            assertNotNull("jack's shadow does not exist", getObject(ShadowType.class, shadow.getOid()));
        }
    }
    if (resourceObjectOperation == ResourceObjectOperation.DELETE) {
        getDummyResource().deleteAccountByName("jack");
        assertNoDummyAccount(null, "jack");
    } else {
        assertDummyAccount(null, "jack");
    }
    // WHEN
    switch(focusOperation) {
        case RECOMPUTE:
            recomputeUser(USER_JACK_OID, task, result);
            break;
        case RECONCILE:
            ObjectDelta<UserType> emptyDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
            modelService.executeChanges(MiscSchemaUtil.createCollection(emptyDelta), ModelExecuteOptions.createReconcile(), task, result);
            break;
        default:
            throw new IllegalArgumentException("focusOperation: " + focusOperation);
    }
    // THEN
    result.computeStatus();
    if (ASSERT_SUCCESS) {
        TestUtil.assertSuccess(result);
    }
    jack = getUser(USER_JACK_OID);
    display("Jack after " + focusOperation, jack);
    assertEquals("Unexpected # of accounts for jack", 1, jack.asObjectable().getLinkRef().size());
    String shadowOidAfter = jack.asObjectable().getLinkRef().get(0).getOid();
    // check the shadow really exists
    assertNotNull("jack's shadow does not exist after " + focusOperation, getObject(ShadowType.class, shadowOidAfter));
    // check number of jack's shadows
    List<PrismObject<ShadowType>> shadows = getJacksShadows(result);
    display("Shadows for 'jack' on dummy resource", shadows);
    // TODO some of them may be marked as dead (solve if this occurs)
    assertEquals("Unexpected # of dummy shadows for 'jack'", 1, shadows.size());
    // other checks
    assertDummyAccount(null, "jack");
    cleanUpAfterTest(task, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 55 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class TestConsistencySimple method cleanUpBeforeTest.

private void cleanUpBeforeTest(Task task, OperationResult result) throws Exception {
    PrismObject<UserType> jack = getUser(USER_JACK_OID);
    display("Jack on start", jack);
    if (!jack.asObjectable().getAssignment().isEmpty()) {
        unassignAccount(USER_JACK_OID, RESOURCE_DUMMY_OID, SchemaConstants.INTENT_DEFAULT, task, result);
        jack = getUser(USER_JACK_OID);
        display("Jack after initial unassign", jack);
    }
    if (!jack.asObjectable().getLinkRef().isEmpty()) {
        for (ObjectReferenceType ref : jack.asObjectable().getLinkRef()) {
            deleteObject(ShadowType.class, ref.getOid());
        }
        ObjectDelta<UserType> killLinkRefDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_LINK_REF).replace().asObjectDelta(USER_JACK_OID);
        executeChanges(killLinkRefDelta, ModelExecuteOptions.createRaw(), task, result);
    }
    List<PrismObject<ShadowType>> jacksShadows = getJacksShadows(result);
    for (PrismObject<ShadowType> shadow : jacksShadows) {
        deleteObject(ShadowType.class, shadow.getOid());
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)445 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)363 Task (com.evolveum.midpoint.task.api.Task)326 Test (org.testng.annotations.Test)303 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)242 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)218 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)148 ArrayList (java.util.ArrayList)126 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)103 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)47 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)42 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)41 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)38 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)31 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)31 Collection (java.util.Collection)31 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)31 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)26