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);
}
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");
}
}
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);
}
Aggregations