@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 void fillInUserDrake(PrismObject<UserType> user, boolean assertDefinitions) throws SchemaException { user.setOid(USER_OID); // fullName PrismProperty<String> fullNameProperty = user.findOrCreateProperty(USER_FULLNAME_QNAME); assertEquals(USER_FULLNAME_QNAME, fullNameProperty.getElementName()); PrismAsserts.assertParentConsistency(user); if (assertDefinitions) PrismAsserts.assertDefinition(fullNameProperty, DOMUtil.XSD_STRING, 1, 1); fullNameProperty.setValue(new PrismPropertyValue<String>("Sir Fancis Drake")); PrismProperty<String> fullNamePropertyAgain = user.findOrCreateProperty(USER_FULLNAME_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that // is was not created again assertTrue("Property not the same", fullNameProperty == fullNamePropertyAgain); // activation PrismContainer<ActivationType> activationContainer = user.findOrCreateContainer(USER_ACTIVATION_QNAME); assertEquals(USER_ACTIVATION_QNAME, activationContainer.getElementName()); PrismAsserts.assertParentConsistency(user); if (assertDefinitions) PrismAsserts.assertDefinition(activationContainer, ACTIVATION_TYPE_QNAME, 0, 1); PrismContainer<ActivationType> activationContainerAgain = user.findOrCreateContainer(USER_ACTIVATION_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that // is was not created again assertTrue("Property not the same", activationContainer == activationContainerAgain); // activation/enabled PrismProperty<Boolean> enabledProperty = user.findOrCreateProperty(USER_ENABLED_PATH); assertEquals(USER_ENABLED_QNAME, enabledProperty.getElementName()); PrismAsserts.assertParentConsistency(user); if (assertDefinitions) PrismAsserts.assertDefinition(enabledProperty, DOMUtil.XSD_BOOLEAN, 0, 1); enabledProperty.setValue(new PrismPropertyValue<Boolean>(true)); PrismProperty<Boolean> enabledPropertyAgain = activationContainer.findOrCreateProperty(USER_ENABLED_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that // is was not created again assertTrue("Property not the same", enabledProperty == enabledPropertyAgain); // assignment // Try to create this one from the value. It should work the same, but let's test a different // code path PrismContainer<AssignmentType> assignmentContainer = user.getValue().findOrCreateContainer(USER_ASSIGNMENT_QNAME); assertEquals(USER_ASSIGNMENT_QNAME, assignmentContainer.getElementName()); PrismAsserts.assertParentConsistency(user); if (assertDefinitions) PrismAsserts.assertDefinition(assignmentContainer, ASSIGNMENT_TYPE_QNAME, 0, -1); PrismContainer<AssignmentType> assignmentContainerAgain = user.findOrCreateContainer(USER_ASSIGNMENT_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that // is was not created again assertTrue("Property not the same", assignmentContainer == assignmentContainerAgain); assertEquals( "Wrong number of assignment values (empty)", 0, assignmentContainer.getValues().size()); // assignment values: construct assignment value as a new container "out of the blue" and then // add it. PrismContainer<AssignmentType> assBlueContainer = new PrismContainer<AssignmentType>(USER_ASSIGNMENT_QNAME); PrismProperty<String> assBlueDescriptionProperty = assBlueContainer.findOrCreateProperty(USER_DESCRIPTION_QNAME); assBlueDescriptionProperty.addValue( new PrismPropertyValue<String>("Assignment created out of the blue")); PrismAsserts.assertParentConsistency(user); assignmentContainer.mergeValues(assBlueContainer); assertEquals( "Wrong number of assignment values (after blue)", 1, assignmentContainer.getValues().size()); PrismAsserts.assertParentConsistency(user); // assignment values: construct assignment value as a new container value "out of the blue" and // then add it. PrismContainerValue<AssignmentType> assCyanContainerValue = new PrismContainerValue<AssignmentType>(); PrismProperty<String> assCyanDescriptionProperty = assCyanContainerValue.findOrCreateProperty(USER_DESCRIPTION_QNAME); assCyanDescriptionProperty.addValue( new PrismPropertyValue<String>("Assignment created out of the cyan")); assignmentContainer.mergeValue(assCyanContainerValue); assertEquals( "Wrong number of assignment values (after cyan)", 2, assignmentContainer.getValues().size()); PrismAsserts.assertParentConsistency(user); // assignment values: construct assignment value from existing container PrismContainerValue<AssignmentType> assRedContainerValue = assignmentContainer.createNewValue(); PrismProperty<String> assRedDescriptionProperty = assRedContainerValue.findOrCreateProperty(USER_DESCRIPTION_QNAME); assRedDescriptionProperty.addValue( new PrismPropertyValue<String>("Assignment created out of the red")); assertEquals( "Wrong number of assignment values (after red)", 3, assignmentContainer.getValues().size()); PrismAsserts.assertParentConsistency(user); // accountRef PrismReference accountRef = user.findOrCreateReference(USER_ACCOUNTREF_QNAME); assertEquals(USER_ACCOUNTREF_QNAME, accountRef.getElementName()); if (assertDefinitions) PrismAsserts.assertDefinition(accountRef, OBJECT_REFERENCE_TYPE_QNAME, 0, -1); accountRef.add(new PrismReferenceValue(ACCOUNT1_OID)); accountRef.add(new PrismReferenceValue(ACCOUNT2_OID)); PrismReference accountRefAgain = user.findOrCreateReference(USER_ACCOUNTREF_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that // is was not created again assertTrue("Property not the same", accountRef == accountRefAgain); assertEquals("accountRef size", 2, accountRef.getValues().size()); PrismAsserts.assertParentConsistency(user); // extension PrismContainer<?> extensionContainer = user.findOrCreateContainer(USER_EXTENSION_QNAME); assertEquals(USER_EXTENSION_QNAME, extensionContainer.getElementName()); PrismAsserts.assertParentConsistency(user); if (assertDefinitions) PrismAsserts.assertDefinition(extensionContainer, DOMUtil.XSD_ANY, 0, 1); PrismContainer<AssignmentType> extensionContainerAgain = user.findOrCreateContainer(USER_EXTENSION_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that // is was not created again assertTrue("Extension not the same", extensionContainer == extensionContainerAgain); assertEquals( "Wrong number of extension values (empty)", 0, extensionContainer.getValues().size()); // extension / stringType PrismProperty<String> stringTypeProperty = extensionContainer.findOrCreateProperty(EXTENSION_STRING_TYPE_ELEMENT); assertEquals(EXTENSION_STRING_TYPE_ELEMENT, stringTypeProperty.getElementName()); PrismAsserts.assertParentConsistency(user); if (assertDefinitions) PrismAsserts.assertDefinition(stringTypeProperty, DOMUtil.XSD_STRING, 0, -1); // TODO }