Search in sources :

Example 41 with HttpResponseCallback

use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.

the class BraintreeGraphQLHttpClientTest method getRequestBadCertificateCheck.

@Test(timeout = 5000)
public void getRequestBadCertificateCheck() throws InterruptedException, InvalidArgumentException {
    if (!BuildConfig.RUN_ALL_TESTS) {
        return;
    }
    String baseUrl = "https://" + EnvironmentHelper.getLocalhostIp() + ":9443";
    BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, TOKENIZATION_KEY);
    httpClient.get("/", new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            fail("Request was successful");
            mCountDownLatch.countDown();
        }

        @Override
        public void failure(Exception exception) {
            assertEquals("java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.", exception.getMessage());
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) SSLException(javax.net.ssl.SSLException) Test(org.junit.Test)

Example 42 with HttpResponseCallback

use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.

the class BraintreeHttpClientTest method getRequestSslCertificateSuccessfulInSandbox.

@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInSandbox() throws InterruptedException, InvalidArgumentException {
    BraintreeHttpClient httpClient = new BraintreeHttpClient(TokenizationKey.fromString(TOKENIZATION_KEY));
    httpClient.setBaseUrl("https://api.sandbox.braintreegateway.com");
    httpClient.get("/", new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            fail("Request failed");
        }

        @Override
        public void failure(Exception exception) {
            assertTrue(exception instanceof AuthorizationException);
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 43 with HttpResponseCallback

use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.

the class BraintreeHttpClientTest method getRequestSslCertificateSuccessfulInProduction.

@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInProduction() throws InterruptedException, InvalidArgumentException {
    BraintreeHttpClient httpClient = new BraintreeHttpClient(TokenizationKey.fromString(TOKENIZATION_KEY));
    httpClient.setBaseUrl("https://api.braintreegateway.com");
    httpClient.get("/", new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            fail("Request failed");
        }

        @Override
        public void failure(Exception exception) {
            assertTrue(exception instanceof AuthorizationException);
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 44 with HttpResponseCallback

use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.

the class BraintreeHttpClientTest method postsErrorWhenBaseUrlIsNotSet.

@Test(timeout = 1000)
public void postsErrorWhenBaseUrlIsNotSet() throws InterruptedException, IOException, InvalidArgumentException {
    BraintreeHttpClient httpClient = new BraintreeHttpClient(TokenizationKey.fromString(TOKENIZATION_KEY));
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    httpClient.get("/", new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            fail("Request was successful");
        }

        @Override
        public void failure(Exception exception) {
            assertEquals(MalformedURLException.class, exception.getClass());
            countDownLatch.countDown();
        }
    });
    httpClient.post("/", "{}", new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            fail("Request was successful");
        }

        @Override
        public void failure(Exception exception) {
            assertEquals(MalformedURLException.class, exception.getClass());
            countDownLatch.countDown();
        }
    });
    countDownLatch.await();
}
Also used : MalformedURLException(java.net.MalformedURLException) CountDownLatch(java.util.concurrent.CountDownLatch) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 45 with HttpResponseCallback

use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.

the class BraintreeHttpClientTest method postsErrorWhenClientTokenIsUsedAndInvalidJsonIsSent.

@Test(timeout = 1000)
public void postsErrorWhenClientTokenIsUsedAndInvalidJsonIsSent() throws InvalidArgumentException, InterruptedException {
    BraintreeHttpClient httpClient = new BraintreeHttpClient(Authorization.fromString(stringFromFixture("client_token.json")));
    httpClient.post("/", "not json", new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            fail("Request was successful");
        }

        @Override
        public void failure(Exception exception) {
            assertTrue(exception instanceof JSONException);
            assertEquals("Value not of type java.lang.String cannot be converted to JSONObject", exception.getMessage());
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : JSONException(org.json.JSONException) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Aggregations

HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)54 Test (org.junit.Test)36 JSONException (org.json.JSONException)26 IOException (java.io.IOException)22 JSONObject (org.json.JSONObject)22 InvocationOnMock (org.mockito.invocation.InvocationOnMock)20 Answer (org.mockito.stubbing.Answer)20 CountDownLatch (java.util.concurrent.CountDownLatch)18 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)16 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)14 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 Configuration (com.braintreepayments.api.models.Configuration)13 MalformedURLException (java.net.MalformedURLException)11 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)10 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)10 IdealBank (com.braintreepayments.api.models.IdealBank)9 Matchers.anyString (org.mockito.Matchers.anyString)8 List (java.util.List)7 SSLException (javax.net.ssl.SSLException)7