Supply body for POST/PUT/PATCH tests (for OkHttp 2.4 compatibility)

master
Juergen Hoeller 9 years ago
parent 4b05bda0bf
commit 2bed89340b
  1. 6
      spring-web/src/test/java/org/springframework/http/client/AbstractAsyncHttpRequestFactoryTestCase.java
  2. 9
      spring-web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTestCase.java

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -206,6 +206,10 @@ public abstract class AbstractAsyncHttpRequestFactoryTestCase extends AbstractJe
ClientHttpResponse response = null;
try {
AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/methods/" + path), method);
if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) {
// requires a body
request.getBody().write(32);
}
Future<ClientHttpResponse> futureResponse = request.executeAsync();
response = futureResponse.get();
assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());

@ -172,6 +172,15 @@ public abstract class AbstractHttpRequestFactoryTestCase extends AbstractJettySe
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());

Loading…
Cancel
Save