RestXPathProcessor { public OutputStream getXpathResource(final String resourceName, final String xpath, final boolean nodeid, final Integer revision, final OutputStream output, final boolean wrapResult) throws IOException, SirixException { String qQuery = xpath; if (xpath.charAt(0) == '/') qQuery = ".".concat(xpath); if (WorkerHelper.checkExistingResource(mStoragePath, resourceName)) { if (wrapResult) { output.write(beginResult.getBytes()); doXPathRes(resourceName, revision, output, nodeid, qQuery); output.write(endResult.getBytes()); } else { doXPathRes(resourceName, revision, output, nodeid, qQuery); } } else { throw new WebApplicationException(Response.Status.NOT_FOUND); } return output; } RestXPathProcessor(final File pStoragePath); OutputStream getXpathResource(final String resourceName,
			final String xpath, final boolean nodeid, final Integer revision,
			final OutputStream output, final boolean wrapResult); void getXpathResource(final File dbFile, final long rId,
			final String query, final boolean doNodeId, final Integer doRevision,
			final OutputStream output, final boolean doWrap);  }
@Test public final void testGetXpathResourceStringStringBooleanLongOutputStreamBoolean() throws IOException, SAXException, ParserConfigurationException, SirixException { String xPath = " boolean withNodeIds = true; OutputStream output = new ByteArrayOutputStream(); rxProcessor.getXpathResource(RESOURCENAME, xPath, withNodeIds, 1, output, true); InputStream xmlInput = new ByteArrayInputStream( ((ByteArrayOutputStream) output).toByteArray()); Document resultDoc = xmlDocument(xmlInput); final NodeList bNodes = resultDoc.getElementsByTagName(PARAMBOOKS); assertEquals("test for items size of books is 6", 6, bNodes.getLength()); final NodeList aNodes = resultDoc.getElementsByTagName(PARAMAUTHOR); assertEquals("test for items size of authors is 12", 12, aNodes.getLength()); final NodeList rNodes = resultDoc.getElementsByTagName(PARAMJAXRES); assertEquals("test for existence of result element is 1", 1, rNodes.getLength()); final NodeList iNodes = resultDoc.getElementsByTagName(PARAMJRESTSEQ); assertEquals("test for existence of node ids", 6, iNodes.getLength()); xPath = " withNodeIds = false; output = new ByteArrayOutputStream(); rxProcessor.getXpathResource(RESOURCENAME, xPath, withNodeIds, null, output, true); xmlInput = new ByteArrayInputStream( ((ByteArrayOutputStream) output).toByteArray()); resultDoc = xmlDocument(xmlInput); final NodeList b2Nodes = resultDoc.getElementsByTagName(PARAMBOOKS); assertEquals("test for items size of books is 0", 0, b2Nodes.getLength()); final NodeList a2Nodes = resultDoc.getElementsByTagName(PARAMAUTHOR); assertEquals("test for items size of authors", 12, a2Nodes.getLength()); final NodeList r2Nodes = resultDoc.getElementsByTagName(PARAMJAXRES); assertEquals("test for existence of result element", 1, r2Nodes.getLength()); final NodeList i2Nodes = resultDoc.getElementsByTagName(PARAMJRESTSEQ); assertEquals("test for existence of node ids", 0, i2Nodes.getLength()); }
@Test public final void testGetXpathResourceFileLongStringBooleanLongOutputStreamBoolean() throws SAXException, IOException, ParserConfigurationException, SirixException { String xPath = " boolean withNodeIds = true; OutputStream output = new ByteArrayOutputStream(); final File tnkFile = new File(TestHelper.PATHS.PATH1.getFile(), RESOURCENAME); rxProcessor.getXpathResource(tnkFile, 10L, xPath, withNodeIds, 1, output, true); InputStream xmlInput = new ByteArrayInputStream( ((ByteArrayOutputStream) output).toByteArray()); Document resultDoc = xmlDocument(xmlInput); final NodeList bNodes = resultDoc.getElementsByTagName(PARAMBOOKS); assertEquals("test for items size of books", 0, bNodes.getLength()); final NodeList aNodes = resultDoc.getElementsByTagName(PARAMAUTHOR); assertEquals("test for items size of authors is 2", 2, aNodes.getLength()); final NodeList rNodes = resultDoc.getElementsByTagName(PARAMJAXRES); assertEquals("test for item of result element is 1", 1, rNodes.getLength()); final NodeList iNodes = resultDoc.getElementsByTagName(PARAMJRESTSEQ); assertEquals("test for existence of node ids", 2, iNodes.getLength()); xPath = " withNodeIds = false; output = new ByteArrayOutputStream(); rxProcessor.getXpathResource(tnkFile, 10L, xPath, withNodeIds, null, output, true); xmlInput = new ByteArrayInputStream( ((ByteArrayOutputStream) output).toByteArray()); resultDoc = xmlDocument(xmlInput); final NodeList b2Nodes = resultDoc.getElementsByTagName(PARAMBOOKS); assertEquals("test for item size of books", 0, b2Nodes.getLength()); final NodeList a2Nodes = resultDoc.getElementsByTagName(PARAMAUTHOR); assertEquals("test for item size of authors", 2, a2Nodes.getLength()); final NodeList r2Nodes = resultDoc.getElementsByTagName(PARAMJAXRES); assertEquals("test of result element", 1, r2Nodes.getLength()); final NodeList i2Nodes = resultDoc.getElementsByTagName(PARAMJRESTSEQ); assertEquals("test existence of node ids", 0, i2Nodes.getLength()); }