示例#1
0
  @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();
  }
示例#2
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);
  }
示例#3
0
  @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();
  }
 protected void assertUserJack(
     PrismObject<UserType> user,
     String name,
     String fullName,
     String givenName,
     String familyName,
     String locality) {
   assertUser(user, USER_JACK_OID, name, fullName, givenName, familyName, locality);
   UserType userType = user.asObjectable();
   PrismAsserts.assertEqualsPolyString(
       "Wrong jack honorificPrefix", "Cpt.", userType.getHonorificPrefix());
   PrismAsserts.assertEqualsPolyString(
       "Wrong jack honorificSuffix", "PhD.", userType.getHonorificSuffix());
   assertEquals(
       "Wrong jack emailAddress", "*****@*****.**", userType.getEmailAddress());
   assertEquals("Wrong jack telephoneNumber", "555-1234", userType.getTelephoneNumber());
   assertEquals("Wrong jack employeeNumber", "emp1234", userType.getEmployeeNumber());
   assertEquals("Wrong jack employeeType", "CAPTAIN", userType.getEmployeeType().get(0));
   if (locality == null) {
     assertNull("Locality sneaked to user jack", userType.getLocality());
   } else {
     PrismAsserts.assertEqualsPolyString("Wrong jack locality", locality, userType.getLocality());
   }
 }
  @Test
  public void testParseTaskRoundtrip() throws Exception {
    System.out.println("===[ testParseTaskRoundtrip ]===");

    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();

    PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE);

    System.out.println("Parsed task:");
    System.out.println(task.debugDump());

    assertTask(task);

    // SERIALIZE

    String serializedTask = prismContext.serializeObjectToString(task, PrismContext.LANG_XML);

    System.out.println("serialized task:");
    System.out.println(serializedTask);

    // RE-PARSE

    PrismObject<TaskType> reparsedTask = prismContext.parseObject(serializedTask);

    System.out.println("Re-parsed task:");
    System.out.println(reparsedTask.debugDump());

    // Cannot assert here. It will cause parsing of some of the raw values and diff will fail
    assertTask(reparsedTask);

    ObjectDelta<TaskType> objectDelta = task.diff(reparsedTask);
    System.out.println("Delta:");
    System.out.println(objectDelta.debugDump());
    assertTrue("Delta is not empty", objectDelta.isEmpty());

    PrismAsserts.assertEquivalent("Task re-parsed equivalence", task, reparsedTask);
  }
  private void assertTask(PrismObject<TaskType> task) {

    task.checkConsistence();

    assertEquals("Wrong oid", "44444444-4444-4444-4444-000000001111", task.getOid());
    PrismObjectDefinition<TaskType> usedDefinition = task.getDefinition();
    assertNotNull("No task definition", usedDefinition);
    PrismAsserts.assertObjectDefinition(
        usedDefinition,
        new QName(SchemaConstantsGenerated.NS_COMMON, "task"),
        TaskType.COMPLEX_TYPE,
        TaskType.class);
    assertEquals("Wrong class in task", TaskType.class, task.getCompileTimeClass());
    TaskType taskType = task.asObjectable();
    assertNotNull("asObjectable resulted in null", taskType);

    assertPropertyValue(task, "name", PrismTestUtil.createPolyString("Task2"));
    assertPropertyDefinition(task, "name", PolyStringType.COMPLEX_TYPE, 0, 1);

    assertPropertyValue(task, "taskIdentifier", "44444444-4444-4444-4444-000000001111");
    assertPropertyDefinition(task, "taskIdentifier", DOMUtil.XSD_STRING, 0, 1);

    assertPropertyDefinition(
        task, "executionStatus", JAXBUtil.getTypeQName(TaskExecutionStatusType.class), 1, 1);
    PrismProperty<TaskExecutionStatusType> executionStatusProperty =
        task.findProperty(TaskType.F_EXECUTION_STATUS);
    PrismPropertyValue<TaskExecutionStatusType> executionStatusValue =
        executionStatusProperty.getValue();
    TaskExecutionStatusType executionStatus = executionStatusValue.getValue();
    assertEquals("Wrong execution status", TaskExecutionStatusType.RUNNABLE, executionStatus);

    PrismContainer extension = task.getExtension();
    PrismContainerValue extensionValue = extension.getValue();
    assertTrue("Extension parent", extensionValue.getParent() == extension);
    assertNull("Extension ID", extensionValue.getId());
  }
 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

  }
 public static void assertPropertyValue(
     PrismContainer<?> container, String propName, Object propValue) {
   QName propQName = new QName(SchemaConstantsGenerated.NS_COMMON, propName);
   PrismAsserts.assertPropertyValue(container, propQName, propValue);
 }
 private void assertPropertyDefinition(
     PrismContainer<?> container, String propName, QName xsdType, int minOccurs, int maxOccurs) {
   QName propQName = new QName(SchemaConstantsGenerated.NS_COMMON, propName);
   PrismAsserts.assertPropertyDefinition(container, propQName, xsdType, minOccurs, maxOccurs);
 }