Search in sources :

Example 1 with RootXNode

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());
}
Also used : QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Example 2 with RootXNode

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());
}
Also used : Entry(java.util.Map.Entry) QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 3 with RootXNode

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

Example 4 with RootXNode

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

Example 5 with RootXNode

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());
}
Also used : QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) ResourceType(com.evolveum.midpoint.prism.foo.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) 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