@Override protected PrismSerializer<String> getSerializer() { return prismContext.yamlSerializer(); }
@Test public void test370SerializeToYaml() throws Exception { System.out.println("===[ test370SerializeToYaml ]==="); PrismObject<UserType> jack = getJack(); measure("serialize to YAML", () -> getPrismContext().yamlSerializer().serialize(jack)); }
@Test public void testParseTaskFileToXNode() throws Exception { System.out.println("===[ testParseTaskFileToXNode ]==="); // GIVEN PrismContext prismContext = PrismTestUtil.getPrismContext(); // WHEN RootXNode node = prismContext.parserFor(TASK_FILE).xml().parseToXNode(); // THEN System.out.println("Parsed task (XNode):"); System.out.println(node.debugDump()); System.out.println("XML -> XNode -> JSON:\n" + prismContext.jsonSerializer().serialize(node)); System.out.println("XML -> XNode -> YAML:\n" + prismContext.yamlSerializer().serialize(node)); }
@Test public void testParseTaskFileToXNode() throws Exception { System.out.println("===[ testParseTaskFileToXNode ]==="); // GIVEN PrismContext prismContext = PrismTestUtil.getPrismContext(); // WHEN RootXNode node = prismContext.parserFor(TASK_FILE).xml().parseToXNode(); // THEN System.out.println("Parsed task (XNode):"); System.out.println(node.debugDump()); System.out.println("XML -> XNode -> JSON:\n" + prismContext.jsonSerializer().serialize(node)); System.out.println("XML -> XNode -> YAML:\n" + prismContext.yamlSerializer().serialize(node)); }
@Test public void testParseToXNode() throws Exception { PrismContext prismContext = PrismTestUtil.getPrismContext(); RootXNode node = prismContext.parserFor(getFile()).parseToXNode(); System.out.println("Parsed to XNode:"); System.out.println(node.debugDump()); System.out.println("XML -> XNode -> XML:\n" + prismContext.xmlSerializer().serialize(node)); System.out.println("XML -> XNode -> JSON:\n" + prismContext.jsonSerializer().serialize(node)); System.out.println("XML -> XNode -> YAML:\n" + prismContext.yamlSerializer().serialize(node)); }
@Test public void testParseToXNode() throws Exception { PrismContext prismContext = PrismTestUtil.getPrismContext(); RootXNode node = prismContext.parserFor(getFile()).parseToXNode(); System.out.println("Parsed to XNode:"); System.out.println(node.debugDump()); System.out.println("XML -> XNode -> XML:\n" + prismContext.xmlSerializer().serialize(node)); System.out.println("XML -> XNode -> JSON:\n" + prismContext.jsonSerializer().serialize(node)); System.out.println("XML -> XNode -> YAML:\n" + prismContext.yamlSerializer().serialize(node)); }
@Test public void testParseToXNode() throws Exception { displayTestTitle("testParseToXNode"); System.out.println("\n\n-----------------------------------\n"); String file = MiscUtil.readFile(getFile()); System.out.println("Original text:\n" + file); RootXNode xnode = getPrismContext().parserFor(file).parseToXNode(); System.out.println("XNode:\n" + xnode.debugDump()); System.out.println("source -> XNode -> JSON:\n" + getPrismContext().jsonSerializer().serialize(xnode)); System.out.println("source -> XNode -> YAML:\n" + getPrismContext().yamlSerializer().serialize(xnode)); System.out.println("source -> XNode -> XML:\n" + getPrismContext().xmlSerializer().serialize(xnode)); }
@Test public void testYamlSerialization() throws Exception { displayTestTitle("testParseToXNode"); String file = MiscUtil.readFile(getFile()); System.out.println("Original text:\n" + file); RootXNode xnode = getPrismContext().parserFor(file).parseToXNode(); System.out.println("XNode:\n" + xnode.debugDump()); String yaml = getPrismContext().yamlSerializer().serialize(xnode); System.out.println("source -> XNode -> YAML:\n" + yaml); PrismValue value = getPrismContext().parserFor(yaml).parseItemValue(); assertPrismPropertyValueLocal((PrismPropertyValue<ExpressionPipelineType>) value); }
@Test public void test330ParseYaml() throws Exception { System.out.println("===[ test330ParseYaml ]==="); PrismObject<UserType> jack = getJack(); String string = getPrismContext().yamlSerializer().serialize(jack); measure("parse YAML (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).yaml().parse()); measure("parse YAML to XNode (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).yaml().parse()); }
@Test public void testRoundTrip() throws Exception { displayTestTitle("testRoundTrip"); PrismContext prismContext = getPrismContext(); PrismParser parser = prismContext.parserFor(getFile()); List<PrismObject<?>> objects = parser.parseObjects(); System.out.println("Objects as parsed: " + DebugUtil.debugDump(objects)); assertEquals("Wrong # of objects", 3, objects.size()); assertEquals("Wrong class of object 1", UserType.class, objects.get(0).asObjectable().getClass()); assertEquals("Wrong class of object 2", UserType.class, objects.get(1).asObjectable().getClass()); assertEquals("Wrong class of object 2", RoleType.class, objects.get(2).asObjectable().getClass()); PrismSerializer<String> serializer = prismContext.serializerFor(language); String serializedAsObjects = serializer.serializeObjects(objects, SchemaConstants.C_OBJECTS); System.out.println("Objects as re-serialized (c:objects):\n" + serializedAsObjects); System.out.println("Re-serialized to XML:\n" + prismContext.xmlSerializer().serializeObjects(objects, SchemaConstants.C_OBJECTS)); System.out.println("Re-serialized to JSON:\n" + prismContext.jsonSerializer().serializeObjects(objects, SchemaConstants.C_OBJECTS)); System.out.println("Re-serialized to YAML:\n" + prismContext.yamlSerializer().serializeObjects(objects, SchemaConstants.C_OBJECTS)); List<PrismObject<?>> objectsReparsed = prismContext.parserFor(serializedAsObjects).parseObjects(); assertEquals("Reparsed objects are different from original ones", objects, objectsReparsed); String serializedByDefault = serializer.serializeObjects(objects, null); System.out.println("Objects as re-serialized (default method):\n" + serializedByDefault); System.out.println("Re-serialized to XML (default):\n" + prismContext.xmlSerializer().serializeObjects(objects, null)); System.out.println("Re-serialized to JSON (default):\n" + prismContext.jsonSerializer().serializeObjects(objects, null)); System.out.println("Re-serialized to YAML (default):\n" + prismContext.yamlSerializer().serializeObjects(objects, null)); List<PrismObject<?>> objectsReparsedDefault = prismContext.parserFor(serializedAsObjects).parseObjects(); assertEquals("Reparsed objects are different from original ones", objects, objectsReparsedDefault); }
@Test public void testParseToXNode() throws Exception { displayTestTitle("testParseToXNode"); ItemDefinition sequenceDef = getPrismContext().getSchemaRegistry().findItemDefinitionByElementName(SchemaConstants.S_SEQUENCE); System.out.println("sequence.substitutionHead = " + sequenceDef.getSubstitutionHead()); System.out.println("sequence.heterogeneousListItem = " + sequenceDef.isHeterogeneousListItem()); ComplexTypeDefinition sequenceCtd = getPrismContext().getSchemaRegistry().findComplexTypeDefinitionByType(sequenceDef.getTypeName()); System.out.println("ExpressionSequenceType.list = " + sequenceCtd.isListMarker()); System.out.println("\n\n-----------------------------------\n"); String file = MiscUtil.readFile(getFile()); System.out.println("Original text:\n" + file); RootXNode xnode = getPrismContext().parserFor(file).parseToXNode(); System.out.println("XNode:\n" + xnode.debugDump()); System.out.println("source -> XNode -> JSON:\n" + getPrismContext().jsonSerializer().serialize(xnode)); System.out.println("source -> XNode -> YAML:\n" + getPrismContext().yamlSerializer().serialize(xnode)); System.out.println("source -> XNode -> XML:\n" + getPrismContext().xmlSerializer().serialize(xnode)); }