Search in sources :

Example 11 with ObjectModificationType

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

the class OrgStructTest method test002modifyOrgStructAddRefIncorrect.

@Test
public void test002modifyOrgStructAddRefIncorrect() throws Exception {
    OperationResult opResult = new OperationResult("test002modifyOrgStructAddRefIncorrect");
    // test modification of org ref in another org type..
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_INCORRECT_ADD_REF_FILENAME), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<OrgType> delta = DeltaConvertor.createObjectDelta(modification, OrgType.class, prismContext);
    repositoryService.modifyObject(OrgType.class, MODIFY_ORG_INCORRECT_ADD_REF_OID, delta.getModifications(), opResult);
    Session session = open();
    try {
        List<ROrgClosure> orgClosure = getOrgClosureByDescendant(MODIFY_ORG_INCORRECT_ADD_REF_OID, session);
        LOGGER.info("after modify incorrect - closure");
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}\t{}", new Object[] { c.getAncestor().getOid(), c.getDescendant().getOid() });
        }
        AssertJUnit.assertEquals(5, orgClosure.size());
        List<String> ancestors = new ArrayList<String>();
        ancestors.add(MODIFY_ORG_INCORRECT_ADD_REF_OID);
        ancestors.add(ORG_F001_OID);
        ancestors.add(ORG_F002_OID);
        for (String ancestorOid : ancestors) {
            orgClosure = getOrgClosure(ancestorOid, MODIFY_ORG_INCORRECT_ADD_REF_OID, session);
            AssertJUnit.assertEquals(1, orgClosure.size());
            AssertJUnit.assertEquals(ancestorOid, orgClosure.get(0).getAncestor().getOid());
            AssertJUnit.assertEquals(MODIFY_ORG_INCORRECT_ADD_REF_OID, orgClosure.get(0).getDescendant().getOid());
        }
    } finally {
        close(session);
    }
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 12 with ObjectModificationType

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

the class OrgStructTest method test002modifyOrgStructAddRef.

@Test
public void test002modifyOrgStructAddRef() throws Exception {
    OperationResult opResult = new OperationResult("test002modifyOrgStructAddRef");
    // test modification of org ref in another org type..
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_ADD_REF_FILENAME), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<OrgType> delta = DeltaConvertor.createObjectDelta(modification, OrgType.class, prismContext);
    Query query;
    List<ROrgClosure> orgClosure;
    Session session = open();
    try {
        orgClosure = getOrgClosureByDescendant(MODIFY_ORG_ADD_REF_OID, session);
        LOGGER.info("before modify");
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}\t{}", new Object[] { c.getAncestor().getOid(), c.getDescendant().getOid() });
        }
        AssertJUnit.assertEquals(3, orgClosure.size());
    } finally {
        close(session);
    }
    repositoryService.modifyObject(OrgType.class, MODIFY_ORG_ADD_REF_OID, delta.getModifications(), opResult);
    session = open();
    try {
        orgClosure = getOrgClosureByDescendant(MODIFY_ORG_ADD_REF_OID, session);
        LOGGER.info("after modify");
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}\t{}", new Object[] { c.getAncestor().getOid(), c.getDescendant().getOid() });
        }
        AssertJUnit.assertEquals(4, orgClosure.size());
        List<String> ancestors = new ArrayList<String>();
        ancestors.add(MODIFY_ORG_ADD_REF_OID);
        ancestors.add(ORG_F003_OID);
        ancestors.add(ORG_F001_OID);
        ancestors.add(ORG_F002_OID);
        for (String ancestorOid : ancestors) {
            orgClosure = getOrgClosure(ancestorOid, MODIFY_ORG_ADD_REF_OID, session);
            LOGGER.info("=> A: {}, D: {}", orgClosure.get(0).getAncestor(), orgClosure.get(0).getDescendant());
            AssertJUnit.assertEquals(1, orgClosure.size());
            AssertJUnit.assertEquals(ancestorOid, orgClosure.get(0).getAncestor().getOid());
            AssertJUnit.assertEquals(MODIFY_ORG_ADD_REF_OID, orgClosure.get(0).getDescendant().getOid());
        }
    } finally {
        close(session);
    }
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) Query(org.hibernate.Query) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 13 with ObjectModificationType

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

the class ModifyTest method test100ModifyUserAddRole.

