From 2f21201171af225a11635ba6904da3314ca47055 Mon Sep 17 00:00:00 2001 From: Roy Clarkson Date: Wed, 24 Jun 2015 12:40:15 -0500 Subject: [PATCH] Update tests to OkHttp 2.4.0 --- .../spring-android-rest-template-test/pom.xml | 2 +- .../AbstractHttpRequestFactoryTestCase.java | 39 ++++++++++++------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/test/spring-android-rest-template-test/pom.xml b/test/spring-android-rest-template-test/pom.xml index 96ec77b0..ac903c30 100644 --- a/test/spring-android-rest-template-test/pom.xml +++ b/test/spring-android-rest-template-test/pom.xml @@ -14,7 +14,7 @@ 4.3.5.1 - 2.1.0 + 2.4.0 1.9.13 2.5.4 2.3.1 diff --git a/test/spring-android-rest-template-test/src/main/java/org/springframework/http/client/AbstractHttpRequestFactoryTestCase.java b/test/spring-android-rest-template-test/src/main/java/org/springframework/http/client/AbstractHttpRequestFactoryTestCase.java index 5de5c978..8e9ec27b 100644 --- a/test/spring-android-rest-template-test/src/main/java/org/springframework/http/client/AbstractHttpRequestFactoryTestCase.java +++ b/test/spring-android-rest-template-test/src/main/java/org/springframework/http/client/AbstractHttpRequestFactoryTestCase.java @@ -292,6 +292,30 @@ public void testHttpMethods() throws Exception { assertHttpMethod("delete", HttpMethod.DELETE); } + protected void assertHttpMethod(String path, HttpMethod method) throws Exception { + ClientHttpResponse response = null; + try { + ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/methods/" + path), method); + if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) { + // requires a body + try { + request.getBody().write(32); + } + catch (UnsupportedOperationException ex) { + // probably a streaming request - let's simply ignore it + } + } + response = request.execute(); + assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode()); + assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name()); + } + finally { + if (response != null) { + response.close(); + } + } + } + @MediumTest public void testGetAcceptEncodingGzip() throws Exception { ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/gzip"), HttpMethod.GET); @@ -448,21 +472,6 @@ public void writeTo(OutputStream outputStream) throws IOException { } } - protected void assertHttpMethod(String path, HttpMethod method) throws Exception { - ClientHttpResponse response = null; - try { - ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/methods/" + path), method); - response = request.execute(); - assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode()); - assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name()); - } - finally { - if (response != null) { - response.close(); - } - } - } - /** * Servlet that sets a given status code. */