ServiceDocumentXmlSerializer { public void writeServiceDocument(final XMLStreamWriter writer) throws XMLStreamException { final String metadataUri = (serviceRoot == null ? "" : serviceRoot.endsWith("/") ? serviceRoot : (serviceRoot + "/")) + Constants.METADATA; writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0"); writer.writeStartElement(APP, "service", NS_APP); writer.writeNamespace(ATOM, NS_ATOM); writer.writeNamespace(APP, NS_APP); writer.writeNamespace(METADATA, NS_METADATA); writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT, metadataUri); if (metadata != null && metadata.getServiceMetadataETagSupport() != null && metadata.getServiceMetadataETagSupport().getMetadataETag() != null) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATOM_ATTR_METADATAETAG, metadata.getServiceMetadataETagSupport().getMetadataETag()); } writer.writeStartElement(APP, "workspace", NS_APP); final EdmEntityContainer container = metadata.getEdm().getEntityContainer(); if (container != null) { writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM); writer.writeCharacters(container.getFullQualifiedName().getFullQualifiedNameAsString()); writer.writeEndElement(); writeEntitySets(writer, container); writeFunctionImports(writer, container); writeSingletons(writer, container); writeServiceDocuments(writer); } writer.writeEndElement(); writer.writeEndElement(); } ServiceDocumentXmlSerializer(final ServiceMetadata metadata, final String serviceRoot); void writeServiceDocument(final XMLStreamWriter writer);  }
@Test public void writeServiceDocument() throws Exception { CsdlEdmProvider provider = new MetadataDocumentXmlSerializerTest.LocalProvider(); ServiceMetadata serviceMetadata = new ServiceMetadataImpl(provider, Collections.<EdmxReference> emptyList(), null); InputStream metadataStream = serializer.serviceDocument(serviceMetadata, "http: String metadata = IOUtils.toString(metadataStream); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<app:service xmlns:atom=\"http: + "xmlns:app=\"http: + "xmlns:metadata=\"http: + "metadata:context=\"http: + "<app:workspace>" + "<atom:title>org.olingo.container</atom:title>" + "<app:collection href=\"ESAllPrim\" metadata:name=\"ESAllPrim\">" + "<atom:title>ESAllPrim</atom:title>" + "</app:collection>" + "<metadata:function-import href=\"FINRTInt16\" metadata:name=\"FINRTInt16\">" + "<atom:title>FINRTInt16</atom:title>" + "</metadata:function-import>" + "<metadata:function-import href=\"FINRTET\" metadata:name=\"FINRTET\">" + "<atom:title>FINRTET</atom:title>" + "</metadata:function-import>" + "<metadata:singleton href=\"SI\" metadata:name=\"SI\">" + "<atom:title>SI</atom:title>" + "</metadata:singleton>" + "</app:workspace>" + "</app:service>", metadata); }