use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class TypeFilterTest method testFilterConvetions.
@Test
public void testFilterConvetions() throws Exception {
final AbstractAxis axis = new XPathAxis(holder.getReader(), "a");
final XdmNodeReadTrx xtx = ((XdmNodeReadTrx) axis.getTrx());
xtx.moveTo(9L);
FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:untyped"), true);
FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:long"), false);
xtx.moveTo(4L);
FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:untyped"), true);
FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:double"), false);
xtx.moveTo(1L);
xtx.moveToAttribute(0);
FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:untyped"), true);
FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:anyType"), false);
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class DivOpAxisTest 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 DivOpAxis(holder.getReader(), op1, op2);
assertEquals(true, axis.hasNext());
axis.next();
assertThat(0.5, is(Double.parseDouble(holder.getReader().getValue())));
assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
assertEquals(false, axis.hasNext());
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class IDivOpAxisTest method testOperate.
@Test
public final void testOperate() throws SirixException {
AtomicValue item1 = new AtomicValue(3.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 IDivOpAxis(holder.getReader(), op1, op2);
assertEquals(true, axis.hasNext());
axis.next();
// note: although getRawValue() returns [1], parseString returns ""
// assertEquals(1,
// Integer.parseInt(TypedValue.parseString(holder.getRtx().getRawValue())));
assertEquals(holder.getReader().keyForName("xs:integer"), holder.getReader().getTypeKey());
assertEquals(false, axis.hasNext());
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class IDivOpAxisTest method testGetReturnType.
@Test
public final void testGetReturnType() throws SirixException {
AbstractAxis op1 = new SequenceAxis(holder.getReader());
AbstractAxis op2 = new SequenceAxis(holder.getReader());
AbstractObAxis axis = new IDivOpAxis(holder.getReader(), op1, op2);
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:double"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:float"), holder.getReader().keyForName("xs:decimal")));
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:integer")));
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:integer"), holder.getReader().keyForName("xs:integer")));
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: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."));
}
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class ModOpAxisTest method testGetReturnType.
@Test
public final void testGetReturnType() throws SirixException {
AbstractAxis op1 = new SequenceAxis(holder.getReader());
AbstractAxis op2 = new SequenceAxis(holder.getReader());
AbstractObAxis axis = new ModOpAxis(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")));
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: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."));
}
}
Aggregations