Search in sources :

Example 81 with PropertyDelta

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
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Collection(java.util.Collection) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 82 with PropertyDelta

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 83 with PropertyDelta

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationProvisioningScriptsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationProvisioningScriptsType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) Test(org.testng.annotations.Test)

Aggregations

PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)83 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)51 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)36 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)25 QName (javax.xml.namespace.QName)24 Test (org.testng.annotations.Test)24 ArrayList (java.util.ArrayList)22 Task (com.evolveum.midpoint.task.api.Task)21 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)11 SystemException (com.evolveum.midpoint.util.exception.SystemException)11 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)11 Collection (java.util.Collection)11 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)10 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)10 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)10 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)9 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)8