use of com.google.api.client.http.ByteArrayContent in project googleads-java-lib by googleads.
the class BatchJobUploaderTest method testUploadIncrementalBatchJobOperations_logging.
@Test
public void testUploadIncrementalBatchJobOperations_logging() throws Exception {
BatchJobUploadStatus status = new BatchJobUploadStatus(10, URI.create(mockHttpServer.getServerUrl()));
String uploadRequestBody = "<mutate>testUpload</mutate>";
when(uploadBodyProvider.getHttpContent(request, false, true)).thenReturn(new ByteArrayContent(null, uploadRequestBody.getBytes(UTF_8)));
mockHttpServer.setMockResponse(new MockResponse("testUploadResponse"));
String expectedBody = "testUpload</mutate>";
expectedBody = Strings.padEnd(expectedBody, BatchJobUploader.REQUIRED_CONTENT_LENGTH_INCREMENT, ' ');
// Invoke the incremental upload method.
BatchJobUploadResponse response = uploader.uploadIncrementalBatchJobOperations(request, true, status);
verify(batchJobLogger, times(1)).logUpload(expectedBody, status.getResumableUploadUri(), response, null);
}
use of com.google.api.client.http.ByteArrayContent in project googleads-java-lib by googleads.
the class BatchJobUploaderTest method testUploadIncrementalBatchJobOperations_notFirst_notLast.
@Test
public void testUploadIncrementalBatchJobOperations_notFirst_notLast() throws Exception {
BatchJobUploadStatus status = new BatchJobUploadStatus(10, URI.create(mockHttpServer.getServerUrl()));
String uploadRequestBody = "<mutate>testUpload</mutate>";
when(uploadBodyProvider.getHttpContent(request, false, false)).thenReturn(new ByteArrayContent(null, uploadRequestBody.getBytes(UTF_8)));
mockHttpServer.setMockResponse(new MockResponse("testUploadResponse"));
// Invoked the incremental upload method.
BatchJobUploadResponse response = uploader.uploadIncrementalBatchJobOperations(request, false, status);
assertEquals("Should have made one request", 1, mockHttpServer.getAllResponses().size());
// Check the request.
String firstRequest = mockHttpServer.getLastResponse().getRequestBody();
String expectedBody = "testUpload";
expectedBody = Strings.padEnd(expectedBody, BatchJobUploader.REQUIRED_CONTENT_LENGTH_INCREMENT, ' ');
assertEquals("Request body is incorrect", expectedBody, firstRequest);
assertEquals("Request should have succeeded", 200, response.getHttpStatus());
// Check the BatchJobUploadStatus.
BatchJobUploadStatus expectedStatus = new BatchJobUploadStatus(status.getTotalContentLength() + expectedBody.getBytes(UTF_8).length, URI.create(mockHttpServer.getServerUrl()));
BatchJobUploadStatus actualStatus = response.getBatchJobUploadStatus();
assertEquals("Status total content length is incorrect", expectedStatus.getTotalContentLength(), actualStatus.getTotalContentLength());
assertEquals("Status resumable upload URI is incorrect", expectedStatus.getResumableUploadUri(), actualStatus.getResumableUploadUri());
}
use of com.google.api.client.http.ByteArrayContent in project data-transfer-project by google.
the class GoogleVideosInterface method uploadVideoContent.
String uploadVideoContent(InputStream inputStream, String filename) throws IOException {
InputStreamContent content = new InputStreamContent(null, inputStream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
content.writeTo(outputStream);
byte[] contentBytes = outputStream.toByteArray();
HttpContent httpContent = new ByteArrayContent(null, contentBytes);
return makePostRequest(BASE_URL + "uploads/", Optional.empty(), httpContent, String.class);
}
Aggregations