Search in sources :

Example 1 with DatabaseRepresentation

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);
}
Also used : NodeIdRepresentationTest(org.sirix.service.jaxrx.implementation.NodeIdRepresentationTest) InputStream(java.io.InputStream) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) StreamingOutput(javax.ws.rs.core.StreamingOutput) DatabaseRepresentation(org.sirix.service.jaxrx.implementation.DatabaseRepresentation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) Test(org.junit.Test) NodeIdRepresentationTest(org.sirix.service.jaxrx.implementation.NodeIdRepresentationTest)

Example 2 with DatabaseRepresentation

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DatabaseRepresentation(org.sirix.service.jaxrx.implementation.DatabaseRepresentation) BeforeClass(org.junit.BeforeClass)

Example 3 with DatabaseRepresentation

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;
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DatabaseRepresentation(org.sirix.service.jaxrx.implementation.DatabaseRepresentation)

Example 4 with DatabaseRepresentation

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);
}
Also used : DatabaseRepresentation(org.sirix.service.jaxrx.implementation.DatabaseRepresentation) Before(org.junit.Before)

Aggregations

DatabaseRepresentation (org.sirix.service.jaxrx.implementation.DatabaseRepresentation)4 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 NodeIdRepresentationTest (org.sirix.service.jaxrx.implementation.NodeIdRepresentationTest)1 Attr (org.w3c.dom.Attr)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1