NodeIdRepresentation { public StreamingOutput performQueryOnResource(final String resourceName, final long nodeId, final String query, final Map<QueryParameter, String> queryParams) { final StreamingOutput sOutput = new StreamingOutput() { @Override public void write(final OutputStream output) throws IOException, JaxRxException { final File dbFile = new File(mStoragePath, resourceName); final String revision = queryParams.get(QueryParameter.REVISION); final String wrap = queryParams.get(QueryParameter.WRAP); final String doNodeId = queryParams.get(QueryParameter.OUTPUT); final boolean wrapResult = (wrap == null) ? true : wrap .equalsIgnoreCase(YESSTRING); final boolean nodeid = (doNodeId == null) ? false : doNodeId .equalsIgnoreCase(YESSTRING); final Integer rev = revision == null ? null : Integer.valueOf(revision); final RestXPathProcessor xpathProcessor = new RestXPathProcessor( mStoragePath); try { xpathProcessor.getXpathResource(dbFile, nodeId, query, nodeid, rev, output, wrapResult); } catch (final SirixException exce) { throw new JaxRxException(exce); } } }; return sOutput; } NodeIdRepresentation(final File storagePath); StreamingOutput getResource(final String resourceName,
			final long nodeId, final Map<QueryParameter, String> queryParams); StreamingOutput getResourceByAT(final String resourceName,
			final long nodeId, final Map<QueryParameter, String> queryParams,
			final IDAccessType accessType); StreamingOutput performQueryOnResource(final String resourceName,
			final long nodeId, final String query,
			final Map<QueryParameter, String> queryParams); void deleteResource(final String resourceName, final long nodeId); void modifyResource(final String resourceName, final long nodeId,
			final InputStream newValue); void addSubResource(final String resourceName, final long nodeId,
			final InputStream input, final IDAccessType type);  }
@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); }