use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestTolerantAttributes method test105modifyAddNonTolerantAttribute.
@Test
public void test105modifyAddNonTolerantAttribute() throws Exception {
TestUtil.displayTestTile(this, "test105modifyAddNonTolerantAttribute");
// GIVEN
Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test105modifyAddNonTolerantAttribute");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
ObjectDelta<ShadowType> userDelta = ObjectDelta.createEmptyModifyDelta(ShadowType.class, accountOid, prismContext);
ItemPath drinkItemPath = new ItemPath(ShadowType.F_ATTRIBUTES, new QName(RESOURCE_DUMMY_BLACK_NAMESPACE, "drink"));
assertNotNull("null definition for drink attribute ", accountDefinition.findPropertyDefinition(drinkItemPath));
PropertyDelta propertyDelta = PropertyDelta.createModificationAddProperty(drinkItemPath, accountDefinition.findPropertyDefinition(drinkItemPath), "This should be ignored");
userDelta.addModification(propertyDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
try {
modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, result);
fail("Expected Policy violation exception, because non-tolerant attribute is modified, but haven't got one.");
} catch (PolicyViolationException ex) {
//this is expected
}
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestDummy method test502ModifyProtectedAccountShadowAttributes.
/**
* Attribute modification should fail.
*/
@Test
public void test502ModifyProtectedAccountShadowAttributes() throws Exception {
final String TEST_NAME = "test502ModifyProtectedAccountShadowAttributes";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
syncServiceMock.reset();
Collection<? extends ItemDelta> modifications = new ArrayList<ItemDelta>(1);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
ResourceAttributeDefinition fullnameAttrDef = defaultAccountDefinition.findAttributeDefinition("fullname");
ResourceAttribute fullnameAttr = fullnameAttrDef.instantiate();
PropertyDelta fullnameDelta = fullnameAttr.createDelta(new ItemPath(ShadowType.F_ATTRIBUTES, fullnameAttrDef.getName()));
fullnameDelta.setValueToReplace(new PrismPropertyValue<String>("Good Daemon"));
((Collection) modifications).add(fullnameDelta);
// WHEN
try {
provisioningService.modifyObject(ShadowType.class, ACCOUNT_DAEMON_OID, modifications, null, null, task, result);
AssertJUnit.fail("Expected security exception while modifying 'daemon' account");
} catch (SecurityViolationException e) {
// This is expected
display("Expected exception", e);
}
result.computeStatus();
display("modifyObject result (expected failure)", result);
TestUtil.assertFailure(result);
syncServiceMock.assertNotifyFailureOnly();
// checkConsistency();
assertSteadyResource();
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestDummyPrioritiesAndReadReplace method test150ModifyObjectAddDelete.
@Test
public void test150ModifyObjectAddDelete() throws Exception {
final String TEST_NAME = "test150ModifyObjectAddDelete";
TestUtil.displayTestTile(TEST_NAME);
Task task = taskManager.createTaskInstance(TestDummyPrioritiesAndReadReplace.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
syncServiceMock.reset();
// NOT a read replace attribute
// todo add correct definition
ObjectDelta<ShadowType> objectDelta = ObjectDelta.createModificationReplaceProperty(ShadowType.class, ACCOUNT_WILL_OID, dummyResourceCtl.getAttributeFullnamePath(), prismContext, "Pirate Great Master Will Turner");
// read replace attribute, priority 0
PropertyDelta weaponDelta = objectDelta.createPropertyModification(dummyResourceCtl.getAttributeWeaponPath());
weaponDelta.setDefinition(getAttributeDefinition(resourceType, ShadowKindType.ACCOUNT, null, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME));
weaponDelta.addValuesToAdd(new PrismPropertyValue<>("Sword"));
// case-insensitive treatment should work here
weaponDelta.addValuesToDelete(new PrismPropertyValue<>("GUN"));
objectDelta.addModification(weaponDelta);
// read replace attribute, priority 1
PropertyDelta lootDelta = objectDelta.createPropertyModification(dummyResourceCtl.getAttributeLootPath());
lootDelta.setDefinition(getAttributeDefinition(resourceType, ShadowKindType.ACCOUNT, null, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME));
lootDelta.addValuesToAdd(new PrismPropertyValue<>(44));
lootDelta.addValuesToDelete(new PrismPropertyValue<>(43));
objectDelta.addModification(lootDelta);
// NOT a read-replace attribute
PropertyDelta titleDelta = objectDelta.createPropertyModification(dummyResourceCtl.getAttributePath(DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME));
titleDelta.setDefinition(getAttributeDefinition(resourceType, ShadowKindType.ACCOUNT, null, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME));
titleDelta.addValuesToAdd(new PrismPropertyValue<>("Pirate Great Master"));
titleDelta.addValuesToDelete(new PrismPropertyValue<>("Pirate Master"));
objectDelta.addModification(titleDelta);
// read replace attribute
PropertyDelta drinkDelta = objectDelta.createPropertyModification(dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME));
drinkDelta.setDefinition(getAttributeDefinition(resourceType, ShadowKindType.ACCOUNT, null, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME));
drinkDelta.addValuesToAdd(new PrismPropertyValue<>("orange juice"));
objectDelta.addModification(drinkDelta);
display("ObjectDelta", objectDelta);
objectDelta.checkConsistence();
// WHEN
provisioningService.modifyObject(ShadowType.class, objectDelta.getOid(), objectDelta.getModifications(), new OperationProvisioningScriptsType(), null, task, result);
// THEN
result.computeStatus();
display("modifyObject result", result);
TestUtil.assertSuccess(result);
objectDelta.checkConsistence();
assertDummyAccountAttributeValues(ACCOUNT_WILL_USERNAME, willIcfUid, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Pirate Great Master Will Turner");
assertDummyAccountAttributeValues(ACCOUNT_WILL_USERNAME, willIcfUid, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate Great Master");
assertDummyAccountAttributeValues(ACCOUNT_WILL_USERNAME, willIcfUid, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 44);
assertDummyAccountAttributeValues(ACCOUNT_WILL_USERNAME, willIcfUid, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Sword");
assertDummyAccountAttributeValues(ACCOUNT_WILL_USERNAME, willIcfUid, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "orange juice");
// BEWARE: very brittle!
List<OperationResult> updatesExecuted = TestUtil.selectSubresults(result, ProvisioningTestUtil.CONNID_CONNECTOR_FACADE_CLASS_NAME + ".update", ProvisioningTestUtil.CONNID_CONNECTOR_FACADE_CLASS_NAME + ".addAttributeValues", ProvisioningTestUtil.CONNID_CONNECTOR_FACADE_CLASS_NAME + ".removeAttributeValues");
assertEquals("Wrong number of updates executed", 5, updatesExecuted.size());
// prio 0, read-replace
checkAttributesUpdated(updatesExecuted.get(0), "update", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME);
// prio 1, read-replace
checkAttributesUpdated(updatesExecuted.get(1), "update", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME);
// prio none, not read-replace
checkAttributesUpdated(updatesExecuted.get(2), "addAttributeValues", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME);
// prio none, read-replace + real replace
checkAttributesUpdated(updatesExecuted.get(3), "update", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME);
// prio none, not read-replace
checkAttributesUpdated(updatesExecuted.get(4), "removeAttributeValues", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME);
syncServiceMock.assertNotifySuccessOnly();
//assertSteadyResource();
}
Aggregations