Supply body for POST/PUT/PATCH tests (for OkHttp 2.4 compatibility)
This commit is contained in:
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
ClientHttpResponse response = null;
|
||||||
try {
|
try {
|
||||||
AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/methods/" + path), method);
|
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();
|
Future<ClientHttpResponse> futureResponse = request.executeAsync();
|
||||||
response = futureResponse.get();
|
response = futureResponse.get();
|
||||||
assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
|
assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
|
||||||
|
|||||||
@@ -172,6 +172,15 @@ public abstract class AbstractHttpRequestFactoryTestCase extends AbstractJettySe
|
|||||||
ClientHttpResponse response = null;
|
ClientHttpResponse response = null;
|
||||||
try {
|
try {
|
||||||
ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/methods/" + path), method);
|
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();
|
response = request.execute();
|
||||||
assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
|
assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
|
||||||
assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
|
assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
|
||||||
|
|||||||
Reference in New Issue
Block a user