use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project beam by apache.
the class UploadIdResponseInterceptorTest method buildHttpResponse.
/**
* Builds an HttpResponse with the given string response.
*
* @param header header value to provide or null if none.
* @param uploadId upload id to provide in the url upload id param or null if none.
* @param uploadType upload type to provide in url upload type param or null if none.
* @return HttpResponse with the given parameters
* @throws IOException
*/
private HttpResponse buildHttpResponse(String header, String uploadId, String uploadType) throws IOException {
MockHttpTransport.Builder builder = new MockHttpTransport.Builder();
MockLowLevelHttpResponse resp = new MockLowLevelHttpResponse();
builder.setLowLevelHttpResponse(resp);
resp.setStatusCode(200);
GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL);
if (header != null) {
resp.addHeader("X-GUploader-UploadID", header);
}
if (uploadId != null) {
url.put("upload_id", uploadId);
}
if (uploadType != null) {
url.put("uploadType", uploadType);
}
return builder.build().createRequestFactory().buildGetRequest(url).execute();
}
use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project beam by apache.
the class DataflowWorkUnitClientTest method generateMockResponse.
private LowLevelHttpResponse generateMockResponse(WorkItem... workItems) throws Exception {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setContentType(Json.MEDIA_TYPE);
LeaseWorkItemResponse lease = new LeaseWorkItemResponse();
lease.setWorkItems(Lists.newArrayList(workItems));
// N.B. Setting the factory is necessary in order to get valid JSON.
lease.setFactory(Transport.getJsonFactory());
response.setContent(lease.toPrettyString());
return response;
}
use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project druid by druid-io.
the class GoogleStorageTest method testGet.
@Test
public void testGet() throws IOException {
String content = "abcdefghij";
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setContent(content);
GoogleStorage googleStorage = makeGoogleStorage(response);
InputStream is = googleStorage.get("bucket", "path");
String actual = GoogleTestUtils.readAsString(is);
Assert.assertEquals(content, actual);
}
use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project druid by druid-io.
the class GoogleStorageTest method testGetWithOffset.
@Test
public void testGetWithOffset() throws IOException {
String content = "abcdefghij";
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setContent(content);
GoogleStorage googleStorage = makeGoogleStorage(response);
InputStream is = googleStorage.get("bucket", "path", 2);
String actual = GoogleTestUtils.readAsString(is);
Assert.assertEquals(content.substring(2), actual);
}
use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project druid by druid-io.
the class GoogleStorageTest method testInsert.
@Test
public void testInsert() throws IOException {
String content = "abcdefghij";
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.addHeader("Location", "http://random-path");
response.setContent("{}");
MockHttpTransport transport = new MockHttpTransport.Builder().setLowLevelHttpResponse(response).build();
GoogleStorage googleStorage = makeGoogleStorage(transport);
googleStorage.insert("bucket", "path", new ByteArrayContent("text/html", StringUtils.toUtf8(content)));
MockLowLevelHttpRequest request = transport.getLowLevelHttpRequest();
String actual = request.getContentAsString();
Assert.assertEquals(content, actual);
}
Aggregations