@Test public void testUserSimplePropertyDiffReplace() throws Exception { System.out.println("\n\n===[ testUserSimplePropertyDiffReplace ]===\n"); // GIVEN PrismObjectDefinition<UserType> userDef = getUserTypeDefinition(); PrismObject<UserType> user1 = userDef.instantiate(); user1.setOid(USER_JACK_OID); user1.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("test name")); PrismObject<UserType> user2 = userDef.instantiate(); user2.setOid(USER_JACK_OID); user2.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("other name")); // WHEN ObjectDelta<UserType> delta = user1.diff(user2); // THEN assertNotNull(delta); System.out.println(delta.debugDump()); assertEquals("Unexpected number of midifications", 1, delta.getModifications().size()); PrismAsserts.assertPropertyReplace( delta, UserType.F_NAME, PrismTestUtil.createPolyString("other name")); assertEquals("Wrong OID", USER_JACK_OID, delta.getOid()); delta.checkConsistence(); }
@Test public void testUserSimpleDiffMultiAdd() throws Exception { System.out.println("\n\n===[ testUserSimpleDiffMulti ]===\n"); // GIVEN PrismObjectDefinition<UserType> userDef = getUserTypeDefinition(); PrismObject<UserType> user1 = userDef.instantiate(); user1.setOid(USER_JACK_OID); PrismProperty<String> anamesProp1 = user1.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); anamesProp1.addRealValue("foo"); anamesProp1.addRealValue("bar"); PrismObject<UserType> user2 = userDef.instantiate(); user2.setOid(USER_JACK_OID); PrismProperty<String> anamesProp2 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); anamesProp2.addRealValue("foo"); anamesProp2.addRealValue("bar"); anamesProp2.addRealValue("baz"); // WHEN ObjectDelta<UserType> delta = user1.diff(user2); // THEN assertNotNull(delta); System.out.println(delta.debugDump()); assertEquals("Unexpected number of midifications", 1, delta.getModifications().size()); PrismAsserts.assertPropertyAdd(delta, UserType.F_ADDITIONAL_NAMES, "baz"); assertEquals("Wrong OID", USER_JACK_OID, delta.getOid()); delta.checkConsistence(); }
private ObjectDelta createAddingObjectDelta() throws SchemaException { PrismObject object = this.object.clone(); List<ContainerWrapper> containers = getContainers(); // sort containers by path size Collections.sort(containers, new PathSizeComparator()); for (ContainerWrapper containerWrapper : getContainers()) { if (containerWrapper.getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) { PrismContainer associationContainer = object.findOrCreateContainer(ShadowType.F_ASSOCIATION); List<AssociationWrapper> associationItemWrappers = (List<AssociationWrapper>) containerWrapper.getItems(); for (AssociationWrapper associationItemWrapper : associationItemWrappers) { List<ValueWrapper> assocValueWrappers = associationItemWrapper.getValues(); for (ValueWrapper assocValueWrapper : assocValueWrappers) { PrismContainerValue<ShadowAssociationType> assocValue = (PrismContainerValue<ShadowAssociationType>) assocValueWrapper.getValue(); associationContainer.add(assocValue.clone()); } } continue; } if (!containerWrapper.hasChanged()) { continue; } PrismContainer container = containerWrapper.getItem(); ItemPath path = containerWrapper.getPath(); if (containerWrapper.getPath() != null) { container = container.clone(); if (path.size() > 1) { ItemPath parentPath = path.allExceptLast(); PrismContainer parent = object.findOrCreateContainer(parentPath); parent.add(container); } else { PrismContainer existing = object.findContainer(container.getElementName()); if (existing == null) { object.add(container); } else { continue; } } } else { container = object; } for (ItemWrapper propertyWrapper : (List<ItemWrapper>) containerWrapper.getItems()) { if (!propertyWrapper.hasChanged()) { continue; } Item property = propertyWrapper.getItem().clone(); if (container.findProperty(property.getElementName()) != null) { continue; } for (ValueWrapper valueWrapper : propertyWrapper.getValues()) { valueWrapper.normalize(object.getPrismContext()); if (!valueWrapper.hasValueChanged() || ValueStatus.DELETED.equals(valueWrapper.getStatus())) { continue; } if (property.hasRealValue(valueWrapper.getValue())) { continue; } PrismValue cloned = clone(valueWrapper.getValue()); if (cloned != null) { property.add(cloned); } } if (!property.isEmpty()) { container.add(property); } } } // cleanup empty containers cleanupEmptyContainers(object); ObjectDelta delta = ObjectDelta.createAddDelta(object); // returning container to previous order Collections.sort(containers, new ItemWrapperComparator()); if (InternalsConfig.consistencyChecks) { delta.checkConsistence(true, true, true, ConsistencyCheckScope.THOROUGH); } return delta; }