Search in sources :

Example 46 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class TestOpenDj method test170DisableAccount.

@Test
public void test170DisableAccount() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ShadowType object = parseObjectType(ACCOUNT_DISABLE_SIMULATED_FILE, ShadowType.class);
    System.out.println(SchemaDebugUtil.prettyPrint(object));
    System.out.println(object.asPrismObject().debugDump());
    String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, task, result);
    assertEquals(ACCOUNT_DISABLE_SIMULATED_OID, addedObjectOid);
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(REQUEST_DISABLE_ACCOUNT_SIMULATED_FILE, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<ShadowType> delta = DeltaConvertor.createObjectDelta(objectChange, object.asPrismObject().getDefinition());
    displayDumpable("Object change", delta);
    // WHEN
    when();
    provisioningService.modifyObject(ShadowType.class, objectChange.getOid(), delta.getModifications(), null, null, task, result);
    // THEN
    then();
    ShadowType accountAfter = provisioningService.getObject(ShadowType.class, ACCOUNT_DISABLE_SIMULATED_OID, null, task, result).asObjectable();
    display("Object after change", accountAfter);
    assertEquals("The account was not disabled in the shadow", ActivationStatusType.DISABLED, accountAfter.getActivation().getAdministrativeStatus());
    String uid = ShadowUtil.getSingleStringAttributeValue(accountAfter, getPrimaryIdentifierQName());
    assertNotNull(uid);
    // Check if object was modified in LDAP
    Entry response = openDJController.searchAndAssertByEntryUuid(uid);
    display("LDAP account", response);
    String disabled = OpenDJController.getAttributeValue(response, "ds-pwp-account-disabled");
    assertNotNull("no ds-pwp-account-disabled attribute in account " + uid, disabled);
    display("ds-pwp-account-disabled after change: " + disabled);
    assertEquals("ds-pwp-account-disabled not set to \"TRUE\"", "TRUE", disabled);
    PrismObject<ShadowType> repoShadow = getShadowRepo(ACCOUNT_DISABLE_SIMULATED_OID);
    ActivationType repoActivation = repoShadow.asObjectable().getActivation();
    assertNotNull("No activation in repo", repoActivation);
    XMLGregorianCalendar repoDisableTimestamp = repoActivation.getDisableTimestamp();
    assertNotNull("No activation disableTimestamp in repo", repoDisableTimestamp);
    assertEquals("Wrong activation disableTimestamp in repo", XmlTypeConverter.createXMLGregorianCalendar(2001, 2, 3, 4, 5, 6), repoDisableTimestamp);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) Entry(org.opends.server.types.Entry) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 47 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class TestOpenDj method test322ModifyAccountPosix.