@Test
public void test100ModifyUserAddRole() throws Exception {
    final String TEST_NAME = "test100ModifyUserAddRole";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult parentResult = new OperationResult("Modify user -> add roles");
    String userToModifyOid = "f65963e3-9d47-4b18-aaf3-bfc98bdfa000";
    PrismObject<ResourceType> csvResource = prismContext.parseObject(new File(TEST_DIR + "/resource-csv.xml"));
    repositoryService.addObject(csvResource, null, parentResult);
    PrismObject<ResourceType> openDjResource = prismContext.parseObject(new File(TEST_DIR + "/resource-opendj.xml"));
    repositoryService.addObject(openDjResource, null, parentResult);
    PrismObject<UserType> user = prismContext.parseObject(new File(TEST_DIR + "/user.xml"));
    repositoryService.addObject(user, null, parentResult);
    PrismObject<RoleType> roleCsv = prismContext.parseObject(new File(TEST_DIR + "/role-csv.xml"));
    repositoryService.addObject(roleCsv, null, parentResult);
    String ldapRoleOid = "12345678-d34d-b33f-f00d-987987987988";
    PrismObject<RoleType> roleLdap = prismContext.parseObject(new File(TEST_DIR + "/role-ldap.xml"));
    repositoryService.addObject(roleLdap, null, parentResult);
    RoleType ldapRole = repositoryService.getObject(RoleType.class, ldapRoleOid, null, parentResult).asObjectable();
    assertEquals("Expected that the role has one approver.", 1, ldapRole.getApproverRef().size());
    assertEquals("Actual approved not equals to expected one.", userToModifyOid, ldapRole.getApproverRef().get(0).getOid());
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(TEST_DIR + "/modify-user-add-roles.xml"), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta delta = DeltaConvertor.createObjectDelta(modification, UserType.class, prismContext);
    repositoryService.modifyObject(UserType.class, userToModifyOid, delta.getModifications(), getModifyOptions(), parentResult);
    UserType modifiedUser = repositoryService.getObject(UserType.class, userToModifyOid, null, parentResult).asObjectable();
    assertEquals("wrong number of assignments", 3, modifiedUser.getAssignment().size());
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) File(java.io.File) Test(org.testng.annotations.Test)

Example 14 with ObjectModificationType

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

the class ModifyTest method test010ModifyWithExistingName.

@Test(expectedExceptions = SystemException.class, enabled = false)
public void test010ModifyWithExistingName() throws Exception {
    final String TEST_NAME = "test010ModifyWithExistingName";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult result = new OperationResult("MODIFY");
    File userFile = new File(TEST_DIR, "modify-user.xml");
    //add first user
    PrismObject<UserType> user = prismContext.parseObject(userFile);
    user.setOid(null);
    user.setPropertyRealValue(ObjectType.F_NAME, "existingName");
    repositoryService.addObject(user, null, result);
    //add second user
    user = prismContext.parseObject(userFile);
    user.setOid(null);
    user.setPropertyRealValue(ObjectType.F_NAME, "otherName");
    String oid = repositoryService.addObject(user, null, result);
    //modify second user name to "existingName"
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "change-name.xml"), ObjectModificationType.COMPLEX_TYPE);
    modification.setOid(oid);
    Collection<? extends ItemDelta> deltas = DeltaConvertor.toModifications(modification, UserType.class, prismContext);
    repositoryService.modifyObject(UserType.class, oid, deltas, result);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 15 with ObjectModificationType

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

the class ModifyTest method test150ModifyRoleAddInducements.

@Test
public void test150ModifyRoleAddInducements() throws Exception {
    final String TEST_NAME = "test150ModifyRoleAddInducements";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult result = new OperationResult(TEST_NAME);
    File roleFile = new File(TEST_DIR, "role-modify.xml");
    //add first user
    PrismObject<RoleType> role = prismContext.parseObject(roleFile);
    String oid = repositoryService.addObject(role, null, result);
    //modify second user name to "existingName"
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "role-modify-change.xml"), ObjectModificationType.COMPLEX_TYPE);
    modification.setOid(oid);
    Collection<? extends ItemDelta> deltas = DeltaConvertor.toModifications(modification, RoleType.class, prismContext);
    repositoryService.modifyObject(RoleType.class, oid, deltas, getModifyOptions(), result);
    result.recomputeStatus();
    AssertJUnit.assertTrue(result.isSuccess());
    role = repositoryService.getObject(RoleType.class, oid, null, result);
    result.recomputeStatus();
    AssertJUnit.assertTrue(result.isSuccess());
    PrismContainer container = role.findContainer(RoleType.F_INDUCEMENT);
    assertEquals(2, container.size());
    AssertJUnit.assertNotNull(container.getValue(2L));
    AssertJUnit.assertNotNull(container.getValue(3L));
    // modify role once more to check version progress
    String version = role.getVersion();
    repositoryService.modifyObject(RoleType.class, oid, new ArrayList<ItemDelta>(), getModifyOptions(), result);
    result.recomputeStatus();
    AssertJUnit.assertTrue(result.isSuccess());
    role = repositoryService.getObject(RoleType.class, oid, null, result);
    result.recomputeStatus();
    AssertJUnit.assertTrue(result.isSuccess());
    if (RepoModifyOptions.isExecuteIfNoChanges(getModifyOptions())) {
        SqlRepoTestUtil.assertVersionProgress(version, role.getVersion());
    } else {
        assertEquals("Version has changed", version, role.getVersion());
    }
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)45 Test (org.testng.annotations.Test)40 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)31 File (java.io.File)31 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)8 Task (com.evolveum.midpoint.task.api.Task)7 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)4 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)3 QName (javax.xml.namespace.QName)3 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2