Search in sources :

Example 26 with AbstractAxis

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

the class MulOpAxisTest method testGetReturnType.

@Test
public final void testGetReturnType() throws SirixException {
    AbstractAxis op1 = new SequenceAxis(holder.getReader());
    AbstractAxis op2 = new SequenceAxis(holder.getReader());
    AbstractObAxis axis = new MulOpAxis(holder.getReader(), op1, op2);
    assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:double"), holder.getReader().keyForName("xs:double")));
    assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:double")));
    assertEquals(Type.FLOAT, axis.getReturnType(holder.getReader().keyForName("xs:float"), holder.getReader().keyForName("xs:decimal")));
    assertEquals(Type.DECIMAL, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:integer")));
    // assertEquals(Type.INTEGER,
    // axis.getReturnType(holder.getRtx().keyForName("xs:integer"),
    // holder.getRtx().keyForName("xs:integer")));
    assertEquals(Type.YEAR_MONTH_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:yearMonthDuration"), holder.getReader().keyForName("xs:double")));
    assertEquals(Type.YEAR_MONTH_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:integer"), holder.getReader().keyForName("xs:yearMonthDuration")));
    assertEquals(Type.DAY_TIME_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:dayTimeDuration"), holder.getReader().keyForName("xs:double")));
    assertEquals(Type.DAY_TIME_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:integer"), holder.getReader().keyForName("xs:dayTimeDuration")));
    try {
        axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:yearMonthDuration"));
        fail("Expected an XPathError-Exception.");
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
    }
    try {
        axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:double"));
        fail("Expected an XPathError-Exception.");
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
    }
    try {
        axis.getReturnType(holder.getReader().keyForName("xs:string"), holder.getReader().keyForName("xs:yearMonthDuration"));
        fail("Expected an XPathError-Exception.");
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
    }
    try {
        axis.getReturnType(holder.getReader().keyForName("xs:yearMonthDuration"), holder.getReader().keyForName("xs:yearMonthDuration"));
        fail("Expected an XPathError-Exception.");
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
    }
}
Also used : SequenceAxis(org.sirix.service.xml.xpath.expr.SequenceAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) XPathError(org.sirix.service.xml.xpath.XPathError) Test(org.junit.Test)

Example 27 with AbstractAxis

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

the class SubOpAxisTest method testGetReturnType.

@Test
public final void testGetReturnType() throws SirixException {
    AbstractAxis op1 = new SequenceAxis(holder.getReader());
    AbstractAxis op2 = new SequenceAxis(holder.getReader());
    AbstractObAxis axis = new SubOpAxis(holder.getReader(), op1, op2);
    assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:double"), holder.getReader().keyForName("xs:double")));
    assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:double")));
    assertEquals(Type.FLOAT, axis.getReturnType(holder.getReader().keyForName("xs:float"), holder.getReader().keyForName("xs:decimal")));
    assertEquals(Type.DECIMAL, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:integer")));
    // assertEquals(Type.INTEGER,
    // axis.getReturnType(holder.getRtx().keyForName("xs:integer"),
    // holder.getRtx().keyForName("xs:integer")));
    assertEquals(Type.YEAR_MONTH_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:yearMonthDuration"), holder.getReader().keyForName("xs:yearMonthDuration")));
    assertEquals(Type.DAY_TIME_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:dayTimeDuration"), holder.getReader().keyForName("xs:dayTimeDuration")));
    assertEquals(Type.DAY_TIME_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:date"), holder.getReader().keyForName("xs:date")));
    assertEquals(Type.DATE, axis.getReturnType(holder.getReader().keyForName("xs:date"), holder.getReader().keyForName("xs:yearMonthDuration")));
    assertEquals(Type.DATE, axis.getReturnType(holder.getReader().keyForName("xs:date"), holder.getReader().keyForName("xs:dayTimeDuration")));
    assertEquals(Type.DAY_TIME_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:time"), holder.getReader().keyForName("xs:time")));
    assertEquals(Type.DATE_TIME, axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:yearMonthDuration")));
    assertEquals(Type.DATE_TIME, axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:dayTimeDuration")));
    assertEquals(Type.DAY_TIME_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:dateTime")));
    try {
        axis.getReturnType(holder.getReader().keyForName("xs:string"), holder.getReader().keyForName("xs:yearMonthDuration"));
        fail("Expected an XPathError-Exception.");
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
    }
    try {
        axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:double"));
        fail("Expected an XPathError-Exception.");
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
    }
    try {
        axis.getReturnType(holder.getReader().keyForName("xs:string"), holder.getReader().keyForName("xs:yearMonthDuration"));
        fail("Expected an XPathError-Exception.");
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
    }
    try {
        axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:IDREF"));
        fail("Expected an XPathError-Exception.");
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
    }
}
Also used : SequenceAxis(org.sirix.service.xml.xpath.expr.SequenceAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) XPathError(org.sirix.service.xml.xpath.XPathError) Test(org.junit.Test)

Example 28 with AbstractAxis

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

the class SubOpAxisTest method testOperate.

@Test
public final void testOperate() throws SirixException {
    AtomicValue item1 = new AtomicValue(1.0, Type.DOUBLE);
    AtomicValue item2 = new AtomicValue(2.0, Type.DOUBLE);
    AbstractAxis op1 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item1));
    AbstractAxis op2 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item2));
    AbstractObAxis axis = new SubOpAxis(holder.getReader(), op1, op2);
    assertEquals(true, axis.hasNext());
    axis.next();
    assertThat(-1.0, is(Double.parseDouble(holder.getReader().getValue())));
    assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
    assertEquals(false, axis.hasNext());
}
Also used : AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Example 29 with AbstractAxis

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

the class XPathParserTest method testLiterals.

@Test
public void testLiterals() throws SirixException {
    holder.getReader().moveTo(2L);
    AbstractAxis axis;
    axis = new XPathAxis(holder.getReader(), "\"12.5\"");
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals("12.5", holder.getReader().getValue());
    assertEquals(holder.getReader().keyForName("xs:string"), holder.getReader().getTypeKey());
    assertEquals(false, axis.hasNext());
    axis = new XPathAxis(holder.getReader(), "\"He said, \"\"I don't like it\"\"\"");
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals("He said, I don't like it", holder.getReader().getValue());
    assertEquals(holder.getReader().keyForName("xs:string"), holder.getReader().getTypeKey());
    assertEquals(false, axis.hasNext());
    axis = new XPathAxis(holder.getReader(), "12");
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals(holder.getReader().keyForName("xs:integer"), holder.getReader().getTypeKey());
    assertEquals("12", holder.getReader().getValue());
    assertEquals(false, axis.hasNext());
    axis = new XPathAxis(holder.getReader(), "12.5");
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals(holder.getReader().keyForName("xs:decimal"), holder.getReader().getTypeKey());
    assertEquals("12.5", holder.getReader().getValue());
    assertEquals(false, axis.hasNext());
    axis = new XPathAxis(holder.getReader(), "12.5E2");
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
    assertEquals("12.5E2", holder.getReader().getValue());
    assertEquals(false, axis.hasNext());
    axis = new XPathAxis(holder.getReader(), "1");
    assertEquals(true, axis.hasNext());
    axis.next();
    assertEquals("1", holder.getReader().getValue());
    assertEquals(holder.getReader().keyForName("xs:integer"), holder.getReader().getTypeKey());
    assertEquals(false, axis.hasNext());
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) Test(org.junit.Test)

Aggregations

AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)29 Test (org.junit.Test)28 XPathAxis (org.sirix.service.xml.xpath.XPathAxis)12 AtomicValue (org.sirix.service.xml.xpath.AtomicValue)10 XPathError (org.sirix.service.xml.xpath.XPathError)8 LiteralExpr (org.sirix.service.xml.xpath.expr.LiteralExpr)7 SequenceAxis (org.sirix.service.xml.xpath.expr.SequenceAxis)6 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)2 ArrayList (java.util.ArrayList)1 Axis (org.sirix.api.Axis)1 FilterTest (org.sirix.axis.filter.FilterTest)1 TypeFilter (org.sirix.axis.filter.TypeFilter)1 SirixXPathException (org.sirix.exception.SirixXPathException)1 FNBoolean (org.sirix.service.xml.xpath.functions.sequences.FNBoolean)1