use of org.sirix.api.Database in project sirix by sirixdb.
the class WorkerHelperTest method testSerializeXML.
/**
* This method tests
* {@link WorkerHelper#serializeXML(Session, OutputStream, boolean, boolean,Long)}
*/
@Test
public void testSerializeXML() throws SirixException, IOException {
final Database database = Databases.openDatabase(DBFILE.getParentFile());
final Session session = database.getSession(new SessionConfiguration.Builder(DBFILE.getName()).build());
final OutputStream out = new ByteArrayOutputStream();
assertNotNull("test serialize xml", WorkerHelper.serializeXML(session, out, true, true, null));
session.close();
database.close();
out.close();
}
use of org.sirix.api.Database in project sirix by sirixdb.
the class Holder method openResourceManager.
/**
* Open a resource manager.
*
* @return this holder instance
* @throws SirixException if an error occurs
*/
public static Holder openResourceManager() throws SirixException {
final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
final ResourceManager session = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
final Holder holder = new Holder();
holder.setDatabase(database);
holder.setResourceManager(session);
return holder;
}
use of org.sirix.api.Database in project sirix by sirixdb.
the class TestHelper method createPICommentTestDocument.
/**
* Creating a test document with comments and processing instructions at {@link PATHS#PATH1}.
*
* @throws SirixException
*/
public static void createPICommentTestDocument() throws SirixException {
try (final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile())) {
database.createResource(new ResourceConfiguration.Builder(RESOURCE, PATHS.PATH1.config).build());
try (final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(RESOURCE).build());
final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx()) {
DocumentCreater.createCommentPI(wtx);
wtx.commit();
}
}
}
use of org.sirix.api.Database in project sirix by sirixdb.
the class TestHelper method createTestDocument.
/**
* Creating a test document at {@link PATHS#PATH1}.
*
* @throws SirixException
*/
public static void createTestDocument() throws SirixException {
try (final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile())) {
database.createResource(new ResourceConfiguration.Builder(RESOURCE, PATHS.PATH1.config).build());
try (final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(RESOURCE).build());
final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx()) {
DocumentCreater.create(wtx);
wtx.commit();
}
}
}
use of org.sirix.api.Database 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();
}
Aggregations