RESTResponseHelper { public static StreamingOutput buildResponseOfDomLR(final File storagePath, final List<String> availableRes) { final StreamingOutput sOutput = new StreamingOutput() { @Override public void write(final OutputStream output) throws IOException, WebApplicationException { Document document; try { document = createSurroundingXMLResp(); final Element resElement = RESTResponseHelper .createResultElement(document); List<Element> collections; try { collections = RESTResponseHelper.createCollectionElementDBs( storagePath, availableRes, document); } catch (final SirixException exce) { throw new WebApplicationException(exce); } for (final Element resource : collections) { resElement.appendChild(resource); } document.appendChild(resElement); final DOMSource domSource = new DOMSource(document); final StreamResult streamResult = new StreamResult(output); final Transformer transformer = TransformerFactory.newInstance() .newTransformer(); transformer.transform(domSource, streamResult); } catch (ParserConfigurationException | TransformerFactoryConfigurationError | TransformerException e) { throw new WebApplicationException(e); } } }; return sOutput; } private  RESTResponseHelper(); static StreamingOutput buildResponseOfDomLR(final File storagePath,
			final List<String> availableRes);  }
@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); }