Search in sources :

Example 6 with QueryParameter

use of org.jaxrx.core.QueryParameter in project sirix by sirixdb.

the class NodeIdRepresentationTest method testGetResource.

/**
 * Test method for
 * {@link org.sirix.service.jaxrx.implementation.NodeIdRepresentation#getResource(java.lang.String, long, java.util.Map)}
 * .
 *
 * @throws IOException
 * @throws WebApplicationException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
@Test
public final void testGetResource() throws WebApplicationException, IOException, ParserConfigurationException, SAXException {
    final Map<QueryParameter, String> queryParams = new HashMap<QueryParameter, String>();
    queryParams.put(QueryParameter.OUTPUT, LITERALSTRUE);
    queryParams.put(QueryParameter.WRAP, LITERALSTRUE);
    queryParams.put(QueryParameter.REVISION, "0");
    ByteArrayOutputStream outputStream;
    StreamingOutput result;
    Document doc;
    NodeList list;
    Node node;
    Node resultNode;
    Attr attribute;
    // Test for fist child
    result = ridWorker.getResource(RESOURCENAME, NODEIDGETRESOURCE, queryParams);
    outputStream = new ByteArrayOutputStream();
    result.write(outputStream);
    doc = DOMHelper.buildDocument(outputStream);
    list = doc.getElementsByTagName("city");
    node = list.item(0);
    attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
    final NodeList resultList = doc.getElementsByTagName(RESULTNAME);
    resultNode = resultList.item(0);
    outputStream.close();
    assertNotNull("Test if node exist 1a", node);
    assertNotNull("Test if node exist 1b", resultNode);
    assertNotNull("Test if node exist 1c", attribute);
    queryParams.clear();
    queryParams.put(QueryParameter.OUTPUT, LITERALSFALSE);
    queryParams.put(QueryParameter.QUERY, null);
    queryParams.put(QueryParameter.WRAP, LITERALSFALSE);
    queryParams.put(QueryParameter.REVISION, null);
    result = ridWorker.getResource(RESOURCENAME, NODEIDGETRESOURCE, queryParams);
    outputStream = new ByteArrayOutputStream();
    result.write(outputStream);
    doc = DOMHelper.buildDocument(outputStream);
    list = doc.getElementsByTagName(COUNTRYNAME);
    node = list.item(0);
    attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
    resultNode = doc.getElementsByTagName(RESULTNAME).item(0);
    outputStream.close();
    assertNotNull("Test if node exist 2a", node);
    assertNull("Test if node exist 2b", resultNode);
    assertNull("Test if node exist 2c", attribute);
    queryParams.clear();
    queryParams.put(QueryParameter.OUTPUT, LITERALSFALSE);
    queryParams.put(QueryParameter.WRAP, LITERALSTRUE);
    queryParams.put(QueryParameter.REVISION, null);
    result = ridWorker.getResource(RESOURCENAME, NODEIDGETRESOURCE, queryParams);
    outputStream = new ByteArrayOutputStream();
    result.write(outputStream);
    doc = DOMHelper.buildDocument(outputStream);
    list = doc.getElementsByTagName("city");
    node = list.item(0);
    attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
    resultNode = doc.getElementsByTagName(RESULTNAME).item(0);
    outputStream.close();
    assertNotNull("Test if node exist 3a", node);
    assertNotNull("Test if node exist 3b", resultNode);
    assertNull("Test if node exist 3c", attribute);
    queryParams.clear();
    queryParams.put(QueryParameter.OUTPUT, LITERALSFALSE);
    queryParams.put(QueryParameter.WRAP, LITERALSTRUE);
    queryParams.put(QueryParameter.REVISION, "0");
    result = ridWorker.getResource(RESOURCENAME, NODEIDGETRESOURCE, queryParams);
    outputStream = new ByteArrayOutputStream();
    result.write(outputStream);
    doc = DOMHelper.buildDocument(outputStream);
    list = doc.getElementsByTagName(COUNTRYNAME);
    node = list.item(0);
    attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
    resultNode = doc.getElementsByTagName(RESULTNAME).item(0);
    outputStream.close();
    assertNotNull("Test if node exist 4a", node);
    assertNotNull("Test if node exist 4b", resultNode);
    assertNull("Test if node exist 4c", attribute);
}
Also used : QueryParameter(org.jaxrx.core.QueryParameter) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) StreamingOutput(javax.ws.rs.core.StreamingOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) Test(org.junit.Test)

Example 7 with QueryParameter

use of org.jaxrx.core.QueryParameter in project sirix by sirixdb.

the class DatabaseRepresentationTest method revertToRevision.

/**
 * This method tests
 * {@link DatabaseRepresentation#revertToRevision(String, long)}
 *
 * @throws SirixException
 * @throws IOException
 * @throws WebApplicationException
 * @throws SAXException
 * @throws ParserConfigurationException
 * @throws InterruptedException
 */
