Search in sources :

Example 46 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class TestParseTaskBulkAction method testParseTaskRoundtrip.

@Test
public void testParseTaskRoundtrip() throws Exception {
    // 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.xmlSerializer().serialize(task);
    System.out.println("serialized task:");
    System.out.println(serializedTask);
    // RE-PARSE
    RootXNode reparsedToXNode = prismContext.parserFor(serializedTask).xml().parseToXNode();
    System.out.println("Re-parsed task (to XNode):");
    System.out.println(reparsedToXNode.debugDump());
    // real reparse
    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);
}
Also used : TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) Test(org.testng.annotations.Test)

Example 47 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class TestParseTaskBulkAction method testParseTaskFileToXNode.

@Test
public void testParseTaskFileToXNode() throws Exception {
    // 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));
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) Test(org.testng.annotations.Test)

Example 48 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class TestParseForm method testParseToXNode.

@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));
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) Test(org.testng.annotations.Test)

Example 49 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class TestParseResource method testParseResourceDom.

// todo eliminate dependency on prism-impl
@Test
public void testParseResourceDom() throws Exception {
    if (!"xml".equals(language)) {
        return;
    }
    // GIVEN
    PrismContext prismContext = getPrismContext();
    // WHEN
    DomLexicalProcessor parserDom = ((PrismContextImpl) prismContext).getParserDom();
    RootXNode xnode = parserDom.read(new ParserFileSource(getFile(TestConstants.RESOURCE_FILE_BASENAME)), createDefaultParsingContext());
    PrismObject<ResourceType> resource = prismContext.parserFor(xnode).parse();
    // THEN
    System.out.println("Parsed resource:");
    System.out.println(resource.debugDump());
    assertResource(resource, true, true, false);
}
Also used : DomLexicalProcessor(com.evolveum.midpoint.prism.impl.lex.dom.DomLexicalProcessor) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PrismContextImpl(com.evolveum.midpoint.prism.impl.PrismContextImpl) Test(org.testng.annotations.Test)

Example 50 with RootXNode

use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.

the class TestParseScriptingExpression method testParseToXNode.

@Test
public void testParseToXNode() throws Exception {
    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));
}
Also used : ComplexTypeDefinition(com.evolveum.midpoint.prism.ComplexTypeDefinition) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) Test(org.testng.annotations.Test)

Aggregations

RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)51 Test (org.testng.annotations.Test)22 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)14 QName (javax.xml.namespace.QName)13 XNode (com.evolveum.midpoint.prism.xnode.XNode)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)7 NotNull (org.jetbrains.annotations.NotNull)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)4 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)3 ArrayList (java.util.ArrayList)3 ResourceType (com.evolveum.midpoint.prism.foo.ResourceType)2 UserType (com.evolveum.midpoint.prism.foo.UserType)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 Element (org.w3c.dom.Element)2