use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.
the class CommonGoogleProtoClientRequestInitializerTest method testInitialize.
public void testInitialize() throws Exception {
CommonGoogleProtoClientRequestInitializer key = new CommonGoogleProtoClientRequestInitializer("foo");
MockGoogleProtoClient client = new MockGoogleProtoClient.Builder(new MockHttpTransport(), HttpTesting.SIMPLE_URL, "test/", null).setApplicationName("Test Application").build();
MyRequest request = new MyRequest(client, "GET", "", null, String.class);
assertNull(request.key);
key.initialize(request);
assertEquals("foo", request.key);
}
use of com.google.api.client.testing.http.MockHttpTransport in project endpoints-java by cloudendpoints.
the class GoogleAuthTest method constructHttpRequest.
private HttpRequest constructHttpRequest(final String content) throws IOException {
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
result.setContentType("application/json");
result.setContent(content);
return result;
}
};
}
};
return transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com")).setParser(new JsonObjectParser(new JacksonFactory()));
}
use of com.google.api.client.testing.http.MockHttpTransport in project components by Talend.
the class GoogleDriveCredentialWithInstalledApplicationTest method testBuilder.
@Test
public void testBuilder() {
GoogleAuthorizationCodeFlow.Builder builder = new GoogleAuthorizationCodeFlow.Builder(new MockHttpTransport(), new JacksonFactory(), CLIENT_ID, CLIENT_SECRET, ImmutableList.of("https://www.googleapis.com/auth/userinfo.email"));
assertNull(builder.getApprovalPrompt());
assertNull(builder.getAccessType());
}
use of com.google.api.client.testing.http.MockHttpTransport in project ddf by codice.
the class PaosInInterceptorTest method getHttpUnsuccessfulResponseHandlerHeaderTest.
@Test
public void getHttpUnsuccessfulResponseHandlerHeaderTest() throws IOException {
Message message = new MessageImpl();
message.put(Message.HTTP_REQUEST_METHOD, "GET");
HashMap<String, List> protocolHeaders = new HashMap<>();
message.put(Message.PROTOCOL_HEADERS, protocolHeaders);
protocolHeaders.put("X-Custom-Header", Collections.singletonList("Custom"));
PaosInInterceptor paosInInterceptor = spy(new PaosInInterceptor(Phase.RECEIVE, new SamlSecurity()));
doReturn(true).when(paosInInterceptor).isRedirect(any(HttpRequest.class), any(HttpResponse.class), any(String.class));
GenericUrl url = new GenericUrl("https://localhost:8993/PAOSConsumer");
HttpRequest request = new MockHttpTransport().createRequestFactory().buildGetRequest(url);
request.getUrl().set("url", "https://localhost:8993/PAOSConsumer");
// Using request.execute to create an HttpResponse since it's final and cannot be mocked
HttpResponse response = request.execute();
response.getHeaders().setLocation("https://localhost:8993/PAOSConsumer");
response.getHeaders().set("set-cookie", Collections.singletonList("cookie"));
HttpUnsuccessfulResponseHandler responseHandler = paosInInterceptor.getHttpUnsuccessfulResponseHandler(message);
boolean returned = responseHandler.handleResponse(request, response, true);
assertThat(returned, is(true));
// HttpHeaders ignores header case
assertThat(request.getHeaders().containsKey("x-custom-header"), is(true));
assertThat(request.getHeaders().get("x-custom-header"), is(Collections.singletonList("Custom")));
}
use of com.google.api.client.testing.http.MockHttpTransport in project beam by apache.
the class GcsUtilTest method testFileSizeWhenFileNotFoundNonBatch.
@Test
public void testFileSizeWhenFileNotFoundNonBatch() throws Exception {
MockLowLevelHttpResponse notFoundResponse = new MockLowLevelHttpResponse();
notFoundResponse.setContent("");
notFoundResponse.setStatusCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
MockHttpTransport mockTransport = new MockHttpTransport.Builder().setLowLevelHttpResponse(notFoundResponse).build();
GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
GcsUtil gcsUtil = pipelineOptions.getGcsUtil();
gcsUtil.setStorageClient(new Storage(mockTransport, Transport.getJsonFactory(), null));
thrown.expect(FileNotFoundException.class);
gcsUtil.fileSize(GcsPath.fromComponents("testbucket", "testobject"));
}
Aggregations