use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.
the class AbstractLexicalProcessorTest method testParseUserRoundTrip.
@Test
public void testParseUserRoundTrip() throws Exception {
final String TEST_NAME = "testParseUserRoundTrip";
displayTestTitle(TEST_NAME);
// GIVEN
LexicalProcessor<String> lexicalProcessor = createParser();
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN (parse)
RootXNode xnode = lexicalProcessor.read(getFileSource(USER_JACK_FILE_BASENAME), ParsingContext.createDefault());
System.out.println("\nParsed xnode:");
System.out.println(xnode.debugDump());
PrismObject<UserType> user = prismContext.parserFor(xnode).parse();
// THEN
System.out.println("\nParsed user:");
System.out.println(user.debugDump());
assertUserJack(user, true);
// WHEN (re-serialize to XNode)
RootXNode serializedXNode = prismContext.xnodeSerializer().options(SerializationOptions.createSerializeCompositeObjects()).serialize(user);
String serializedString = lexicalProcessor.write(serializedXNode, new QName(NS_FOO, "user"), null);
// THEN
System.out.println("\nXNode after re-serialization:");
System.out.println(serializedXNode.debugDump());
System.out.println("\nRe-serialized string:");
System.out.println(serializedString);
String whenSerialized = getWhenItemSerialized();
assertTrue("Serialized form does not contain " + whenSerialized, serializedString.contains(whenSerialized));
assertUserJackXNodeOrdering("serialized xnode", serializedXNode);
validateUserSchema(serializedString, prismContext);
// WHEN (re-parse)
RootXNode reparsedXnode = lexicalProcessor.read(new ParserStringSource(serializedString), ParsingContext.createDefault());
PrismObject<UserType> reparsedUser = prismContext.parserFor(reparsedXnode).parse();
// THEN
System.out.println("\nXNode after re-parsing:");
System.out.println(reparsedXnode.debugDump());
System.out.println("\nRe-parsed user:");
System.out.println(reparsedUser.debugDump());
assertUserJackXNodeOrdering("serialized xnode", reparsedXnode);
ObjectDelta<UserType> diff = DiffUtil.diff(user, reparsedUser);
System.out.println("\nDiff:");
System.out.println(diff.debugDump());
PrismObject accountRefObjOrig = findObjectFromAccountRef(user);
PrismObject accountRefObjRe = findObjectFromAccountRef(reparsedUser);
ObjectDelta<UserType> accountRefObjDiff = DiffUtil.diff(accountRefObjOrig, accountRefObjRe);
System.out.println("\naccountRef object diff:");
System.out.println(accountRefObjDiff.debugDump());
assertTrue("Re-parsed object in accountRef does not match: " + accountRefObjDiff, accountRefObjDiff.isEmpty());
assertTrue("Re-parsed user does not match: " + diff, diff.isEmpty());
}
use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.
the class AbstractLexicalProcessorTest method assertUserJackXNodeOrdering.
protected void assertUserJackXNodeOrdering(String message, XNode xnode) {
if (xnode instanceof RootXNode) {
xnode = ((RootXNode) xnode).getSubnode();
}
MapXNode xmap = getAssertXNode(message + ": top", xnode, MapXNode.class);
Set<Entry<QName, XNode>> reTopMapEntrySet = xmap.entrySet();
Iterator<Entry<QName, XNode>> reTopMapEntrySetIter = reTopMapEntrySet.iterator();
Entry<QName, XNode> reTopMapEntry0 = reTopMapEntrySetIter.next();
assertEquals(message + ": Wrong entry 0, the xnodes were shuffled", "oid", reTopMapEntry0.getKey().getLocalPart());
Entry<QName, XNode> reTopMapEntry1 = reTopMapEntrySetIter.next();
assertEquals(message + ": Wrong entry 1, the xnodes were shuffled", "version", reTopMapEntry1.getKey().getLocalPart());
Entry<QName, XNode> reTopMapEntry2 = reTopMapEntrySetIter.next();
assertEquals(message + ": Wrong entry 2, the xnodes were shuffled", UserType.F_NAME, reTopMapEntry2.getKey());
Entry<QName, XNode> reTopMapEntry3 = reTopMapEntrySetIter.next();
assertEquals(message + ": Wrong entry 3, the xnodes were shuffled", UserType.F_DESCRIPTION, reTopMapEntry3.getKey());
}
use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.
the class AbstractLexicalProcessorTest method testParseEventHandler.
// The following is not supported now (and probably won't be in the future).
// Enable it if that changes.
@Test(enabled = false)
public void testParseEventHandler() throws Exception {
final String TEST_NAME = "testParseEventHandler";
displayTestTitle(TEST_NAME);
// GIVEN
LexicalProcessor lexicalProcessor = createParser();
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN (parse to xnode)
RootXNode xnode = lexicalProcessor.read(getFileSource(EVENT_HANDLER_FILE_BASENAME), ParsingContext.createDefault());
System.out.println("XNode after parsing:");
System.out.println(xnode.debugDump());
// WHEN (parse to prism)
EventHandlerType eventHandlerType = prismContext.parserFor(xnode).parseRealValue(EventHandlerChainType.class);
// EventHandlerType eventHandlerType = prismContext.getBeanConverter().unmarshall((MapXNode) , EventHandlerChainType.class,
// ParsingContext.createDefault());
// THEN
System.out.println("Parsed object:");
System.out.println(eventHandlerType);
// WHEN2 (marshalling)
MapXNode marshalled = (MapXNode) (prismContext.xnodeSerializer().serializeRealValue(eventHandlerType).getSubnode());
System.out.println("XNode after unmarshalling and marshalling back:");
System.out.println(marshalled.debugDump());
}
use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.
the class AbstractLexicalProcessorTest method testParseResourceRumToPrism.
@Test
public void testParseResourceRumToPrism() throws Exception {
final String TEST_NAME = "testParseResourceRumToPrism";
displayTestTitle(TEST_NAME);
// GIVEN
LexicalProcessor lexicalProcessor = createParser();
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN (parse to xnode)
RootXNode xnode = lexicalProcessor.read(getFileSource(RESOURCE_RUM_FILE_BASENAME), ParsingContext.createDefault());
System.out.println("XNode after parsing:");
System.out.println(xnode.debugDump());
// WHEN (parse to prism)
PrismObject<ResourceType> resource = prismContext.parserFor(xnode).parse();
// THEN
System.out.println("Parsed resource:");
System.out.println(resource.debugDump());
assertResourceRum(resource);
}
use of com.evolveum.midpoint.prism.xnode.RootXNode in project midpoint by Evolveum.
the class AbstractLexicalProcessorTest method testParseResourceRoundTrip.
@Test
public void testParseResourceRoundTrip() throws Exception {
final String TEST_NAME = "testParseResourceRoundTrip";
displayTestTitle(TEST_NAME);
// GIVEN
LexicalProcessor<String> lexicalProcessor = createParser();
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN (parse)
RootXNode xnode = lexicalProcessor.read(getFileSource(RESOURCE_RUM_FILE_BASENAME), ParsingContext.createDefault());
PrismObject<ResourceType> resource = prismContext.parserFor(xnode).parse();
// THEN
System.out.println("\nParsed resource:");
System.out.println(resource.debugDump());
assertResourceRum(resource);
// WHEN (re-serialize to XNode)
XNode serializedXNode = prismContext.xnodeSerializer().options(SerializationOptions.createSerializeCompositeObjects()).serialize(resource);
String serializedString = lexicalProcessor.write(serializedXNode, new QName(NS_FOO, "resource"), null);
// THEN
System.out.println("\nXNode after re-serialization:");
System.out.println(serializedXNode.debugDump());
System.out.println("\nRe-serialized string:");
System.out.println(serializedString);
validateResourceSchema(serializedString, prismContext);
// WHEN (re-parse)
RootXNode reparsedXnode = lexicalProcessor.read(new ParserStringSource(serializedString), ParsingContext.createDefault());
PrismObject<ResourceType> reparsedResource = prismContext.parserFor(reparsedXnode).parse();
// THEN
System.out.println("\nXNode after re-parsing:");
System.out.println(reparsedXnode.debugDump());
System.out.println("\nRe-parsed resource:");
System.out.println(reparsedResource.debugDump());
ObjectDelta<ResourceType> diff = DiffUtil.diff(resource, reparsedResource);
System.out.println("\nDiff:");
System.out.println(diff.debugDump());
assertTrue("Re-parsed user does not match: " + diff, diff.isEmpty());
}
Aggregations