use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project copybara by google.
the class GithubArchiveTest method setup.
@Before
public void setup() throws IOException {
httpTransport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) {
String requestString = method + " " + url;
MockLowLevelHttpRequest request = new MockLowLevelHttpRequest();
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
request.setResponse(response);
response.setStatusCode(200);
response.setContent(responseContent);
if (!url.equals(expectedRequest)) {
response.setStatusCode(404);
response.setContent(String.format("UNEXPECTED REQUEST (Returning 404) REQUEST: %s, expected: %s", requestString, expectedRequest));
}
return request;
}
};
RemoteFileOptions options = new RemoteFileOptions();
options.transport = () -> new GclientHttpStreamFactory(httpTransport, Duration.ofSeconds(20));
Console console = new TestingConsole();
OptionsBuilder optionsBuilder = new OptionsBuilder().setConsole(console);
optionsBuilder.remoteFile = options;
skylark = new SkylarkTestExecutor(optionsBuilder);
}
use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project endpoints-java by cloudendpoints.
the class GoogleAuthTest method constructHttpRequest.
private HttpRequest constructHttpRequest(final String content, final int statusCode) 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);
result.setStatusCode(statusCode);
return result;
}
};
}
};
HttpRequest httpRequest = transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com")).setParser(new JsonObjectParser(new JacksonFactory()));
GoogleAuth.configureErrorHandling(httpRequest);
return httpRequest;
}
use of com.google.api.client.testing.http.MockLowLevelHttpResponse in project tink by google.
the class PaymentMethodTokenRecipientTest method testShouldDecryptECV1WhenFetchingSenderVerifyingKeys.
@Test
public void testShouldDecryptECV1WhenFetchingSenderVerifyingKeys() throws Exception {
PaymentMethodTokenRecipient recipient = new PaymentMethodTokenRecipient.Builder().fetchSenderVerifyingKeysWith(new GooglePaymentsPublicKeysManager.Builder().setHttpTransport(new MockHttpTransport.Builder().setLowLevelHttpResponse(new MockLowLevelHttpResponse().setContent(GOOGLE_VERIFYING_PUBLIC_KEYS_JSON)).build()).build()).recipientId(RECIPIENT_ID).addRecipientPrivateKey(MERCHANT_PRIVATE_KEY_PKCS8_BASE64).build();
assertEquals(PLAINTEXT, recipient.unseal(CIPHERTEXT_EC_V1));
}
Aggregations