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);
}
}
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);
}
}
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());
}
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);
}
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());
}
}
Aggregations