@Override protected ODataSingleProcessor createProcessor() throws ODataException { final ODataSingleProcessor processor = mock(ODataSingleProcessor.class); when(((MetadataProcessor) processor) .readMetadata(any(GetMetadataUriInfo.class), any(String.class))) .thenReturn(ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build()); when(((ServiceDocumentProcessor) processor) .readServiceDocument(any(GetServiceDocumentUriInfo.class), any(String.class))) .thenReturn(ODataResponse.entity("service document").status(HttpStatusCodes.OK).build()); return processor; }
@Test public void serviceDocumentEmpty() throws Exception { Edm edm = mock(Edm.class); EdmServiceMetadata metadata = mock(EdmServiceMetadata.class); when(edm.getServiceMetadata()).thenReturn(metadata); final ODataResponse response = new JsonEntityProvider().writeServiceDocument(edm, "http://host:80/service/"); assertNotNull(response); assertNotNull(response.getEntity()); assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader()); assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION)); final String json = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertNotNull(json); assertEquals("{\"d\":{\"EntitySets\":[]}}", json); }
@Test public void serviceDocument() throws Exception { Edm edm = mock(Edm.class); EdmServiceMetadata metadata = mock(EdmServiceMetadata.class); EdmEntitySetInfo entitySetInfo1 = mock(EdmEntitySetInfo.class); when(entitySetInfo1.getEntitySetUri()).thenReturn(URI.create("EntitySet")); EdmEntitySetInfo entitySetInfo2 = mock(EdmEntitySetInfo.class); when(entitySetInfo2.getEntitySetUri()).thenReturn(URI.create("Container2.EntitySet2")); when(metadata.getEntitySetInfos()).thenReturn(Arrays.asList(entitySetInfo1, entitySetInfo2)); when(edm.getServiceMetadata()).thenReturn(metadata); final ODataResponse response = new JsonEntityProvider().writeServiceDocument(edm, "http://host:80/service/"); assertNotNull(response); assertNotNull(response.getEntity()); assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader()); assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION)); final String json = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertNotNull(json); assertEquals("{\"d\":{\"EntitySets\":[\"EntitySet\",\"Container2.EntitySet2\"]}}", json); }