diff --git a/google-api-client/src/test/java/com/google/api/client/googleapis/batch/BatchRequestTest.java b/google-api-client/src/test/java/com/google/api/client/googleapis/batch/BatchRequestTest.java index 371cec10e..944d3972d 100644 --- a/google-api-client/src/test/java/com/google/api/client/googleapis/batch/BatchRequestTest.java +++ b/google-api-client/src/test/java/com/google/api/client/googleapis/batch/BatchRequestTest.java @@ -480,7 +480,7 @@ private BatchRequest getBatchPopulatedWithRequests(boolean testServerError, boolean returnSuccessAuthenticatedContent, boolean testRedirect, boolean testBinary, - boolean testMissingLength) throws Exception { + boolean testMissingLength) throws IOException { transport = new MockTransport(testServerError, testAuthenticationError, testRedirect, @@ -540,7 +540,7 @@ public void testQueueDatastructures() throws Exception { assertEquals(METHOD2, requestInfos.get(1).request.getRequestMethod()); } - public void testExecute() throws Exception { + public void testExecute() throws IOException { BatchRequest batchRequest = getBatchPopulatedWithRequests(false, false, false, false, false, false); batchRequest.execute(); @@ -552,7 +552,7 @@ public void testExecute() throws Exception { assertTrue(batchRequest.requestInfos.isEmpty()); } - public void testExecuteWithError() throws Exception { + public void testExecuteWithError() throws IOException { BatchRequest batchRequest = getBatchPopulatedWithRequests(true, false, false, false, false, false); batchRequest.execute(); @@ -582,7 +582,7 @@ public void testExecuteWithVoidCallbackError() throws Exception { assertEquals(1, callback3.failureCalls); } - public void subTestExecuteWithVoidCallback(boolean testServerError) throws Exception { + public void subTestExecuteWithVoidCallback(boolean testServerError) throws IOException { MockTransport transport = new MockTransport(testServerError, false,false, false, false); MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, null, null).setApplicationName("Test Application") @@ -661,29 +661,34 @@ public void testExecute_checkWriteTo() throws Exception { String request2Method = HttpMethods.GET; String request2Url = "http://test/dummy/url2"; - - final StringBuilder expectedOutput = new StringBuilder(); - expectedOutput.append("--__END_OF_PART__\r\n"); - expectedOutput.append("Content-Length: 118\r\n"); - expectedOutput.append("Content-Type: application/http\r\n"); - expectedOutput.append("content-id: 1\r\n"); - expectedOutput.append("content-transfer-encoding: binary\r\n"); - expectedOutput.append("\r\n"); - expectedOutput.append("POST http://test/dummy/url1 HTTP/1.1\r\n"); - expectedOutput.append("Content-Length: 26\r\n"); - expectedOutput.append("Content-Type: " + request1ContentType + "\r\n"); - expectedOutput.append("\r\n"); - expectedOutput.append(request1Content + "\r\n"); - expectedOutput.append("--__END_OF_PART__\r\n"); - expectedOutput.append("Content-Length: 39\r\n"); - expectedOutput.append("Content-Type: application/http\r\n"); - expectedOutput.append("content-id: 2\r\n"); - expectedOutput.append("content-transfer-encoding: binary\r\n"); - expectedOutput.append("\r\n"); - expectedOutput.append("GET http://test/dummy/url2 HTTP/1.1\r\n"); - expectedOutput.append("\r\n"); - expectedOutput.append("\r\n"); - expectedOutput.append("--__END_OF_PART__--\r\n"); + + // MIME content boundaries are not reproducible. + StringBuilder part1 = new StringBuilder(); + part1.append("Content-Length: 118\r\n"); + part1.append("Content-Type: application/http\r\n"); + part1.append("content-id: 1\r\n"); + part1.append("content-transfer-encoding: binary\r\n"); + part1.append("\r\n"); + part1.append("POST http://test/dummy/url1 HTTP/1.1\r\n"); + part1.append("Content-Length: 26\r\n"); + part1.append("Content-Type: " + request1ContentType + "\r\n"); + part1.append("\r\n"); + part1.append(request1Content + "\r\n"); + part1.append("--__END_OF_PART__"); + String expected1 = part1.toString(); + + StringBuilder part2 = new StringBuilder(); + part2.append("Content-Length: 39\r\n"); + part2.append("Content-Type: application/http\r\n"); + part2.append("content-id: 2\r\n"); + part2.append("content-transfer-encoding: binary\r\n"); + part2.append("\r\n"); + part2.append("GET http://test/dummy/url2 HTTP/1.1\r\n"); + part2.append("\r\n"); + part2.append("\r\n"); + part2.append("--__END_OF_PART__"); + String expected2 = part2.toString(); + MockHttpTransport transport = new MockHttpTransport(); HttpRequest request1 = transport @@ -694,11 +699,11 @@ public void testExecute_checkWriteTo() throws Exception { new ByteArrayContent(request1ContentType, request1Content.getBytes(UTF_8))); HttpRequest request2 = transport.createRequestFactory() .buildRequest(request2Method, new GenericUrl(request2Url), null); - subtestExecute_checkWriteTo(expectedOutput.toString(), request1, request2); + subtestExecute_checkWriteTo(expected1, expected2, request1, request2); } - private void subtestExecute_checkWriteTo(final String expectedOutput, HttpRequest... requests) - throws IOException { + private void subtestExecute_checkWriteTo( + final String part1, final String part2, HttpRequest... requests) throws IOException { MockHttpTransport transport = new MockHttpTransport() { @@ -708,10 +713,12 @@ public LowLevelHttpRequest buildRequest(String method, String url) { @Override public LowLevelHttpResponse execute() throws IOException { - assertEquals("multipart/mixed; boundary=__END_OF_PART__", getContentType()); + assertTrue(getContentType().startsWith("multipart/mixed; boundary=__END_OF_PART__")); ByteArrayOutputStream out = new ByteArrayOutputStream(); getStreamingContent().writeTo(out); - assertEquals(expectedOutput, out.toString("UTF-8")); + String actual = out.toString("UTF-8"); + assertTrue(actual + "\n does not contain \n" + part1, actual.contains(part1)); + assertTrue(actual.contains(part2)); MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); response.setStatusCode(200); response.addHeader("Content-Type", "multipart/mixed; boundary=" + RESPONSE_BOUNDARY); @@ -748,9 +755,9 @@ public void onFailure(Void e, HttpHeaders responseHeaders) { batchRequest.execute(); } - public void testExecute_checkWriteToNoHeaders() throws Exception { + public void testExecute_checkWriteToNoHeaders() throws IOException { MockHttpTransport transport = new MockHttpTransport(); - HttpRequest request1 = transport.createRequestFactory() + HttpRequest request = transport.createRequestFactory() .buildPostRequest(HttpTesting.SIMPLE_GENERIC_URL, new HttpContent() { @Override @@ -772,14 +779,15 @@ public boolean retrySupported() { return true; } }); - subtestExecute_checkWriteTo(new StringBuilder().append("--__END_OF_PART__\r\n") - .append("Content-Length: 36\r\n").append("Content-Type: application/http\r\n") - .append("content-id: 1\r\n").append("content-transfer-encoding: binary\r\n").append("\r\n") - .append("POST http://google.com/ HTTP/1.1\r\n").append("\r\n").append("\r\n") - .append("--__END_OF_PART__--\r\n").toString(), request1); + String expected = new StringBuilder() + .append("Content-Length: 36\r\n").append("Content-Type: application/http\r\n") + .append("content-id: 1\r\n").append("content-transfer-encoding: binary\r\n").append("\r\n") + .append("POST http://google.com/ HTTP/1.1\r\n").append("\r\n").append("\r\n") + .append("--__END_OF_PART__").toString(); + subtestExecute_checkWriteTo(expected, expected, request); } - public void testProtoExecute() throws Exception { + public void testProtoExecute() throws IOException { BatchRequest batchRequest = getBatchPopulatedWithRequests(false, false, false, false, true, false); batchRequest.execute(); @@ -791,7 +799,7 @@ public void testProtoExecute() throws Exception { assertTrue(batchRequest.requestInfos.isEmpty()); } - public void testProtoExecuteWithError() throws Exception { + public void testProtoExecuteWithError() throws IOException { BatchRequest batchRequest = getBatchPopulatedWithRequests(true, false, false, false, true, false); batchRequest.execute(); @@ -805,7 +813,7 @@ public void testProtoExecuteWithError() throws Exception { assertEquals(1, transport.actualCalls); } - public void testProtoExecuteWithoutLength() throws Exception { + public void testProtoExecuteWithoutLength() throws IOException { BatchRequest batchRequest = getBatchPopulatedWithRequests(false, false, false, false, true, true); batchRequest.execute(); diff --git a/pom.xml b/pom.xml index e0d22f6b3..606b82b9e 100644 --- a/pom.xml +++ b/pom.xml @@ -121,11 +121,6 @@ <artifactId>xpp3</artifactId> <version>${project.xpp3.version}</version> </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <version>${project.httpclient.version}</version> - </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> @@ -480,10 +475,9 @@ - google-oauth-java-client/google-oauth-client-assembly/android-properties (make the filenames match the version here) - google-http-java-client/pom.xml (versions must match) - google-http-java-client/google-http-client-assembly/android-properties (make the filenames match the version here) - - Internally, update the default features.json file --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.http.version>1.34.0</project.http.version> + <project.http.version>1.34.1</project.http.version> <project.oauth.version>1.30.5</project.oauth.version> <project.jsr305.version>3.0.2</project.jsr305.version> <project.gson.version>2.8.6</project.gson.version> @@ -491,8 +485,6 @@ <project.guava.version>28.2-android</project.guava.version> <project.appengine.version>1.9.77</project.appengine.version> <project.xpp3.version>1.1.4c</project.xpp3.version> - <project.httpclient.version>4.5.10</project.httpclient.version> - <project.httpcore.version>4.4.12</project.httpcore.version> <project.jdo2-api.version>2.3-eb</project.jdo2-api.version> <project.datanucleus-core.version>3.2.2</project.datanucleus-core.version> <project.datanucleus-api-jdo.version>3.2.1</project.datanucleus-api-jdo.version>