Search in sources :

Example 1 with DomLexicalProcessor

use of com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor in project midpoint by Evolveum.

the class TestDomParser method testParseUserToXNode.

@Test
public void testParseUserToXNode() throws Exception {
    final String TEST_NAME = "testParseUserToXNode";
    displayTestTitle(TEST_NAME);
    // GIVEN
    DomLexicalProcessor parser = createParser();
    // WHEN
    XNode xnode = parser.read(getFile(USER_JACK_FILE_BASENAME), ParsingContext.createDefault());
    // THEN
    System.out.println("Parsed XNode:");
    System.out.println(xnode.debugDump());
    RootXNode root = getAssertXNode("root node", xnode, RootXNode.class);
    MapXNode rootMap = getAssertXNode("root subnode", root.getSubnode(), MapXNode.class);
    PrimitiveXNode<String> xname = getAssertXMapSubnode("root map", rootMap, UserType.F_NAME, PrimitiveXNode.class);
    // TODO: assert value
    ListXNode xass = getAssertXMapSubnode("root map", rootMap, UserType.F_ASSIGNMENT, ListXNode.class);
    assertEquals("assignment size", 2, xass.size());
    // TODO: asserts
    MapXNode xextension = getAssertXMapSubnode("root map", rootMap, UserType.F_EXTENSION, MapXNode.class);
}
Also used : DomLexicalProcessor(com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) Test(org.testng.annotations.Test)

Example 2 with DomLexicalProcessor

use of com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor in project midpoint by Evolveum.

the class TestXmlSerialization method testHandlingInvalidChars.

@Test
public void testHandlingInvalidChars() throws Exception {
    final String TEST_NAME = "testHandlingInvalidChars";
    displayTestTitle(TEST_NAME);
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    PrimitiveXNode<String> valOkNode = new PrimitiveXNode<>("abcdef");
    PrimitiveXNode<String> valWrongNode = new PrimitiveXNode<>("abc\1def");
    // THEN
    final DomLexicalProcessor domLexicalProcessor = ((PrismContextImpl) prismContext).getParserDom();
    String ok = domLexicalProcessor.write(valOkNode, new QName("ok"), null);
    System.out.println("correct value serialized to: " + ok);
    // todo make this less brittle with regards to serialization style
    assertEquals("Wrong serialization", "<ok>abcdef</ok>", ok.trim());
    try {
        String wrong = domLexicalProcessor.write(valWrongNode, new QName("wrong"), null);
        System.out.println("wrong value serialized to: " + wrong);
        assert false : "Wrong value serialization had to fail but it didn't!";
    } catch (RuntimeException e) {
        System.out.println("wrong value was not serialized (as expected): " + e);
        assertTrue(e.getMessage().contains("Invalid character"), "Didn't get expected error message");
    }
}
Also used : DomLexicalProcessor(com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) QName(javax.xml.namespace.QName) Test(org.testng.annotations.Test)

Example 3 with DomLexicalProcessor

use of com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor in project midpoint by Evolveum.

the class TestParseResource method testParseResourceDom.

@Test
public void testParseResourceDom() throws Exception {
    if (!"xml".equals(language)) {
        return;
    }
    final String TEST_NAME = "testParseResourceDom";
    displayTestTitle(TEST_NAME);
    // GIVEN
    PrismContext prismContext = getPrismContext();
    // WHEN
    DomLexicalProcessor parserDom = ((PrismContextImpl) prismContext).getParserDom();
    RootXNode xnode = parserDom.read(new ParserFileSource(getFile(TestConstants.RESOURCE_FILE_BASENAME)), ParsingContext.createDefault());
    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.lex.dom.DomLexicalProcessor) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) Test(org.testng.annotations.Test)

Aggregations

DomLexicalProcessor (com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor)3 Test (org.testng.annotations.Test)3 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)2 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)2 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)1 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)1 XNode (com.evolveum.midpoint.prism.xnode.XNode)1 QName (javax.xml.namespace.QName)1