Search in sources :

Example 16 with XPathHolder

use of com.evolveum.midpoint.prism.marshaller.XPathHolder in project midpoint by Evolveum.

the class XPathTest method variableTest.

@Test
public void variableTest() {
    String xpathStr = "declare namespace v='http://vvv.com';" + "declare namespace x='http://www.xxx.com';" + "$v:var/x:xyz[10]";
    XPathHolder xpath = new XPathHolder(xpathStr);
    AssertJUnit.assertEquals("$v:var/x:xyz[10]", xpath.getXPathWithoutDeclarations());
    AssertJUnit.assertEquals("http://vvv.com", xpath.getNamespaceMap().get("v"));
    AssertJUnit.assertEquals("http://www.xxx.com", xpath.getNamespaceMap().get("x"));
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) Test(org.testng.annotations.Test)

Example 17 with XPathHolder

use of com.evolveum.midpoint.prism.marshaller.XPathHolder in project midpoint by Evolveum.

the class XPathTest method strangeCharsTest.

@Test
public void strangeCharsTest() throws FileNotFoundException, UnsupportedEncodingException, IOException {
    String xpathStr;
    // The file contains strange chanrs (no-break spaces), so we need to pull
    // it in exactly as it is.
    File file = new File(FILENAME_STRANGECHARS);
    FileInputStream stream = new FileInputStream(file);
    try {
        FileChannel fc = stream.getChannel();
        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
        xpathStr = Charset.forName("UTF-8").decode(bb).toString();
    } finally {
        stream.close();
    }
    XPathHolder xpath = new XPathHolder(xpathStr);
    System.out.println("Stragechars Pure XPath: " + xpath.getXPathWithoutDeclarations());
    AssertJUnit.assertEquals("$i:user/i:extension/ri:foobar", xpath.getXPathWithoutDeclarations());
    System.out.println("Stragechars ROUND TRIP: " + xpath.getXPathWithDeclarations());
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) MappedByteBuffer(java.nio.MappedByteBuffer) FileChannel(java.nio.channels.FileChannel) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 18 with XPathHolder

use of com.evolveum.midpoint.prism.marshaller.XPathHolder in project midpoint by Evolveum.

the class XPathTest method testUndefinedPrefix.

//not actual anymore..we have something like "wildcard" in xpath..there don't need to be prefix specified.we will try to match the local names
@Test(enabled = false)
public void testUndefinedPrefix() throws ParserConfigurationException, SAXException, IOException {
    // GIVEN
    Element el1 = parseDataGetEl1();
    String xpathString = "/root/undef:el1";
    el1.setTextContent(xpathString);
    try {
        // WHEN
        XPathHolder xpath = new XPathHolder(el1);
        AssertJUnit.fail("Unexpected success");
    } catch (IllegalArgumentException e) {
    // This is expected
    }
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) Element(org.w3c.dom.Element) Test(org.testng.annotations.Test)

Aggregations

XPathHolder (com.evolveum.midpoint.prism.marshaller.XPathHolder)18 Test (org.testng.annotations.Test)11 Element (org.w3c.dom.Element)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QName (javax.xml.namespace.QName)4 XPathSegment (com.evolveum.midpoint.prism.marshaller.XPathSegment)3 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)3 CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 File (java.io.File)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)1 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)1 FileInputStream (java.io.FileInputStream)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1