Search in sources :

Example 26 with ObjectDeltaType

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

the class TestSanityLegacy method testModifyAccountDjRoomNumber.

public void testModifyAccountDjRoomNumber(final String TEST_NAME, File reqFile, String expectedVal) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    assertNoRepoCache();
    ObjectDeltaType objectChange = unmarshallValueFromFile(reqFile, ObjectDeltaType.class);
    objectChange.setOid(accountShadowOidOpendj);
    // WHEN
    OperationResultType result = modifyObjectViaModelWS(objectChange);
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result:", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("modifyObject has failed", result);
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj, null, repoResult);
    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject(repo) has failed", repoResult);
    display("repository shadow", repoShadow);
    AssertJUnit.assertNotNull(repoShadow);
    ShadowType repoShadowType = repoShadow.asObjectable();
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
    // check attributes in the shadow: should be only identifiers (ICF UID)
    String uid = checkRepoShadow(repoShadow);
    // Check if LDAP account was updated
    Entry jackLdapEntry = assertOpenDJAccountJack(uid, "jack");
    OpenDJController.assertAttribute(jackLdapEntry, "roomNumber", expectedVal);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)

Example 27 with ObjectDeltaType

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

the class TestSanityLegacy method test503NotifyChangeDeleteAccount.

@Test
public void test503NotifyChangeDeleteAccount() throws Exception {
    TestUtil.displayTestTile("test503NotifyChangeDeleteAccount");
    OperationResult parentResult = new OperationResult("test500notifyChange.addAngelicaAccount");
    PrismObject<UserType> userAngelika = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelika);
    UserType user = userAngelika.asObjectable();
    assertNotNull("User with the name angelika must have one link ref.", user.getLinkRef());
    assertEquals("Expected one account ref in user", 1, user.getLinkRef().size());
    String oid = user.getLinkRef().get(0).getOid();
    ResourceObjectShadowChangeDescriptionType changeDescription = new ResourceObjectShadowChangeDescriptionType();
    ObjectDeltaType delta = new ObjectDeltaType();
    delta.setChangeType(ChangeTypeType.DELETE);
    delta.setObjectType(ShadowType.COMPLEX_TYPE);
    delta.setOid(oid);
    changeDescription.setObjectDelta(delta);
    changeDescription.setOldShadowOid(oid);
    changeDescription.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
    TaskType task = modelWeb.notifyChange(changeDescription);
    OperationResult result = OperationResult.createOperationResult(task.getResult());
    display(result);
    assertSuccess(result);
    PrismObject<UserType> userAngelikaAfterSync = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelikaAfterSync);
    UserType userType = userAngelikaAfterSync.asObjectable();
    assertNotNull("User with the name angelika must have one link ref.", userType.getLinkRef());
    assertEquals("Expected no account ref in user", 0, userType.getLinkRef().size());
//    	String oid = userType.getLinkRef().get(0).getOid();
//    	UserType userAfterSync = userAngelikaAfterSync.asObjectable();
//    	PrismAsserts.assertEqualsPolyString("wrong given name in user angelika", PrismTestUtil.createPolyStringType("newAngelika"), userAfterSync.getGivenName());
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ResourceObjectShadowChangeDescriptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectShadowChangeDescriptionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 28 with ObjectDeltaType

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

the class TestSanityLegacy method test023ChangeUserPasswordJAXB.

/**
     * Similar to previous test just the request is constructed a bit differently.
     */
