Search in sources :

Example 96 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class TestModelServiceContract method test109ModifyUserAddAccountAgain.

@Test
public void test109ModifyUserAddAccountAgain() throws Exception {
    TestUtil.displayTestTile(this, "test109ModifyUserAddAccountAgain");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + ".test109ModifyUserAddAccountAgain");
    OperationResult result = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    account.setOid(null);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
    userDelta.addModification(accountDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
    try {
        // WHEN
        modelService.executeChanges(deltas, null, task, result);
        // THEN
        assert false : "Expected executeChanges operation to fail but it has obviously succeeded";
    } catch (SchemaException e) {
        // This is expected
        // THEN
        String message = e.getMessage();
        assertMessageContains(message, "already contains account");
        assertMessageContains(message, "default");
    }
    assertNoProvisioningScripts();
    assertShadowFetchOperationCountIncrement(0);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR);
    assertSteadyResources();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) 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) Collection(java.util.Collection) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowDiscriminatorObjectDelta(com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 97 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class TestModelServiceContract method test149ModifyUserJackDeleteAccount.

/**
	 * Assignment enforcement is set to POSITIVE for this test as it was for the previous test.
	 * Now we will explicitly delete the account.
	 */
@Test
public void test149ModifyUserJackDeleteAccount() throws Exception {
    final String TEST_NAME = "test149ModifyUserJackDeleteAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setOid(accountJackOid);
    ReferenceDelta accountRefDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), accountJackOid);
    userDelta.addModification(accountRefDelta);
    ObjectDelta<ShadowType> accountDelta = ObjectDelta.createDeleteDelta(ShadowType.class, accountJackOid, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta, accountDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    assertShadowFetchOperationCountIncrement(0);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    assertUserJack(userJack, "Jack Sparrow", "Jack", "Sparrow");
    // Check accountRef
    assertUserNoAccountRefs(userJack);
    // Check is shadow is gone
    assertNoShadow(accountJackOid);
    // Check if dummy resource account is gone
    assertNoDummyAccount("jack");
    assertDummyScriptsDelete();
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(2);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.DELETE, ShadowType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    // Check notifications
    notificationManager.setDisabled(true);
    checkDummyTransportMessages("accountPasswordNotifier", 0);
    checkDummyTransportMessages("userPasswordNotifier", 0);
    checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
    checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
    checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 0);
    checkDummyTransportMessages("simpleAccountNotifier-DELETE-SUCCESS", 1);
    checkDummyTransportMessages("simpleUserNotifier", 0);
    checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
    assertScriptCompileIncrement(0);
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) 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) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowDiscriminatorObjectDelta(com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 98 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class TestModelServiceContract method test120AddAccount.

@Test
public void test120AddAccount() throws Exception {
    TestUtil.displayTestTile(this, "test120AddAccount");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + ".test120AddAccount");
    OperationResult result = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    ObjectDelta<ShadowType> accountDelta = ObjectDelta.createAddDelta(account);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDelta);
    XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
    assertShadowFetchOperationCountIncrement(0);
    accountJackOid = accountDelta.getOid();
    assertNotNull("No account OID in resulting delta", accountJackOid);
    // Check accountRef (should be none)
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    assertUserJack(userJack);
    UserType userJackType = userJack.asObjectable();
    assertEquals("Unexpected number of accountRefs", 0, userJackType.getLinkRef().size());
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
    assertDummyAccountShadowRepo(accountShadow, accountJackOid, "jack");
    assertEnableTimestampShadow(accountShadow, startTime, endTime);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountJackOid, "jack", "Jack Sparrow");
    assertEnableTimestampShadow(accountModel, startTime, endTime);
    // Check account in dummy resource
    assertDefaultDummyAccount("jack", "Jack Sparrow", true);
    // The user is not associated with the account
    assertDummyScriptsAdd(null, accountModel, getDummyResourceType());
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(1);
    dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
    // We cannot have OID in the request. The OID is not assigned yet at that stage.
    dummyAuditService.assertTarget(accountShadow.getOid(), AuditEventStage.EXECUTION);
    dummyAuditService.assertExecutionSuccess();
    // Check notifications
    notificationManager.setDisabled(true);
    // there's no password for that account
    checkDummyTransportMessages("accountPasswordNotifier", 0);
    checkDummyTransportMessages("userPasswordNotifier", 0);
    checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
    checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
    checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 1);
    // account has no owner
    checkDummyTransportMessages("simpleUserNotifier", 0);
    checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
    assertSteadyResources();
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) 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) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowDiscriminatorObjectDelta(com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 99 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class TestUserTemplate method test204AddUserHerman.

/**
	 * MID-3186
	 */
@Test
public void test204AddUserHerman() throws Exception {
    final String TEST_NAME = "test204AddUserHerman";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestUserTemplate.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = PrismTestUtil.parseObject(USER_HERMAN_FILE);
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    ObjectDelta<UserType> userDelta = ObjectDelta.createAddDelta(user);
    deltas.add(userDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_HERMAN_OID, null, task, result);
    assertUser(userAfter, USER_HERMAN_OID, USER_HERMAN_USERNAME, USER_HERMAN_FULL_NAME, "Herman", "Toothrot");
    PrismAsserts.assertNoItem(userAfter, UserType.F_DESCRIPTION);
    PrismAsserts.assertPropertyValue(userAfter, UserType.F_TIMEZONE, "High Seas/Monkey Island");
    assertAssignedAccount(userAfter, RESOURCE_DUMMY_BLUE_OID);
    assertAssignedNoRole(userAfter);
    assertAssignments(userAfter, 1);
    UserType userAfterType = userAfter.asObjectable();
    assertLinks(userAfter, 1);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals("Wrong costCenter", "G001", userAfterType.getCostCenter());
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 100 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class TestUserTemplate method test201AddUserLargo.

@Test
public void test201AddUserLargo() throws Exception {
    TestUtil.displayTestTile(this, "test201AddUserLargo");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestUserTemplate.class.getName() + ".test201AddUserLargo");
    // This simulates IMPORT to trigger the channel-limited mapping
    task.setChannel(QNameUtil.qNameToUri(SchemaConstants.CHANGE_CHANNEL_IMPORT));
    OperationResult result = task.getResult();
    PrismObject<UserType> user = PrismTestUtil.parseObject(USER_LARGO_FILE);
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    ObjectDelta<UserType> userDelta = ObjectDelta.createAddDelta(user);
    deltas.add(userDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_LARGO_OID, null, task, result);
    display("Largo after", userAfter);
    assertUser(userAfter, USER_LARGO_OID, "largo", "Largo LaGrande", "Largo", "LaGrande");
    // locality is null; the description comes from inbound mapping on dummy resource
    // PrismAsserts.assertPropertyValue(userAfter, UserType.F_DESCRIPTION, "Came from null");
    // TODO TEMPORARILY allowing value of "Imported user", because the inbound mapping is not applied because of
    // the "locality" attribute is null (Skipping inbound for {...}location in Discr(RSD(account (default)
    // @10000000-0000-0000-0000-000000000004)): Not a full shadow and account a priori delta exists, but
    // doesn't have change for processed property.
    //
    // Either we fix this or recommend setting volatility=unpredictable for such situations.
    PrismAsserts.assertPropertyValue(userAfter, UserType.F_DESCRIPTION, "Imported user");
    assertAssignedAccount(userAfter, RESOURCE_DUMMY_BLUE_OID);
    assertAssignedRole(userAfter, ROLE_PIRATE_OID);
    assertAssignments(userAfter, 2);
    UserType userAfterType = userAfter.asObjectable();
    assertEquals("Unexpected number of accountRefs", 2, userAfterType.getLinkRef().size());
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals("Unexpected length  of employeeNumber, maybe it was not generated?", GenerateExpressionEvaluator.DEFAULT_LENGTH, userAfterType.getEmployeeNumber().length());
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)371 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)297 Test (org.testng.annotations.Test)264 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)253 Task (com.evolveum.midpoint.task.api.Task)252 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)223 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)155 ArrayList (java.util.ArrayList)123 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)100 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)58 Holder (javax.xml.ws.Holder)49 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)46 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)46 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)38 QName (javax.xml.namespace.QName)38 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)37 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)33 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)33 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32