Search in sources :

Example 1 with ResourceType

use of com.evolveum.midpoint.prism.foo.ResourceType 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 2 with ResourceType

use of com.evolveum.midpoint.prism.foo.ResourceType 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

ResourceType (com.evolveum.midpoint.prism.foo.ResourceType)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)2 Test (org.testng.annotations.Test)2 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)1 XNode (com.evolveum.midpoint.prism.xnode.XNode)1 QName (javax.xml.namespace.QName)1