use of org.sirix.service.jaxrx.implementation.DatabaseRepresentation in project sirix by sirixdb.
the class RESTResponseHelperTest method testBuildResponseOfDomLR.
/**
* Test method for
* {@link org.sirix.service.jaxrx.util.RESTResponseHelper#buildResponseOfDomLR(java.util.Map)}
* .
*
* @throws IOException
* @throws WebApplicationException
* @throws SAXException
* @throws ParserConfigurationException
* @throws SirixException
* @throws InterruptedException
*/
@Test
public final void testBuildResponseOfDomLR() throws WebApplicationException, IOException, ParserConfigurationException, SAXException, SirixException, InterruptedException {
final List<String> availResources = new ArrayList<String>();
availResources.add(FACT);
availResources.add(EBAY);
availResources.add(BOOK);
availResources.add(SHAKE);
final DatabaseRepresentation sirix = new DatabaseRepresentation(TestHelper.PATHS.PATH1.getFile());
InputStream input = NodeIdRepresentationTest.class.getClass().getResourceAsStream(RESPATH);
sirix.shred(input, FACT);
input.close();
input = NodeIdRepresentationTest.class.getClass().getResourceAsStream(RESPATH);
sirix.shred(input, EBAY);
input.close();
input.close();
input = NodeIdRepresentationTest.class.getClass().getResourceAsStream(RESPATH);
sirix.add(input, BOOK);
input = NodeIdRepresentationTest.class.getClass().getResourceAsStream(RESPATH);
sirix.shred(input, SHAKE);
input.close();
Node node;
Attr attribute;
final StreamingOutput result = RESTResponseHelper.buildResponseOfDomLR(TestHelper.PATHS.PATH1.getFile(), availResources);
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
result.write(outputStream);
final Document doc = DOMHelper.buildDocument(outputStream);
final NodeList listRes = doc.getElementsByTagName("resource");
assertEquals("Test for the length of resource", 4, listRes.getLength());
node = listRes.item(0);
attribute = (Attr) node.getAttributes().getNamedItem(NAME);
assertEquals("test for name factbook", FACT, attribute.getTextContent());
attribute = (Attr) node.getAttributes().getNamedItem(LREV);
assertNotNull("test for existence of revision attribute", attribute);
node = listRes.item(1);
attribute = (Attr) node.getAttributes().getNamedItem(NAME);
assertEquals("test for name ebay", EBAY, attribute.getTextContent());
attribute = (Attr) node.getAttributes().getNamedItem(LREV);
assertNotNull("test for existence of revision attribute", attribute);
node = listRes.item(2);
attribute = (Attr) node.getAttributes().getNamedItem(NAME);
assertEquals("test for name shakespeare", BOOK, attribute.getTextContent());
attribute = (Attr) node.getAttributes().getNamedItem(LREV);
assertNotNull("test for existence of revision attribute in collection", attribute);
node = listRes.item(3);
attribute = (Attr) node.getAttributes().getNamedItem(NAME);
assertEquals("test for name books", SHAKE, attribute.getTextContent());
attribute = (Attr) node.getAttributes().getNamedItem(LREV);
assertNotNull("test for existence of revision attribute in collection", attribute);
outputStream.close();
sirix.deleteResource(EBAY);
sirix.deleteResource(FACT);
sirix.deleteResource(BOOK);
sirix.deleteResource(SHAKE);
}
use of org.sirix.service.jaxrx.implementation.DatabaseRepresentation in project sirix by sirixdb.
the class RestXPathProcessorTest method setUpGlobal.
@BeforeClass
public static void setUpGlobal() throws SirixException {
deleteDirectory(TestHelper.PATHS.PATH1.getFile());
final InputStream xmlInput = RestXPathProcessorTest.class.getResourceAsStream("/books.xml");
new DatabaseRepresentation(TestHelper.PATHS.PATH1.getFile()).shred(xmlInput, RESOURCENAME);
}
use of org.sirix.service.jaxrx.implementation.DatabaseRepresentation in project sirix by sirixdb.
the class RESTResponseHelper method createCollectionElementDBs.
/**
* This method creates the XML element containing a collection. This
* collection contains the available resources which are children of the
* database.
*
* @param resources
* the list with the path of the available resources
* @param pStoragePath
* path where the data must be stored
* @param document
* the XML {@link Document} instance
* @return a list of XML {@link Element} as the collection
* @throws SirixException
* @throws WebApplicationException
*/
private static List<Element> createCollectionElementDBs(final File pStoragePath, final List<String> resources, final Document document) throws WebApplicationException, SirixException {
final List<Element> collectionsEls = new ArrayList<Element>();
for (final String res : resources) {
final Element elRes = document.createElement("resource");
// Getting the name
elRes.setAttribute("name", res);
// get last revision from given db name
final DatabaseRepresentation dbWorker = new DatabaseRepresentation(pStoragePath);
final String lastRevision = Long.toString(dbWorker.getLastRevision(res.toString()));
elRes.setAttribute("lastRevision", lastRevision);
collectionsEls.add(elRes);
}
return collectionsEls;
}
use of org.sirix.service.jaxrx.implementation.DatabaseRepresentation in project sirix by sirixdb.
the class WorkerHelperTest method setUp.
/**
* A simple set up.
*
* @throws FileNotFoundException
*/
@Before
public void setUp() throws FileNotFoundException, SirixException {
TestHelper.closeEverything();
TestHelper.deleteEverything();
TestHelper.getDatabase(TestHelper.PATHS.PATH1.getFile());
workerHelper = WorkerHelper.getInstance();
sirix = new DatabaseRepresentation(TestHelper.PATHS.PATH1.getFile());
sirix.shred(INPUTFILE, RESOURCENAME);
}
Aggregations