Search in sources :

Example 6 with XPathAxis

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

the class IntersectAxisTest method testIntersect.

@Test
public void testIntersect() throws SirixException {
    holder.getReader().moveTo(1L);
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "child::node() intersect b"), new long[] { 5L, 9L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "child::node() intersect b intersect child::node()[@p:x]"), new long[] { 9L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "child::node() intersect child::node()[attribute::p:x]"), new long[] { 9L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "child::node()/parent::node() intersect self::node()"), new long[] { 1L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "//node() intersect //text()"), new long[] { 4L, 8L, 13L, 6L, 12L });
    holder.getReader().moveTo(1L);
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "b/preceding::node() intersect text()"), new long[] { 4L, 8L });
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 7 with XPathAxis

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

the class OrExprTest method testOrQuery.

@Test
public void testOrQuery() throws SirixException {
    holder.getReader().moveTo(1L);
    final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "text() or node()");
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis1.hasNext());
    final AbstractAxis axis2 = new XPathAxis(holder.getReader(), "comment() or node()");
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis2.hasNext());
    final AbstractAxis axis3 = new XPathAxis(holder.getReader(), "1 eq 1 or 2 eq 2");
    assertEquals(true, axis3.hasNext());
    axis3.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis3.hasNext());
    final AbstractAxis axis4 = new XPathAxis(holder.getReader(), "1 eq 1 or 2 eq 3");
    assertEquals(true, axis4.hasNext());
    axis4.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis4.hasNext());
    final AbstractAxis axis5 = new XPathAxis(holder.getReader(), "1 eq 2 or (3 idiv 0 = 1)");
    try {
        assertEquals(true, axis5.hasNext());
        axis5.next();
        assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
        assertEquals(false, axis5.hasNext());
        axis5.next();
        fail("Exprected XPathError");
    } catch (XPathError e) {
        assertEquals("err:FOAR0001: Division by zero.", e.getMessage());
    }
    final AbstractAxis axis6 = new XPathAxis(holder.getReader(), "1 eq 1 or (3 idiv 0 = 1)");
    assertEquals(true, axis6.hasNext());
    axis6.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) XPathError(org.sirix.service.xml.xpath.XPathError) Test(org.junit.Test)

Example 8 with XPathAxis

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

the class VarRefExprTest method testEveryExpr.

@Test
public void testEveryExpr() throws SirixException {
    final AbstractAxis axis = new XPathAxis(holder.getReader(), "for $a in b return $a");
    final VariableAxis variable = new VariableAxis(holder.getReader(), axis);
    final VarRefExpr axis1 = new VarRefExpr(holder.getReader(), variable);
    // assertEquals(false, axis1.hasNext());
    axis1.update(5L);
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(5L, holder.getReader().getNodeKey());
    axis1.update(13L);
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(13L, holder.getReader().getNodeKey());
    axis1.update(1L);
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(1L, holder.getReader().getNodeKey());
    assertEquals(false, axis1.hasNext());
    final VarRefExpr axis2 = new VarRefExpr(holder.getReader(), variable);
    // assertEquals(false, axis2.hasNext());
    axis2.update(13L);
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(13L, holder.getReader().getNodeKey());
    assertEquals(false, axis2.hasNext());
    axis2.update(12L);
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(12L, holder.getReader().getNodeKey());
    assertEquals(false, axis2.hasNext());
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) Test(org.junit.Test)

Example 9 with XPathAxis

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

the class DubFilterTest method testDupElemination.

@Test
public void testDupElemination() throws SirixException {
    holder.getReader().moveTo(1L);
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "child::node()/parent::node()"), new long[] { 1L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "b/following-sibling::node()"), new long[] { 8L, 9L, 13L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "b/preceding::node()"), new long[] { 4L, 8L, 7L, 6L, 5L });
    AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "//c/ancestor::node()"), new long[] { 5L, 1L, 9L });
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 10 with XPathAxis

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

the class CastableExprTest method testCastableExpr.

@Test
public void testCastableExpr() throws SirixException {
    final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "1 castable as xs:decimal");
    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(), "10.0 castable as xs:anyAtomicType");
    try {
        assertEquals(true, axis2.hasNext());
        axis2.next();
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPST0080 " + "Target type of a cast or castable expression must not be " + "xs:NOTATION or xs:anyAtomicType."));
    }
    // Token is not implemented yet.
    // final IAxis axis3 = new XPathAxis(holder.getRtx(),
    // "\"hello\" castable as xs:token");
    // assertEquals(true, axis3.hasNext());
    // assertEquals(Type.BOOLEAN, holder.getRtx().getValueTypeAsType());
    // assertEquals(true, holder.getRtx().getValueAsBoolean());
    // assertEquals(false, axis3.hasNext());
    final AbstractAxis axis4 = new XPathAxis(holder.getReader(), "\"hello\" castable as 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 IAxis axis5 = new XPathAxis(holder.getRtx(),
// "\"hello\" castable as xs:decimal");
// assertEquals(true, axis5.hasNext());
// assertEquals(holder.getRtx().keyForName("xs:boolean"),
// holder.getRtx().getTypeKey());
// assertEquals(true, Boolean.parseBoolean(holder.getRtx().getValue()));
// assertEquals(false, axis5.hasNext());
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) XPathError(org.sirix.service.xml.xpath.XPathError) 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