Пример #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);
  }
  @Test
  public void testParseModelContextPrism() throws Exception {
    System.out.println("===[ testParseModelContextPrism ]===");

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

    // WHEN
    PrismContainer<LensContextType> lensContextType =
        prismContext.parseContainer(
            MODEL_CONTEXT_FILE, LensContextType.class, PrismContext.LANG_XML);

    // THEN
    System.out.println("Parsed LensContextType: " + lensContextType.getValue().asContainerable());
  }
  @Test
  public void testParseTaskFile() throws Exception {
    System.out.println("===[ testParseTaskFile ]===");

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

    // WHEN
    PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE, PrismContext.LANG_XML);

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

    assertTask(task);
  }
  @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);
  }