@Test public void headers() throws URISyntaxException { MediaType accept = MediaType.TEXT_PLAIN; Charset charset = Charset.forName("UTF-8"); long ifModifiedSince = 12345L; String ifNoneMatch = "\"foo\""; long contentLength = 67890; MediaType contentType = MediaType.TEXT_PLAIN; RequestEntity<Void> responseEntity = RequestEntity.post(new URI("http://example.com")) .accept(accept) .acceptCharset(charset) .ifModifiedSince(ifModifiedSince) .ifNoneMatch(ifNoneMatch) .contentLength(contentLength) .contentType(contentType) .build(); assertNotNull(responseEntity); assertEquals(HttpMethod.POST, responseEntity.getMethod()); assertEquals(new URI("http://example.com"), responseEntity.getUrl()); HttpHeaders responseHeaders = responseEntity.getHeaders(); assertEquals("text/plain", responseHeaders.getFirst("Accept")); assertEquals("utf-8", responseHeaders.getFirst("Accept-Charset")); assertEquals("Thu, 01 Jan 1970 00:00:12 GMT", responseHeaders.getFirst("If-Modified-Since")); assertEquals(ifNoneMatch, responseHeaders.getFirst("If-None-Match")); assertEquals(String.valueOf(contentLength), responseHeaders.getFirst("Content-Length")); assertEquals(contentType.toString(), responseHeaders.getFirst("Content-Type")); assertNull(responseEntity.getBody()); }
@Test public void methods() throws URISyntaxException { URI url = new URI("http://example.com"); RequestEntity<?> entity = RequestEntity.get(url).build(); assertEquals(HttpMethod.GET, entity.getMethod()); entity = RequestEntity.post(url).build(); assertEquals(HttpMethod.POST, entity.getMethod()); entity = RequestEntity.head(url).build(); assertEquals(HttpMethod.HEAD, entity.getMethod()); entity = RequestEntity.options(url).build(); assertEquals(HttpMethod.OPTIONS, entity.getMethod()); entity = RequestEntity.put(url).build(); assertEquals(HttpMethod.PUT, entity.getMethod()); entity = RequestEntity.patch(url).build(); assertEquals(HttpMethod.PATCH, entity.getMethod()); entity = RequestEntity.delete(url).build(); assertEquals(HttpMethod.DELETE, entity.getMethod()); }
@Test // SPR-13154 public void types() throws URISyntaxException { URI url = new URI("http://example.com"); List<String> body = Arrays.asList("foo", "bar"); ParameterizedTypeReference<?> typeReference = new ParameterizedTypeReference<List<String>>() {}; RequestEntity<?> entity = RequestEntity.post(url).body(body, typeReference.getType()); assertEquals(typeReference.getType(), entity.getType()); }