Search in sources :

Example 61 with MockLowLevelHttpResponse

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);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) Before(org.junit.Before)

Example 62 with MockLowLevelHttpResponse

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;
}
Also used : LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) HttpRequest(com.google.api.client.http.HttpRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) JsonObjectParser(com.google.api.client.json.JsonObjectParser) GenericUrl(com.google.api.client.http.GenericUrl) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest)

Example 63 with MockLowLevelHttpResponse

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));
}
Also used : MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) Test(org.junit.Test)

Aggregations

MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)63 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)40 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)38 Test (org.junit.Test)31 LowLevelHttpResponse (com.google.api.client.http.LowLevelHttpResponse)24 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)22 IOException (java.io.IOException)21 HttpTransport (com.google.api.client.http.HttpTransport)10 GenericJson (com.google.api.client.json.GenericJson)9 HttpResponse (com.google.api.client.http.HttpResponse)8 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)8 JsonFactory (com.google.api.client.json.JsonFactory)7 HttpRequest (com.google.api.client.http.HttpRequest)6 GenericUrl (com.google.api.client.http.GenericUrl)5 Objectify (com.googlecode.objectify.Objectify)5 Storage (com.google.api.services.storage.Storage)4 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)4 ErrorInfo (com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo)3 MockGoogleClient (com.google.api.client.googleapis.testing.services.MockGoogleClient)3 MockGoogleClientRequest (com.google.api.client.googleapis.testing.services.MockGoogleClientRequest)3