use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class TestOrgStruct method test305JackConflictZeroAndMinus.
/**
* Conflict: removing the role assignment (that should remove org assignment), while keeping explicit org assignment present
*/
@Test
public void test305JackConflictZeroAndMinus() throws Exception {
final String TEST_NAME = "test305JackConflictZeroAndMinus";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add((createAssignmentModification(ROLE_DEFENDER_OID, RoleType.COMPLEX_TYPE, null, null, null, false)));
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User jack after", userJack);
assertUserOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, ORG_MINISTRY_OF_DEFENSE_OID);
assertAssignedOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, SchemaConstants.ORG_MANAGER);
assertHasOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, SchemaConstants.ORG_MANAGER);
assertHasOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, null);
// Postcondition
assertMonkeyIslandOrgSanity();
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class TestOrgStruct method test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment.
// this test should generate a SchemaException (modifying targetRef in assignment should be prohibited)
@Test
public void test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment() throws Exception {
final String TEST_NAME = "test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> jack = getUser(USER_JACK_OID);
Long id = findAssignmentIdForTarget(jack, ORG_MINISTRY_OF_OFFENSE_OID);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
PrismReferenceDefinition referenceDefinition = getUserDefinition().findItemDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF), PrismReferenceDefinition.class);
ReferenceDelta referenceDelta = new ReferenceDelta(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_TARGET_REF)), referenceDefinition, prismContext);
PrismReferenceValue oldValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
PrismReferenceValue newValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
newValue.setRelation(SchemaConstants.ORG_MANAGER);
referenceDelta.addValueToDelete(oldValue);
referenceDelta.addValueToAdd(newValue);
modifications.add(referenceDelta);
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
try {
modelService.executeChanges(deltas, null, task, result);
AssertJUnit.fail("executeChanges should fail but it did not.");
} catch (SchemaException e) {
// ok!
} catch (Exception e) {
AssertJUnit.fail("executeChanges failed in the wrong way (expected SchemaException): " + e);
}
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class TestBrokenResources method test350AddResourceWrongConnectorOid.
@Test
public void test350AddResourceWrongConnectorOid() throws Exception {
final String TEST_NAME = "test350AddResourceWrongConnectorOid";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestBrokenResources.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<ResourceType> resource = PrismTestUtil.parseObject(RESOURCE_DUMMY_WRONG_CONNECTOR_OID_FILE);
ObjectDelta<ResourceType> delta = ObjectDelta.createAddDelta(resource);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
try {
// WHEN
modelService.executeChanges(deltas, null, task, result);
AssertJUnit.fail("Unexpected success");
} catch (ObjectNotFoundException e) {
// This is expected
}
// THEN
result.computeStatus();
display(result);
TestUtil.assertFailure(result);
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class TestBrokenResources method test359DeleteResourceWrongConnectorOid.
@Test
public void test359DeleteResourceWrongConnectorOid() throws Exception {
final String TEST_NAME = "test359DeleteResourceWrongConnectorOid";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestBrokenResources.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
ObjectDelta<ResourceType> delta = ObjectDelta.createDeleteDelta(ResourceType.class, RESOURCE_DUMMY_WRONG_CONNECTOR_OID_OID, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
result.computeStatus();
display("getObject result", result);
assertEquals("Expected partial errror in result", OperationResultStatus.PARTIAL_ERROR, result.getStatus());
assertNoObject(ResourceType.class, RESOURCE_DUMMY_WRONG_CONNECTOR_OID_OID, task, result);
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method unassignAllRoles.
protected void unassignAllRoles(String userOid, boolean useRawPlusRecompute) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
Task task = taskManager.createTaskInstance(AbstractModelIntegrationTest.class + ".unassignAllRoles");
OperationResult result = task.getResult();
PrismObject<UserType> user = modelService.getObject(UserType.class, userOid, null, task, result);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
for (AssignmentType assignment : user.asObjectable().getAssignment()) {
ObjectReferenceType targetRef = assignment.getTargetRef();
if (targetRef != null) {
if (targetRef.getType().equals(RoleType.COMPLEX_TYPE)) {
ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
PrismContainerValue<AssignmentType> cval = new PrismContainerValue<>(prismContext);
cval.setId(assignment.getId());
assignmentDelta.addValueToDelete(cval);
modifications.add(assignmentDelta);
}
}
}
if (modifications.isEmpty()) {
return;
}
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
modelService.executeChanges(deltas, useRawPlusRecompute ? ModelExecuteOptions.createRaw() : null, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
if (useRawPlusRecompute) {
recomputeUser(userOid, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
}
}
Aggregations