@Test
public void test023ChangeUserPasswordJAXB() throws Exception {
    final String TEST_NAME = "test023ChangeUserPasswordJAXB";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    final String NEW_PASSWORD = "abandonSHIP";
    Document doc = ModelClientUtil.getDocumnent();
    ObjectDeltaType userDelta = new ObjectDeltaType();
    userDelta.setOid(USER_JACK_OID);
    userDelta.setChangeType(ChangeTypeType.MODIFY);
    userDelta.setObjectType(UserType.COMPLEX_TYPE);
    ItemDeltaType passwordDelta = new ItemDeltaType();
    passwordDelta.setModificationType(ModificationTypeType.REPLACE);
    passwordDelta.setPath(ModelClientUtil.createItemPathType("credentials/password/value"));
    ProtectedStringType pass = new ProtectedStringType();
    pass.setClearValue(NEW_PASSWORD);
    XNode passValue = ((PrismContextImpl) prismContext).getBeanMarshaller().marshall(pass);
    System.out.println("PASSWORD VALUE: " + passValue.debugDump());
    RawType passwordValue = new RawType(passValue, prismContext);
    passwordDelta.getValue().add(passwordValue);
    userDelta.getItemDelta().add(passwordDelta);
    // WHEN ObjectTypes.USER.getTypeQName(), 
    OperationResultType result = modifyObjectViaModelWS(userDelta);
    // THEN
    assertUserPasswordChange(NEW_PASSWORD, result);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Document(org.w3c.dom.Document) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 29 with ObjectDeltaType

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

the class TestSanityLegacy method test420RecomputeUsers.

@Test
public void test420RecomputeUsers() throws Exception {
    final String TEST_NAME = "test420RecomputeUsers";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    final OperationResult result = new OperationResult(TestSanityLegacy.class.getName() + "." + TEST_NAME);
    // Assign role to a user, but we do this using a repository instead of model.
    // The role assignment will not be executed and this created an inconsistent state.
    ObjectDeltaType changeAddRoleCaptain = unmarshallValueFromFile(REQUEST_USER_MODIFY_ADD_ROLE_CAPTAIN_1_FILENAME, ObjectDeltaType.class);
    Collection<? extends ItemDelta> modifications = DeltaConvertor.toModifications(changeAddRoleCaptain.getItemDelta(), getUserDefinition());
    repositoryService.modifyObject(UserType.class, changeAddRoleCaptain.getOid(), modifications, result);
    // TODO: setup more "inconsistent" state
    // Add reconciliation task. This will trigger reconciliation
    importObjectFromFile(TASK_USER_RECOMPUTE_FILENAME, result);
    // We need to wait for a sync interval, so the task scanner has a chance
    // to pick up this
    // task
    waitFor("Waiting for task to finish", new Checker() {

        public boolean check() throws ObjectNotFoundException, SchemaException {
            Task task = taskManager.getTask(TASK_USER_RECOMPUTE_OID, result);
            // wait until the task is finished
            if (TaskExecutionStatus.CLOSED == task.getExecutionStatus()) {
                return true;
            }
            return false;
        }

        @Override
        public void timeout() {
        // No reaction, the test will fail right after return from this
        }
    }, 40000);
    // wait a second until the task will be definitely saved
    Thread.sleep(1000);
    // Check task status
    Task task = taskManager.getTask(TASK_USER_RECOMPUTE_OID, result);
    result.computeStatus();
    display("getTask result", result);
    TestUtil.assertSuccess("getTask has failed", result);
    AssertJUnit.assertNotNull(task);
    display("Task after finish", task);
    AssertJUnit.assertNotNull(task.getTaskIdentifier());
    assertFalse(task.getTaskIdentifier().isEmpty());
    PrismObject<TaskType> o = repositoryService.getObject(TaskType.class, TASK_USER_RECOMPUTE_OID, null, result);
    display("Task after pickup in the repository", o.asObjectable());
    AssertJUnit.assertEquals(TaskExecutionStatus.CLOSED, task.getExecutionStatus());
    // .. and last run should not be zero
    assertNotNull(task.getLastRunStartTimestamp());
    AssertJUnit.assertFalse(task.getLastRunStartTimestamp().longValue() == 0);
    assertNotNull(task.getLastRunFinishTimestamp());
    AssertJUnit.assertFalse(task.getLastRunFinishTimestamp().longValue() == 0);
    AssertJUnit.assertEquals(10, task.getProgress());
    // Test for presence of a result. It should be there and it should
    // indicate success
    OperationResult taskResult = task.getResult();
    display("Recompute task result", taskResult);
    AssertJUnit.assertNotNull(taskResult);
    TestUtil.assertSuccess("Recompute task result", taskResult);
    // STOP the task. We don't need it any more and we don't want to give it a chance to run more than once
    taskManager.deleteTask(TASK_USER_RECOMPUTE_OID, result);
    // CHECK RESULT: account created for user guybrush
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<UserType> object = repositoryService.getObject(UserType.class, USER_GUYBRUSH_OID, null, repoResult);
    UserType repoUser = object.asObjectable();
    repoResult.computeStatus();
    displayJaxb("User (repository)", repoUser, new QName("user"));
    List<ObjectReferenceType> accountRefs = repoUser.getLinkRef();
    assertEquals("Wrong number of accountRefs after recompute for user " + repoUser.getName(), 1, accountRefs.size());
    ObjectReferenceType accountRef = accountRefs.get(0);
    accountShadowOidGuybrushOpendj = accountRef.getOid();
    assertFalse(accountShadowOidGuybrushOpendj.isEmpty());
    // Check if shadow was created in the repo
    repoResult = new OperationResult("getObject");
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidGuybrushOpendj, null, repoResult);
    ShadowType repoShadowType = repoShadow.asObjectable();
    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject has failed", repoResult);
    displayJaxb("Shadow (repository)", repoShadowType, new QName("shadow"));
    assertNotNull(repoShadowType);
    assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
    accountGuybrushOpendjEntryUuuid = checkRepoShadow(repoShadow);
    // check if account was created in LDAP
    Entry entry = openDJController.searchAndAssertByEntryUuid(accountGuybrushOpendjEntryUuuid);
    display("LDAP account", entry);
    OpenDJController.assertAttribute(entry, "uid", "guybrush");
    OpenDJController.assertAttribute(entry, "givenName", "Guybrush");
    OpenDJController.assertAttribute(entry, "sn", "Threepwood");
    OpenDJController.assertAttribute(entry, "cn", "Guybrush Threepwood");
    OpenDJController.assertAttribute(entry, "displayName", "Guybrush Threepwood");
    // The "l" attribute is assigned indirectly through schemaHandling and
    // config object
    OpenDJController.assertAttribute(entry, "l", "Deep in the Caribbean");
    // Set by the role
    OpenDJController.assertAttribute(entry, "employeeType", "sailor");
    OpenDJController.assertAttribute(entry, "title", "Honorable Captain");
    OpenDJController.assertAttribute(entry, "carLicense", "C4PT41N");
    OpenDJController.assertAttribute(entry, "businessCategory", "cruise");
    String guybrushPassword = OpenDJController.getAttributeValue(entry, "userPassword");
    assertNotNull("Pasword was not set on create", guybrushPassword);
    checkAllShadows();
}
Also used : Checker(com.evolveum.midpoint.test.Checker) ObjectChecker(com.evolveum.midpoint.test.ObjectChecker) Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 30 with ObjectDeltaType

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

