XMLErrorResponseWriter { public void writeError(ODataException exception) throws ODataRenderException { checkNotNull(exception); try { xmlWriter.writeStartElement(ODATA_METADATA_NS, ERROR); xmlWriter.writeNamespace(METADATA, ODATA_METADATA_NS); xmlWriter.writeStartElement(METADATA, ErrorRendererConstants.CODE, ODATA_METADATA_NS); xmlWriter.writeCharacters(String.valueOf(exception.getCode().getCode())); xmlWriter.writeEndElement(); xmlWriter.writeStartElement(METADATA, ErrorRendererConstants.MESSAGE, ODATA_METADATA_NS); xmlWriter.writeCharacters(String.valueOf(exception.getMessage())); xmlWriter.writeEndElement(); if (exception.getTarget() != null) { xmlWriter.writeStartElement(METADATA, TARGET, ODATA_METADATA_NS); xmlWriter.writeCharacters(String.valueOf(exception.getTarget())); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } catch (XMLStreamException e) { LOG.error("Not possible to marshall error stream XML"); throw new ODataRenderException("Not possible to marshall error stream XML: ", e); } } XMLErrorResponseWriter(); void startDocument(); void endDocument(); void writeError(ODataException exception); String getXml();  }
@Test public void testWriteError() throws Exception { XMLErrorResponseWriter writer = new XMLErrorResponseWriter(); writer.startDocument(); writer.writeError(new ODataServerException(EDM_ERROR, "EDM error")); writer.endDocument(); assertEquals(prettyPrintXml(readContent(EXPECTED_ERROR_RESPONSE_PATH)), prettyPrintXml(writer.getXml())); }