Skip to content

Commit a7e347a

Browse files
committed
confirm that any type of requests can have content set
1 parent d6c4202 commit a7e347a

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

google-http-client-apache-v5/src/test/java/com/google/api/client/http/apache/v5/Apache5HttpTransportTest.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static org.junit.Assert.assertNotNull;
2020
import static org.junit.Assert.assertTrue;
2121
import static org.junit.Assert.fail;
22-
import static org.junit.Assume.assumeFalse;
2322
import static org.junit.Assume.assumeTrue;
2423

2524
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
@@ -83,8 +82,7 @@ public void testRequest(HttpTransport transport) throws IOException {
8382
assumeTrue(credentials != null);
8483
GsonFactory jsonFactory = GsonFactory.getDefaultInstance();
8584
CloudResourceManager.Builder resourceManagerBuilder =
86-
new CloudResourceManager.Builder(
87-
transport, jsonFactory, credentials)
85+
new CloudResourceManager.Builder(transport, jsonFactory, credentials)
8886
.setApplicationName("Example Java App");
8987
CloudResourceManager cloudResourceManager = resourceManagerBuilder.build();
9088

@@ -148,12 +146,7 @@ private void checkHttpClient(HttpClient client) {
148146

149147
@Test
150148
public void testRequestsWithContent() throws IOException {
151-
// This test ensures that requests that have content are rejected, as opposed to those with an
152-
// entity set.
153-
// It is currently failing because we don't perform this check in Apache5HttpRequest.execute();
154-
// TODO(diegomarquezp): find out whether this check is necessary in Apache 5.
155-
// skip for now
156-
assumeFalse(true);
149+
// This test confirms that we can set the content on any type of request
157150
HttpClient mockClient =
158151
new MockHttpClient() {
159152
@Override
@@ -165,14 +158,11 @@ public ClassicHttpResponse executeOpen(
165158
Apache5HttpTransport transport = new Apache5HttpTransport(mockClient);
166159

167160
// Test GET.
168-
subtestUnsupportedRequestsWithContent(
169-
transport.buildRequest("GET", "http://www.test.url"), "GET");
161+
execute(transport.buildRequest("GET", "http://www.test.url"));
170162
// Test DELETE.
171-
subtestUnsupportedRequestsWithContent(
172-
transport.buildRequest("DELETE", "http://www.test.url"), "DELETE");
163+
execute(transport.buildRequest("DELETE", "http://www.test.url"));
173164
// Test HEAD.
174-
subtestUnsupportedRequestsWithContent(
175-
transport.buildRequest("HEAD", "http://www.test.url"), "HEAD");
165+
execute(transport.buildRequest("HEAD", "http://www.test.url"));
176166

177167
// Test PATCH.
178168
execute(transport.buildRequest("PATCH", "http://www.test.url"));
@@ -184,19 +174,6 @@ public ClassicHttpResponse executeOpen(
184174
execute(transport.buildRequest("PATCH", "http://www.test.url"));
185175
}
186176

187-
private void subtestUnsupportedRequestsWithContent(Apache5HttpRequest request, String method)
188-
throws IOException {
189-
try {
190-
execute(request);
191-
fail("expected " + IllegalStateException.class);
192-
} catch (IllegalStateException e) {
193-
// expected
194-
assertEquals(
195-
e.getMessage(),
196-
"Apache HTTP client does not support " + method + " requests with content.");
197-
}
198-
}
199-
200177
private void execute(Apache5HttpRequest request) throws IOException {
201178
byte[] bytes = "abc".getBytes(StandardCharsets.UTF_8);
202179
request.setStreamingContent(new ByteArrayStreamingContent(bytes));

0 commit comments

Comments
 (0)