@Test
public void revertToRevision() throws SirixException, WebApplicationException, IOException, ParserConfigurationException, SAXException, InterruptedException {
    final NodeIdRepresentation rid = new NodeIdRepresentation(TestHelper.PATHS.PATH1.getFile());
    rid.deleteResource(RESOURCENAME, 8);
    rid.deleteResource(RESOURCENAME, 11);
    rid.deleteResource(RESOURCENAME, 14);
    assertEquals(ASSEQUALS, 4, sirix.getLastRevision(RESOURCENAME));
    sirix.revertToRevision(RESOURCENAME, 1);
    final StreamingOutput sOutput = rid.getResource(RESOURCENAME, 14, new HashMap<QueryParameter, String>());
    final ByteArrayOutputStream output = new ByteArrayOutputStream();
    sOutput.write(output);
    final Document doc = DOMHelper.buildDocument(output);
    final Node node = doc.getElementsByTagName("continent").item(0);
    final Attr attribute = (Attr) node.getAttributes().getNamedItem(NAME);
    final String africaString = attribute.getTextContent();
    assertNotNull("check if africa (14) exists in the latest version", africaString);
    assertEquals(ASSEQUALS, 5, sirix.getLastRevision(RESOURCENAME));
    output.close();
}
Also used : QueryParameter(org.jaxrx.core.QueryParameter) Node(org.w3c.dom.Node) StreamingOutput(javax.ws.rs.core.StreamingOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) Test(org.junit.Test)

Example 8 with QueryParameter

use of org.jaxrx.core.QueryParameter in project sirix by sirixdb.

the class NodeIdRepresentationTest method testDeleteResource.

/**
 * Test method for
 * {@link org.sirix.service.jaxrx.implementation.NodeIdRepresentation#deleteResource(java.lang.String, long)}
 * .
 *
 * @throws IOException
 * @throws WebApplicationException
 * @throws SAXException
 * @throws ParserConfigurationException
 * @throws InterruptedException
 */
@Test
public final void testDeleteResource() throws WebApplicationException, IOException, ParserConfigurationException, SAXException, InterruptedException {
    ridWorker.deleteResource(RESOURCENAME, NODEIDGETRESOURCE);
    final Map<QueryParameter, String> queryParams = new HashMap<QueryParameter, String>();
    queryParams.put(QueryParameter.OUTPUT, LITERALSTRUE);
    queryParams.put(QueryParameter.WRAP, LITERALSFALSE);
    final StreamingOutput result = ridWorker.performQueryOnResource(RESOURCENAME, 1, "//country[@name=\"Albania\"]", queryParams);
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    outputStream.write("<resulti>".getBytes());
    result.write(outputStream);
    outputStream.write("</resulti>".getBytes());
    final Document doc = DOMHelper.buildDocument(outputStream);
    final NodeList list = doc.getElementsByTagName("country");
    Node searchedNode = null;
    for (int i = 0; i < list.getLength(); i++) {
        final Element elem = (Element) list.item(i);
        final Attr name = elem.getAttributeNode(NAME);
        if (name.getTextContent().equals("Albania")) {
            searchedNode = list.item(i);
            break;
        }
    }
    outputStream.close();
    assertNull("Country Albania does not exist anymore", searchedNode);
}
Also used : QueryParameter(org.jaxrx.core.QueryParameter) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) StreamingOutput(javax.ws.rs.core.StreamingOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) Test(org.junit.Test)

