Search in sources :

Example 26 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException 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 27 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException 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 28 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException 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)

Example 29 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.

the class BraintreeHttpClientTest method postsErrorWhenPathIsNull.

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

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

        @Override
        public void failure(Exception exception) {
            assertEquals(IllegalArgumentException.class, exception.getClass());
            assertEquals("Path cannot be null", exception.getMessage());
            countDownLatch.countDown();
        }
    });
    httpClient.post(null, "{}", new HttpResponseCallback() {

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

        @Override
        public void failure(Exception exception) {
            assertEquals(IllegalArgumentException.class, exception.getClass());
            assertEquals("Path cannot be null", exception.getMessage());
            countDownLatch.countDown();
        }
    });
    countDownLatch.await();
}
Also used : 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 30 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.

the class ThreeDSecureVerificationTest method getFragment.

private BraintreeFragment getFragment(String authorization, String configuration) {
    try {
        Authorization auth = Authorization.fromString(authorization);
        writeMockConfiguration(getTargetContext(), auth.getConfigUrl(), auth.getBearer(), configuration);
        BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, authorization);
        while (!fragment.isAdded()) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException ignored) {
            }
        }
        return fragment;
    } catch (InvalidArgumentException e) {
        fail(e.getMessage());
        return new BraintreeFragment();
    }
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException)

Aggregations

InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)31 Test (org.junit.Test)27 JSONException (org.json.JSONException)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)12 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)12 IOException (java.io.IOException)12 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)10 Configuration (com.braintreepayments.api.models.Configuration)7 MalformedURLException (java.net.MalformedURLException)6 Intent (android.content.Intent)4 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)4 Authorization (com.braintreepayments.api.models.Authorization)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)3 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)3 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)3 IdealBank (com.braintreepayments.api.models.IdealBank)3 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)3 List (java.util.List)3