the class TestSanityLegacy method test104AssignRoleJudge.

/**
     * Judge role excludes pirate role. This assignment should fail. 
     */
@Test
public void test104AssignRoleJudge() throws Exception {
    final String TEST_NAME = "test104AssignRoleJudge";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResultType result = new OperationResultType();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>(result);
    Holder<String> oidHolder = new Holder<String>();
    assertNoRepoCache();
    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ADD_ROLE_JUDGE_FILENAME, ObjectDeltaType.class);
    try {
        // WHEN ObjectTypes.USER.getTypeQName(), 
        result = modifyObjectViaModelWS(objectChange);
        // THEN
        AssertJUnit.fail("Expected a failure after assigning conflicting roles but nothing happened and life goes on");
    } catch (FaultMessage f) {
    // This is expected
    // TODO: check if the fault is the right one
    }
    assertNoRepoCache();
    displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("modifyObject has failed", result);
    // Check if user object remain unmodified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<UserType> uObject = repositoryService.getObject(UserType.class, USER_GUYBRUSH_OID, null, repoResult);
    UserType repoUser = uObject.asObjectable();
    repoResult.computeStatus();
    display("User (repository)", repoUser);
    List<ObjectReferenceType> accountRefs = repoUser.getLinkRef();
    assertEquals("Unexpected number or accountRefs", 1, accountRefs.size());
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)165 Test (org.testng.annotations.Test)54 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)53 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)50 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)47 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)47 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)44 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)41 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)37 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)33 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)30 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)30 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)23 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)21 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)18 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 QName (javax.xml.namespace.QName)16 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)15 SystemException (com.evolveum.midpoint.util.exception.SystemException)13