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);
}
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();
}
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);
}
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);
}
Aggregations