@Test public void acceptHeaderAppXmlCharsetUtf8() throws Exception { HttpGet get = new HttpGet(URI.create(getEndpoint() + "Rooms('1')")); get.setHeader(HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML_UTF8); final HttpResponse response = new DefaultHttpClient().execute(get); final String contentType = response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(); assertEquals(HttpContentType.APPLICATION_XML_UTF8, contentType); assertEquals( ContentType.create(HttpContentType.APPLICATION_XML_UTF8), ContentType.create(contentType)); assertNotNull(StringHelper.inputStreamToString(response.getEntity().getContent())); }
@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); }