Пример #1
0
  @Test
  public void testContainerValueDiffDesciptionNoPath() throws Exception {
    System.out.println("\n\n===[ testContainerValueDiffDesciptionNoPath ]===\n");

    // GIVEN
    PrismObjectDefinition<UserType> userDef = getUserTypeDefinition();
    PrismContainerDefinition<AssignmentType> assignmentContDef =
        userDef.findContainerDefinition(UserType.F_ASSIGNMENT);

    PrismContainer<AssignmentType> ass1 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass1cval = ass1.createNewValue();
    ass1cval.setPropertyRealValue(
        AssignmentType.F_DESCRIPTION, "blah blah", PrismTestUtil.getPrismContext());

    PrismContainer<AssignmentType> ass2 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass2cval = ass2.createNewValue();
    ass2cval.setPropertyRealValue(
        AssignmentType.F_DESCRIPTION,
        "chamalalia patlama paprtala",
        PrismTestUtil.getPrismContext());

    // WHEN
    Collection<? extends ItemDelta> modifications = ass1cval.diff(ass2cval);

    // THEN
    assertNotNull(modifications);
    System.out.println(DebugUtil.debugDump(modifications));
    assertEquals("Unexpected number of midifications", 1, modifications.size());
    PrismAsserts.assertPropertyReplace(
        modifications,
        new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION),
        "chamalalia patlama paprtala");
    ItemDelta.checkConsistence(modifications);
  }
 private void assertUserDrakeContent(PrismObject<UserType> user, boolean assertDefinitions) {
   // fullName
   PrismProperty fullNameProperty = user.findProperty(USER_FULLNAME_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(fullNameProperty, DOMUtil.XSD_STRING, 1, 1);
   assertEquals("Wrong fullname", "Sir Fancis Drake", fullNameProperty.getValue().getValue());
   // activation
   PrismContainer activationContainer = user.findContainer(USER_ACTIVATION_QNAME);
   assertEquals(USER_ACTIVATION_QNAME, activationContainer.getElementName());
   if (assertDefinitions)
     PrismAsserts.assertDefinition(activationContainer, ACTIVATION_TYPE_QNAME, 0, 1);
   // activation/enabled
   PrismProperty enabledProperty = user.findProperty(USER_ENABLED_PATH);
   assertEquals(USER_ENABLED_QNAME, enabledProperty.getElementName());
   if (assertDefinitions)
     PrismAsserts.assertDefinition(enabledProperty, DOMUtil.XSD_BOOLEAN, 0, 1);
   assertEquals("Wrong enabled", true, enabledProperty.getValue().getValue());
   // assignment
   PrismContainer assignmentContainer = user.findContainer(USER_ASSIGNMENT_QNAME);
   assertEquals(USER_ASSIGNMENT_QNAME, assignmentContainer.getElementName());
   if (assertDefinitions)
     PrismAsserts.assertDefinition(assignmentContainer, ASSIGNMENT_TYPE_QNAME, 0, -1);
   // assignment values
   List<PrismContainerValue> assValues = assignmentContainer.getValues();
   assertEquals("Wrong number of assignment values", 3, assValues.size());
   // assignment values: blue
   PrismContainerValue assBlueValue = assValues.get(0);
   PrismProperty assBlueDescriptionProperty = assBlueValue.findProperty(USER_DESCRIPTION_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(assBlueDescriptionProperty, DOMUtil.XSD_STRING, 0, 1);
   assertEquals(
       "Wrong blue assignment description",
       "Assignment created out of the blue",
       assBlueDescriptionProperty.getValue().getValue());
   // assignment values: cyan
   PrismContainerValue assCyanValue = assValues.get(1);
   PrismProperty assCyanDescriptionProperty = assCyanValue.findProperty(USER_DESCRIPTION_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(assCyanDescriptionProperty, DOMUtil.XSD_STRING, 0, 1);
   assertEquals(
       "Wrong cyan assignment description",
       "Assignment created out of the cyan",
       assCyanDescriptionProperty.getValue().getValue());
   // assignment values: red
   PrismContainerValue assRedValue = assValues.get(2);
   PrismProperty assRedDescriptionProperty = assRedValue.findProperty(USER_DESCRIPTION_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(assRedDescriptionProperty, DOMUtil.XSD_STRING, 0, 1);
   assertEquals(
       "Wrong red assignment description",
       "Assignment created out of the red",
       assRedDescriptionProperty.getValue().getValue());
   // accountRef
   PrismReference accountRef = user.findReference(USER_ACCOUNTREF_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(accountRef, OBJECT_REFERENCE_TYPE_QNAME, 0, -1);
   PrismAsserts.assertReferenceValue(accountRef, ACCOUNT1_OID);
   PrismAsserts.assertReferenceValue(accountRef, ACCOUNT2_OID);
   assertEquals("accountRef size", 2, accountRef.getValues().size());
   PrismAsserts.assertParentConsistency(user);
 }
  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

  }