@Test
public void test322ModifyAccountPosix() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(ACCOUNT_POSIX_MCMUTTON_CHANGE_FILE, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<ShadowType> delta = DeltaConvertor.createObjectDelta(objectChange, getShadowDefinition());
    displayDumpable("Object change", delta);
    // WHEN
    when();
    provisioningService.modifyObject(ShadowType.class, objectChange.getOid(), delta.getModifications(), null, null, taskManager.createTaskInstance(), result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    ShadowType accountType = provisioningService.getObject(ShadowType.class, ACCOUNT_POSIX_MCMUTTON_OID, null, task, result).asObjectable();
    display("Object after change", accountType);
    String uid = ShadowUtil.getSingleStringAttributeValue(accountType, getPrimaryIdentifierQName());
    assertNotNull(uid);
    assertAttribute(accountType, "cn", "Haggis McMutton");
    assertAttribute(accountType, "homeDirectory", "/home/caribbean");
    assertAttribute(accountType, "roomNumber", "Barber Shop");
    assertAttribute(accountType, "uidNumber", 1001);
    // Check if object was modified in LDAP
    Entry entry = openDJController.searchAndAssertByEntryUuid(uid);
    display("LDAP account", entry);
    OpenDJController.assertAttribute(entry, "cn", "Haggis McMutton");
    OpenDJController.assertAttribute(entry, "homeDirectory", "/home/caribbean");
    OpenDJController.assertAttribute(entry, "roomNumber", "Barber Shop");
    OpenDJController.assertAttribute(entry, "uidNumber", "1001");
    assertShadows(17);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) Task(com.evolveum.midpoint.task.api.Task) Entry(org.opends.server.types.Entry) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 48 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class TestOpenDjNegative method test550ModifyObject.

@Test
public void test550ModifyObject() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(ACCOUNT_JACK_CHANGE_FILE, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<ShadowType> delta = DeltaConvertor.createObjectDelta(objectChange, ShadowType.class, PrismTestUtil.getPrismContext());
    displayDumpable("Object change", delta);
    // WHEN
    provisioningService.modifyObject(ShadowType.class, objectChange.getOid(), delta.getModifications(), null, null, task, result);
    // THEN
    result.computeStatus();
    display("deleteObject result", result);
    assertInProgress(result);
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, ACCOUNT_JACK_OID, null, result);
    ShadowAsserter.forShadow(repoShadow, "repo").display().pendingOperations().singleOperation().assertExecutionStatus(PendingOperationExecutionStatusType.EXECUTING).assertResultStatus(OperationResultStatusType.FATAL_ERROR).delta().assertModify();
    PrismObject<ShadowType> provisioningAccount = provisioningService.getObject(ShadowType.class, ACCOUNT_JACK_OID, null, task, result);
    ShadowAsserter.forShadow(provisioningAccount, "provisioning").display().pendingOperations().singleOperation().assertExecutionStatus(PendingOperationExecutionStatusType.EXECUTING).assertResultStatus(OperationResultStatusType.FATAL_ERROR).delta().assertModify();
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 49 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class TestOpenDj method test150ChangePassword.

@Test
public void test150ChangePassword() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ShadowType object = parseObjectType(ACCOUNT_MODIFY_PASSWORD_FILE, ShadowType.class);
    String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, taskManager.createTaskInstance(), result);
    assertEquals(ACCOUNT_MODIFY_PASSWORD_OID, addedObjectOid);
    ShadowType accountType = provisioningService.getObject(ShadowType.class, ACCOUNT_MODIFY_PASSWORD_OID, null, taskManager.createTaskInstance(), result).asObjectable();
    display("Object before password change", accountType);
    String uid = ShadowUtil.getSingleStringAttributeValue(accountType, getPrimaryIdentifierQName());
    assertNotNull(uid);
    Entry entryBefore = openDJController.searchAndAssertByEntryUuid(uid);
    display("LDAP account before", entryBefore);
    String passwordBefore = OpenDJController.getAttributeValue(entryBefore, "userPassword");
    assertNull("Unexpected password before change", passwordBefore);
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "account-change-password.xml"), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<ShadowType> delta = DeltaConvertor.createObjectDelta(objectChange, accountType.asPrismObject().getDefinition());
    displayDumpable("Object change", delta);
    // WHEN
    when();
    provisioningService.modifyObject(ShadowType.class, delta.getOid(), delta.getModifications(), null, null, task, result);
    // THEN
    then();
    // Check if object was modified in LDAP
    Entry entryAfter = openDJController.searchAndAssertByEntryUuid(uid);
    display("LDAP account after", entryAfter);
    String passwordAfter = OpenDJController.getAttributeValue(entryAfter, "userPassword");
    assertNotNull("The password was not changed", passwordAfter);
    System.out.println("Changed password: " + passwordAfter);
    openDJController.assertPassword(entryAfter.getDN().toString(), "mehAbigH4X0R");
    assertShadows(4);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) Task(com.evolveum.midpoint.task.api.Task) Entry(org.opends.server.types.Entry) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) File(java.io.File) Test(org.testng.annotations.Test)

Example 50 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class TestParseDiffPatch method testUser.

