@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())); }
private void wrongRequestContentType( final ODataHttpMethod method, final UriType uriType, final boolean isValue, final ContentType requestContentType) throws EdmException, ODataException { wrongRequestContentType(method, uriType, isValue, requestContentType.toContentTypeString()); }
@Test public void wrongRequestContentType() throws Exception { wrongRequestContentType(ODataHttpMethod.PUT, UriType.URI2, ContentType.APPLICATION_ATOM_SVC); wrongRequestContentType( ODataHttpMethod.PUT, UriType.URI2, ContentType.APPLICATION_ATOM_SVC_CS_UTF_8); wrongRequestContentType(ODataHttpMethod.PUT, UriType.URI2, ContentType.APPLICATION_ATOM_SVC); wrongRequestContentType( ODataHttpMethod.PUT, UriType.URI2, ContentType.APPLICATION_ATOM_SVC_CS_UTF_8); ODataHttpMethod[] methodsToTest = { ODataHttpMethod.PUT, ODataHttpMethod.PATCH, ODataHttpMethod.MERGE }; for (ODataHttpMethod oDataHttpMethod : methodsToTest) { wrongRequestContentType( oDataHttpMethod, UriType.URI2, false, ContentType.create("image/jpeg")); wrongRequestContentType( oDataHttpMethod, UriType.URI5, true, ContentType.APPLICATION_ATOM_SVC); wrongRequestContentType( oDataHttpMethod, UriType.URI5, true, ContentType.APPLICATION_ATOM_SVC_CS_UTF_8); wrongRequestContentType(oDataHttpMethod, UriType.URI5, true, ContentType.APPLICATION_XML); wrongRequestContentType( oDataHttpMethod, UriType.URI5, true, ContentType.APPLICATION_XML_CS_UTF_8); wrongRequestContentType( oDataHttpMethod, UriType.URI5, true, ContentType.APPLICATION_ATOM_XML); wrongRequestContentType( oDataHttpMethod, UriType.URI5, true, ContentType.APPLICATION_ATOM_XML_CS_UTF_8); wrongRequestContentType(oDataHttpMethod, UriType.URI5, true, ContentType.APPLICATION_JSON); wrongRequestContentType( oDataHttpMethod, UriType.URI5, true, ContentType.APPLICATION_JSON_CS_UTF_8); wrongRequestContentType( oDataHttpMethod, UriType.URI5, true, ContentType.create("image/jpeg")); } EdmEntityType entityType = edm.getDefaultEntityContainer().getEntitySet("Employees").getEntityType(); when(entityType.hasStream()).thenReturn(false); wrongRequestContentType(ODataHttpMethod.POST, UriType.URI1, ContentType.APPLICATION_ATOM_SVC); wrongRequestContentType( ODataHttpMethod.POST, UriType.URI1, ContentType.APPLICATION_ATOM_SVC_CS_UTF_8); }