use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class XdmResourceManagerTest method testInsertChild.
@Test
public void testInsertChild() {
try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx()) {
DocumentCreater.create(wtx);
assertNotNull(wtx.moveToDocumentRoot());
assertEquals(Kind.DOCUMENT, wtx.getKind());
assertNotNull(wtx.moveToFirstChild());
assertEquals(Kind.ELEMENT, wtx.getKind());
assertEquals("p:a", new StringBuilder(wtx.getName().getPrefix()).append(":").append(wtx.getName().getLocalName()).toString());
wtx.rollback();
}
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class XdmResourceManagerTest method testIdempotentClose.
@Test
public void testIdempotentClose() {
final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
DocumentCreater.create(wtx);
wtx.commit();
wtx.close();
wtx.close();
final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
assertEquals(false, rtx.moveTo(14L).hasMoved());
rtx.close();
rtx.close();
holder.getResourceManager().close();
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class AttributeAxisTest method testMultipleAttributes.
@Test
public void testMultipleAttributes() throws SirixException {
final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
final long nodeKey = wtx.insertElementAsFirstChild(new QNm("foo")).getNodeKey();
wtx.insertAttribute(new QNm("foo0"), "0");
wtx.moveTo(nodeKey);
wtx.insertAttribute(new QNm("foo1"), "1");
wtx.moveTo(nodeKey);
wtx.insertAttribute(new QNm("foo2"), "2");
Assert.assertEquals(true, wtx.moveTo(nodeKey).hasMoved());
Assert.assertEquals(true, wtx.moveToAttribute(0).hasMoved());
Assert.assertEquals("0", wtx.getValue());
Assert.assertEquals(new QNm("foo0"), wtx.getName());
Assert.assertEquals(true, wtx.moveToParent().hasMoved());
Assert.assertEquals(true, wtx.moveToAttribute(1).hasMoved());
Assert.assertEquals("1", wtx.getValue());
Assert.assertEquals(new QNm("foo1"), wtx.getName());
Assert.assertEquals(true, wtx.moveToParent().hasMoved());
Assert.assertEquals(true, wtx.moveToAttribute(2).hasMoved());
Assert.assertEquals("2", wtx.getValue());
Assert.assertEquals(new QNm("foo2"), wtx.getName());
Assert.assertEquals(true, wtx.moveTo(nodeKey).hasMoved());
final AbstractAxis axis = new AttributeAxis(wtx);
Assert.assertEquals(true, axis.hasNext());
axis.next();
Assert.assertEquals(nodeKey + 1, wtx.getNodeKey());
Assert.assertEquals(new QNm("foo0"), wtx.getName());
Assert.assertEquals("0", wtx.getValue());
Assert.assertEquals(true, axis.hasNext());
axis.next();
Assert.assertEquals(nodeKey + 2, wtx.getNodeKey());
Assert.assertEquals(new QNm("foo1"), wtx.getName());
Assert.assertEquals("1", wtx.getValue());
Assert.assertEquals(true, axis.hasNext());
axis.next();
Assert.assertEquals(nodeKey + 3, wtx.getNodeKey());
Assert.assertEquals(new QNm("foo2"), wtx.getName());
Assert.assertEquals("2", wtx.getValue());
wtx.rollback();
wtx.close();
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class XMLSerializerTest method testSampleCompleteSerializer.
@Test
public void testSampleCompleteSerializer() throws Exception {
final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
// generate serialize all from this session
DocumentCreater.createVersioned(wtx);
wtx.close();
XMLSerializer serializerall = new XMLSerializerBuilder(manager, out, -1).emitXMLDeclaration().build();
serializerall.call();
assertEquals(DocumentCreater.VERSIONEDXML, out.toString());
out.reset();
serializerall = new XMLSerializerBuilder(manager, out, 1, 2, 3).emitXMLDeclaration().build();
serializerall.call();
assertEquals(DocumentCreater.VERSIONEDXML, out.toString());
manager.close();
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class XMLSerializerTest method testKeyStart.
/**
* This test check the XPath //books expression and expects 6 books as result. But the failure is,
* that only the children of the books will be serialized and NOT the book node itself.
*/
@Test
public void testKeyStart() throws Exception {
final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
// generate serialize all from this session
DocumentCreater.createVersioned(wtx);
wtx.commit();
wtx.close();
XMLSerializer serializerall = new XMLSerializerBuilder(manager, 5l, out, new XMLSerializerProperties()).emitXMLDeclaration().build();
serializerall.call();
final String result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><b>foo<c/></b>";
assertEquals(result, out.toString());
out.reset();
serializerall = new XMLSerializerBuilder(manager, out, 1, 2, 3).emitXMLDeclaration().build();
serializerall.call();
assertEquals(DocumentCreater.VERSIONEDXML, out.toString());
manager.close();
}
Aggregations