@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://host/svc").getContent(); String metadata = IOUtils.toString(metadataStream); assertEquals( "<?xml version='1.0' encoding='UTF-8'?>" + "<app:service xmlns:atom=\"http://www.w3.org/2005/Atom\" " + "xmlns:app=\"http://www.w3.org/2007/app\" " + "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" " + "metadata:context=\"http://host/svc/$metadata\">" + "<app:workspace>" + "<atom:title>org.olingo.container</atom:title>" + "<app:collection href=\"ESAllPrim\">" + "<atom:title>ESAllPrim</atom:title>" + "</app:collection>" + "<metadata:function-import href=\"FINRTInt16\">" + "<atom:title>FINRTInt16</atom:title>" + "</metadata:function-import>" + "<metadata:singleton href=\"SI\">" + "<atom:title>SI</atom:title>" + "</metadata:singleton>" + "</app:workspace>" + "</app:service>", metadata); }
@Test public void writeServiceWithEmptyMockedEdm() throws Exception { final Edm edm = mock(Edm.class); EdmEntityContainer container = mock(EdmEntityContainer.class); when(container.getFullQualifiedName()).thenReturn(new FullQualifiedName("service", "test")); when(container.getEntitySets()).thenReturn(Collections.<EdmEntitySet>emptyList()); when(container.getFunctionImports()).thenReturn(Collections.<EdmFunctionImport>emptyList()); when(container.getSingletons()).thenReturn(Collections.<EdmSingleton>emptyList()); when(edm.getEntityContainer()).thenReturn(container); ServiceMetadata metadata = mock(ServiceMetadata.class); when(metadata.getEdm()).thenReturn(edm); assertEquals( "<?xml version='1.0' encoding='UTF-8'?>" + "<app:service xmlns:atom=\"http://www.w3.org/2005/Atom\" " + "xmlns:app=\"http://www.w3.org/2007/app\" " + "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" " + "metadata:context=\"http://host/svc/$metadata\">" + "<app:workspace><atom:title>service.test</atom:title></app:workspace>" + "</app:service>", IOUtils.toString(serializer.serviceDocument(metadata, "http://host/svc").getContent())); }