Search in sources :

Example 1 with XPathAxis

use of org.sirix.service.xml.xpath.XPathAxis in project sirix by sirixdb.

the class ForAxisTest method testFor.

@Test
public void testFor() throws SirixException {
    final XdmNodeReadTrx rtx = holder.getReader();
    rtx.moveTo(1L);
    AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::text() return child::node()"), new long[] { 4L, 5L, 8L, 9L, 13L, 4L, 5L, 8L, 9L, 13L, 4L, 5L, 8L, 9L, 13L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::node() return $a/node()"), new long[] { 6L, 7L, 11L, 12L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::node() return $a/text()"), new long[] { 6L, 12L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::node() return $a/c"), new long[] { 7L, 11L });
    // IAxisTest.testIAxisConventions(new XPathAxis(
    // rtx,
    // "for $a in child::node(), $b in /node(), $c in ., $d in /c return $a/c"),
    // new long[] {7L, 11L});
    AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::node() return $a[@p:x]"), new long[] { 9L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in . return $a"), new long[] { 1L });
    final AbstractAxis axis = new XPathAxis(rtx, "for $i in (10, 20), $j in (1, 2) return ($i + $j)");
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals("11.0", rtx.getValue());
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals("12.0", rtx.getValue());
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals("21.0", rtx.getValue());
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals("22.0", rtx.getValue());
    assertEquals(false, axis.hasNext());
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) Test(org.junit.Test)

Example 2 with XPathAxis

use of org.sirix.service.xml.xpath.XPathAxis in project sirix by sirixdb.

the class ConXPathAxisTest method testCount.

@Test
public void testCount() throws IOException {
    try {
        holder.getReader().moveTo(1L);
        XPathStringChecker.testIAxisConventions(new XPathAxis(holder.getReader(), "fn:count(//node())"), new String[] { "10" });
    } catch (final SirixXPathException mExp) {
        mExp.getStackTrace();
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 3 with XPathAxis

use of org.sirix.service.xml.xpath.XPathAxis in project sirix by sirixdb.

the class ConXPathAxisTest method testNodeTests.

@Test
public void testNodeTests() {
    try {
        // Find descendants starting from nodeKey 0L (root).
        holder.getReader().moveToDocumentRoot();
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "/p:a/node()"), new long[] { 4L, 5L, 8L, 9L, 13L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "p:a/text()"), new long[] { 4L, 8L, 13L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "/p:a/b/text()"), new long[] { 6L, 12L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "p:a/b/node()"), new long[] { 6L, 7L, 11L, 12L });
    } catch (final SirixXPathException mExp) {
        mExp.getStackTrace();
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 4 with XPathAxis

use of org.sirix.service.xml.xpath.XPathAxis in project sirix by sirixdb.

the class ConcurrentAxisTest method testSeriellOld.

/**
 * Test seriell.
 */
// @Ignore
// @SkipBench
// @Bench
@Test
public void testSeriellOld() throws Exception {
    // final String query = "//people/person[@id=\"person3\"]/name";
    // final String query = "count(//location[text() = \"United States\"])";
    final String query = "//regions/africa//location";
    // final String result = "<name>Limor Simone</name>";
    final int resultNumber = 55;
    final Axis axis = new XPathAxis(holder.getReader(), query);
    for (int i = 0; i < resultNumber; i++) {
        assertEquals(true, axis.hasNext());
        axis.next();
    }
    assertEquals(false, axis.hasNext());
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Axis(org.sirix.api.Axis) NestedAxis(org.sirix.axis.NestedAxis) ChildAxis(org.sirix.axis.ChildAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test)

Example 5 with XPathAxis

use of org.sirix.service.xml.xpath.XPathAxis in project sirix by sirixdb.

the class InstanceOfExprTest method testInstanceOfExpr.

@Test(expected = NoSuchElementException.class)
public void testInstanceOfExpr() throws SirixException {
    final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "1 instance of xs:integer");
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis1.hasNext());
    final AbstractAxis axis2 = new XPathAxis(holder.getReader(), "\"hallo\" instance of xs:integer");
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
    assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis2.hasNext());
    final AbstractAxis axis3 = new XPathAxis(holder.getReader(), "\"hallo\" instance of xs:string ?");
    assertEquals(true, axis3.hasNext());
    axis3.next();
    assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis3.hasNext());
    final AbstractAxis axis4 = new XPathAxis(holder.getReader(), "\"hallo\" instance of xs:string +");
    assertEquals(true, axis4.hasNext());
    axis4.next();
    assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis4.hasNext());
    final AbstractAxis axis5 = new XPathAxis(holder.getReader(), "\"hallo\" instance of xs:string *");
    assertEquals(true, axis5.hasNext());
    axis5.next();
    assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis5.hasNext());
    axis5.next();
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) Test(org.junit.Test)

Aggregations

XPathAxis (org.sirix.service.xml.xpath.XPathAxis)67 Test (org.junit.Test)62 Ignore (org.junit.Ignore)27 AbsAxisTest (org.sirix.axis.AbsAxisTest)18 SirixXPathException (org.sirix.exception.SirixXPathException)12 AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)12 Axis (org.sirix.api.Axis)6 IOException (java.io.IOException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 SessionConfiguration (org.sirix.access.conf.SessionConfiguration)3 Database (org.sirix.api.Database)3 NodeReadTrx (org.sirix.api.NodeReadTrx)3 Session (org.sirix.api.Session)3 SirixException (org.sirix.exception.SirixException)3 XPathError (org.sirix.service.xml.xpath.XPathError)3 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)2 LinkedList (java.util.LinkedList)1 StringTokenizer (java.util.StringTokenizer)1 QName (javax.xml.namespace.QName)1 XMLEvent (javax.xml.stream.events.XMLEvent)1