コード例 #1
0
ファイル: RUtil.java プロジェクト: kulkarnisandeep/midpoint
  public static <T> String toRepo(
      ItemDefinition parentDefinition, QName itemName, T value, PrismContext prismContext)
      throws SchemaException, JAXBException {
    if (value == null) {
      return null;
    }

    if (value instanceof Objectable) {
      return prismContext.serializeObjectToString(
          ((Objectable) value).asPrismObject(), PrismContext.LANG_XML);
    }

    ItemDefinition definition = null;
    if (parentDefinition instanceof PrismContainerDefinition) {
      definition = ((PrismContainerDefinition) parentDefinition).findItemDefinition(itemName);
      if (definition == null) {
        definition = parentDefinition;
      }
    } else {
      definition = parentDefinition;
    }

    return ValueSerializationUtil.serializeValue(
        value,
        definition,
        itemName,
        parentDefinition.getName(),
        prismContext,
        PrismContext.LANG_XML);
  }
コード例 #2
0
  @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);
  }