@Test
public void testUser() throws SchemaException, IOException {
    PrismObject<UserType> userBefore = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-before.xml"));
    userBefore.checkConsistence();
    PrismObject<UserType> userAfter = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-after.xml"));
    userAfter.checkConsistence();
    // sanity
    assertFalse("Equals does not work", userBefore.equals(userAfter));
    // WHEN
    ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
    // THEN
    System.out.println("DELTA:");
    System.out.println(userDelta.debugDump());
    userBefore.checkConsistence();
    userAfter.checkConsistence();
    userDelta.checkConsistence();
    userDelta.assertDefinitions();
    assertEquals("Wrong delta OID", userBefore.getOid(), userDelta.getOid());
    assertEquals("Wrong change type", ChangeType.MODIFY, userDelta.getChangeType());
    Collection<? extends ItemDelta> modifications = userDelta.getModifications();
    assertEquals("Unexpected number of modifications", 3, modifications.size());
    PrismAsserts.assertPropertyReplace(userDelta, new ItemName(SchemaConstants.NS_C, "fullName"), new PolyString("Cpt. Jack Sparrow", "cpt jack sparrow"));
    PrismAsserts.assertPropertyAdd(userDelta, new ItemName(SchemaConstants.NS_C, "honorificPrefix"), new PolyString("Cpt.", "cpt"));
    PrismAsserts.assertPropertyAdd(userDelta, new ItemName(SchemaConstants.NS_C, "locality"), new PolyString("Tortuga", "tortuga"));
    ObjectModificationType objectModificationType = DeltaConvertor.toObjectModificationType(userDelta);
    System.out.println("Modification XML:");
    System.out.println(PrismTestUtil.serializeAnyDataWrapped(objectModificationType));
    assertEquals("Wrong delta OID", userBefore.getOid(), objectModificationType.getOid());
    List<ItemDeltaType> propertyModifications = objectModificationType.getItemDelta();
    assertEquals("Unexpected number of modifications", 3, propertyModifications.size());
    PolyStringType polyString = new PolyStringType();
    polyString.setOrig("Cpt. Jack Sparrow");
    polyString.setNorm("cpt jack sparrow");
    assertXmlPolyMod(objectModificationType, new ItemName(SchemaConstants.NS_C, "fullName"), ModificationTypeType.REPLACE, polyString);
    polyString = new PolyStringType();
    polyString.setOrig("Cpt.");
    polyString.setNorm("cpt");
    assertXmlPolyMod(objectModificationType, new ItemName(SchemaConstants.NS_C, "honorificPrefix"), ModificationTypeType.ADD, polyString);
    polyString = new PolyStringType();
    polyString.setOrig("Tortuga");
    polyString.setNorm("tortuga");
    assertXmlPolyMod(objectModificationType, new ItemName(SchemaConstants.NS_C, "locality"), ModificationTypeType.ADD, polyString);
    userBefore.checkConsistence();
    userAfter.checkConsistence();
    userDelta.checkConsistence();
    // ROUNDTRIP
    userDelta.applyTo(userBefore);
    userBefore.checkConsistence();
    userAfter.checkConsistence();
    userDelta.checkConsistence();
    // assertEquals("Round trip failed", userAfter, userBefore);
    assertTrue("Not equivalent", userBefore.equivalent(userAfter));
    ObjectDelta<UserType> roundTripDelta = DiffUtil.diff(userBefore, userAfter);
    System.out.println("roundtrip DELTA:");
    System.out.println(roundTripDelta.debugDump());
    assertTrue("Roundtrip delta is not empty", roundTripDelta.isEmpty());
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemName(com.evolveum.midpoint.prism.path.ItemName) File(java.io.File) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test)

Aggregations

ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)50 Test (org.testng.annotations.Test)44 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)34 File (java.io.File)32 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 Task (com.evolveum.midpoint.task.api.Task)9 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 Session (org.hibernate.Session)6 ROrgClosure (com.evolveum.midpoint.repo.sql.data.common.ROrgClosure)5 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)5 Entry (org.opends.server.types.Entry)5 QName (javax.xml.namespace.QName)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)2 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2