XMLServiceDocumentWriter { public String buildServiceDocument() throws ODataRenderException { LOG.info("Building service(root) document"); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(BUFFER_SIZE)) { XMLStreamWriter writer = startServiceDocument(outputStream); writeEntitySets(writer); writeSingleton(writer); endServiceDocument(writer); LOG.info("Successfully built service document"); return outputStream.toString(); } catch (XMLStreamException | IOException e) { String msg = "Something went wrong when writing service document."; LOG.error(msg, e); throw new ODataRenderException(msg, e); } } XMLServiceDocumentWriter(ODataUri uri, EntityDataModel entityDataModel); String buildServiceDocument();  }
@Test public void testBuildServiceDocument() throws Exception { odataUri = new ODataParserImpl().parseUri("http: String serviceDocument = new XMLServiceDocumentWriter(odataUri, entityDataModel).buildServiceDocument(); assertNotNull(serviceDocument); assertEquals(prettyPrintXml(readContent(SERVICE_DOCUMENT)), prettyPrintXml(serviceDocument)); }
@Test(expected = ODataRenderException.class) public void testBuildServiceDocumentException() throws ODataRenderException, IOException, TransformerException { EntityDataModel entityDataModel = mock(EntityDataModel.class); String serviceDocument = new XMLServiceDocumentWriter(odataUri, entityDataModel).buildServiceDocument(); assertNotNull(serviceDocument); assertEquals(prettyPrintXml(readContent(SERVICE_DOCUMENT)), prettyPrintXml(serviceDocument)); }