Example 9 with QueryParameter

use of org.jaxrx.core.QueryParameter in project sirix by sirixdb.

the class NodeIdRepresentationTest method testPerformQueryOnResource.

/**
 * Test method for
 * {@link org.sirix.service.jaxrx.implementation.NodeIdRepresentation#performQueryOnResource(java.lang.String, long, java.lang.String, java.util.Map)}
 * .
 *
 * @throws IOException
 * @throws WebApplicationException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
@Test
public final void testPerformQueryOnResource() throws WebApplicationException, IOException, ParserConfigurationException, SAXException {
    final Map<QueryParameter, String> queryParams = new HashMap<QueryParameter, String>();
    queryParams.put(QueryParameter.OUTPUT, LITERALSTRUE);
    queryParams.put(QueryParameter.WRAP, LITERALSTRUE);
    queryParams.put(QueryParameter.REVISION, "1");
    ByteArrayOutputStream outputStream;
    Document doc;
    NodeList list;
    String textContent = null;
    Node node;
    Node resultNode;
    Attr attribute;
    StreamingOutput output;
    output = ridWorker.performQueryOnResource(RESOURCENAME, NODEIDGETRESOURCE, QUERY, queryParams);
    outputStream = new ByteArrayOutputStream();
    output.write(outputStream);
    doc = DOMHelper.buildDocument(outputStream);
    list = doc.getElementsByTagName(NAME);
    node = list.item(0);
    attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
    resultNode = doc.getElementsByTagName(RESULTNAME).item(0);
    textContent = node.getTextContent();
    assertEquals("Test expected city Tirane", "Tirane", textContent);
    assertNotNull("Test if wrapping is available", resultNode);
    assertNotNull("Test if node id is supported", attribute);
    node = list.item(list.getLength() - 1);
    textContent = node.getTextContent();
    outputStream.close();
    assertEquals("Test expected city Korce", "Korce", textContent);
    queryParams.clear();
    queryParams.put(QueryParameter.OUTPUT, LITERALSFALSE);
    queryParams.put(QueryParameter.WRAP, LITERALSTRUE);
    queryParams.put(QueryParameter.REVISION, "1");
    output = ridWorker.performQueryOnResource(RESOURCENAME, NODEIDGETRESOURCE, QUERY, queryParams);
    outputStream = new ByteArrayOutputStream();
    output.write(outputStream);
    doc = DOMHelper.buildDocument(outputStream);
    list = doc.getElementsByTagName(NAME);
    node = list.item(0);
    textContent = node.getTextContent();
    attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
    resultNode = doc.getElementsByTagName(RESULTNAME).item(0);
    outputStream.close();
    assertEquals("Test expected city name Tirane", "Tirane", textContent);
    assertNotNull("Test if wrapping is supported", resultNode);
    assertNull("Test if node id is not supported", attribute);
}
Also used : QueryParameter(org.jaxrx.core.QueryParameter) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) StreamingOutput(javax.ws.rs.core.StreamingOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 StreamingOutput (javax.ws.rs.core.StreamingOutput)9 QueryParameter (org.jaxrx.core.QueryParameter)9 Test (org.junit.Test)9 Document (org.w3c.dom.Document)9 Node (org.w3c.dom.Node)9 HashMap (java.util.HashMap)8 Attr (org.w3c.dom.Attr)6 NodeList (org.w3c.dom.NodeList)5 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Element (org.w3c.dom.Element)1