use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class ChildAxisTest method testIterate.
@Test
public void testIterate() throws SirixException {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(1L);
AbsAxisTest.testIAxisConventions(new ChildAxis(rtx), new long[] { 4L, 5L, 8L, 9L, 13L });
rtx.moveTo(5L);
AbsAxisTest.testIAxisConventions(new ChildAxis(rtx), new long[] { 6L, 7L });
rtx.moveTo(13L);
AbsAxisTest.testIAxisConventions(new ChildAxis(rtx), new long[] {});
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class DescendantAxisTest method testIterate.
@Test
public void testIterate() throws SirixException {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveToDocumentRoot();
AbsAxisTest.testIAxisConventions(new DescendantAxis(rtx), new long[] { 1L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L });
new IteratorTester<Long>(ITERATIONS, IteratorFeature.UNMODIFIABLE, ImmutableList.of(1L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L), null) {
@Override
protected Iterator<Long> newTargetIterator() {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveToDocumentRoot();
return new DescendantAxis(rtx);
}
}.test();
rtx.moveTo(1L);
AbsAxisTest.testIAxisConventions(new DescendantAxis(rtx), new long[] { 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L });
new IteratorTester<Long>(ITERATIONS, IteratorFeature.UNMODIFIABLE, ImmutableList.of(4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L), null) {
@Override
protected Iterator<Long> newTargetIterator() {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(1L);
return new DescendantAxis(rtx);
}
}.test();
rtx.moveTo(9L);
AbsAxisTest.testIAxisConventions(new DescendantAxis(rtx), new long[] { 11L, 12L });
new IteratorTester<Long>(ITERATIONS, IteratorFeature.UNMODIFIABLE, ImmutableList.of(11L, 12L), null) {
@Override
protected Iterator<Long> newTargetIterator() {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(9L);
return new DescendantAxis(rtx);
}
}.test();
rtx.moveTo(13L);
AbsAxisTest.testIAxisConventions(new DescendantAxis(rtx), new long[] {});
new IteratorTester<Long>(ITERATIONS, IteratorFeature.UNMODIFIABLE, Collections.<Long>emptyList(), null) {
@Override
protected Iterator<Long> newTargetIterator() {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(13L);
return new DescendantAxis(rtx);
}
}.test();
}
use of org.sirix.api.XdmNodeReadTrx 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());
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class StAXSerializerTest method testStAXSerializer.
@Test
public void testStAXSerializer() {
try {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final XMLSerializer xmlSerializer = new XMLSerializerBuilder(holder.getResourceManager(), out).emitXMLDeclaration().build();
xmlSerializer.call();
final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
StAXSerializer serializer = new StAXSerializer(rtx);
final StringBuilder strBuilder = new StringBuilder();
boolean isEmptyElement = false;
while (serializer.hasNext()) {
XMLEvent event = serializer.nextEvent();
switch(event.getEventType()) {
case XMLStreamConstants.START_DOCUMENT:
strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
break;
case XMLStreamConstants.START_ELEMENT:
emitElement(event, strBuilder);
if (serializer.peek().getEventType() == XMLStreamConstants.END_ELEMENT) {
strBuilder.append("/>");
isEmptyElement = true;
} else {
strBuilder.append('>');
}
break;
case XMLStreamConstants.END_ELEMENT:
if (isEmptyElement) {
isEmptyElement = false;
} else {
emitQName(true, event, strBuilder);
strBuilder.append('>');
}
break;
case XMLStreamConstants.CHARACTERS:
strBuilder.append(((Characters) event).getData());
break;
}
}
assertEquals(out.toString(), strBuilder.toString());
// Check getElementText().
// ========================================================
holder.getReader().moveToDocumentRoot();
holder.getReader().moveToFirstChild();
serializer = new StAXSerializer(holder.getReader());
String elemText = null;
// <p:a>
if (serializer.hasNext()) {
serializer.next();
elemText = serializer.getElementText();
}
assertEquals("oops1foooops2baroops3", elemText);
// oops1
checkForException(serializer);
// <b>
if (serializer.hasNext()) {
serializer.next();
elemText = serializer.getElementText();
}
assertEquals("foo", elemText);
// foo
checkForException(serializer);
// <c>
if (serializer.hasNext()) {
serializer.next();
elemText = serializer.getElementText();
}
assertEquals("", elemText);
// </c>
checkForException(serializer);
// </b>
checkForException(serializer);
// oops2
checkForException(serializer);
// <b p:x='y'>
if (serializer.hasNext()) {
serializer.next();
elemText = serializer.getElementText();
}
assertEquals("bar", elemText);
// <c>
if (serializer.hasNext()) {
serializer.next();
elemText = serializer.getElementText();
}
assertEquals("", elemText);
// </c>
checkForException(serializer);
// bar
checkForException(serializer);
// </b>
checkForException(serializer);
// oops3
checkForException(serializer);
// </p:a>
checkForException(serializer);
rtx.close();
} catch (final XMLStreamException e) {
fail("XML error while parsing: " + e.getMessage());
} catch (final SirixException e) {
fail("Sirix exception occured: " + e.getMessage());
} catch (final Exception e) {
fail("Any exception occured: " + e.getMessage());
}
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class PreviousAxisTest method testAxis.
@Test
public void testAxis() throws SirixException {
final XdmNodeReadTrx firstRtx = holder.getResourceManager().beginNodeReadTrx(1);
final XdmNodeReadTrx secondRtx = holder.getResourceManager().beginNodeReadTrx(2);
new IteratorTester<XdmNodeReadTrx>(ITERATIONS, IteratorFeature.UNMODIFIABLE, ImmutableList.of(firstRtx), null) {
@Override
protected Iterator<XdmNodeReadTrx> newTargetIterator() {
return new PreviousAxis(secondRtx);
}
}.test();
}
Aggregations