Search in sources :

Example 36 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class AnalyticsSenderTest method sendsCorrectlyFormattedAnalyticsRequest.

@Test(timeout = 10000)
public void sendsCorrectlyFormattedAnalyticsRequest() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    String authorization = new TestClientTokenBuilder().withAnalytics().build();
    final Configuration configuration = Configuration.fromJson(authorization);
    AnalyticsEvent event = new AnalyticsEvent(getTargetContext(), "sessionId", "custom", "event.started");
    AnalyticsDatabase.getInstance(getTargetContext()).addEvent(event);
    BraintreeHttpClient httpClient = new BraintreeHttpClient(Authorization.fromString(authorization)) {

        @Override
        protected String parseResponse(HttpURLConnection connection) throws Exception {
            if (connection.getURL().toString().equals(configuration.getAnalytics().getUrl())) {
                assertEquals(200, connection.getResponseCode());
                latch.countDown();
            }
            return "";
        }
    };
    AnalyticsSender.send(getTargetContext(), Authorization.fromString(authorization), httpClient, configuration.getAnalytics().getUrl(), true);
    latch.await();
}
Also used : TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) HttpURLConnection(java.net.HttpURLConnection) Configuration(com.braintreepayments.api.models.Configuration) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 37 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class AndroidPayTest method getTokenizationParameters_returnsCorrectParametersInCallback.

@Test(timeout = 5000)
public void getTokenizationParameters_returnsCorrectParametersInCallback() throws Exception {
    String config = mBaseConfiguration.androidPay(mBaseConfiguration.androidPay().supportedNetworks(new String[] { "visa", "mastercard", "amex", "discover" })).build();
    final Configuration configuration = Configuration.fromJson(config);
    BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, config);
    AndroidPay.getTokenizationParameters(fragment, new TokenizationParametersListener() {

        @Override
        public void onResult(PaymentMethodTokenizationParameters parameters, Collection<Integer> allowedCardNetworks) {
            assertEquals("braintree", parameters.getParameters().getString("gateway"));
            assertEquals(configuration.getMerchantId(), parameters.getParameters().getString("braintree:merchantId"));
            assertEquals(configuration.getAndroidPay().getGoogleAuthorizationFingerprint(), parameters.getParameters().getString("braintree:authorizationFingerprint"));
            assertEquals("v1", parameters.getParameters().getString("braintree:apiVersion"));
            assertEquals(BuildConfig.VERSION_NAME, parameters.getParameters().getString("braintree:sdkVersion"));
            try {
                JSONObject metadata = new JSONObject(parameters.getParameters().getString("braintree:metadata"));
                assertNotNull(metadata);
                assertEquals(BuildConfig.VERSION_NAME, metadata.getString("version"));
                assertNotNull(metadata.getString("sessionId"));
                assertEquals("custom", metadata.getString("integration"));
                assertEquals("android", metadata.get("platform"));
            } catch (JSONException e) {
                fail("Failed to unpack json from tokenization parameters: " + e.getMessage());
            }
            assertEquals(4, allowedCardNetworks.size());
            assertTrue(allowedCardNetworks.contains(CardNetwork.VISA));
            assertTrue(allowedCardNetworks.contains(CardNetwork.MASTERCARD));
            assertTrue(allowedCardNetworks.contains(CardNetwork.AMEX));
            assertTrue(allowedCardNetworks.contains(CardNetwork.DISCOVER));
            mLatch.countDown();
        }
    });
    mLatch.await();
}
Also used : BraintreeFragmentTestUtils.getMockFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) PaymentMethodTokenizationParameters(com.google.android.gms.wallet.PaymentMethodTokenizationParameters) JSONException(org.json.JSONException) TokenizationParametersListener(com.braintreepayments.api.interfaces.TokenizationParametersListener) Test(org.junit.Test)

Example 38 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class BraintreeFragmentTest method fetchConfiguration_worksWithAClientToken.

@Test(timeout = 10000)
public void fetchConfiguration_worksWithAClientToken() throws InterruptedException {
    final BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, mClientToken);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            assertNotNull(configuration);
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) Test(org.junit.Test)

Example 39 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class CardTest method setupBraintreeFragment.

private BraintreeFragment setupBraintreeFragment(String authorization) throws Exception {
    final BraintreeFragment fragment = BraintreeFragment.newInstance(mActivityTestRule.getActivity(), authorization);
    final CountDownLatch latch = new CountDownLatch(1);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            if (mRequestProtocol.equals(REST)) {
                try {
                    JSONObject configJson = new JSONObject(configuration.toJson());
                    configJson.remove("graphQL");
                    fragment.setConfiguration(Configuration.fromJson(configJson.toString()));
                } catch (JSONException ignored) {
                }
                assertFalse(fragment.getConfiguration().getGraphQL().isEnabled());
            } else if (mRequestProtocol.equals(GRAPHQL)) {
                assertTrue(configuration.getGraphQL().isEnabled());
            }
            latch.countDown();
        }
    });
    latch.await();
    return fragment;
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 40 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class GooglePaymentTest method getAllowedCardNetworks_returnsSupportedNetworks.

@Test(timeout = 5000)
public void getAllowedCardNetworks_returnsSupportedNetworks() throws InterruptedException {
    String configuration = mBaseConfiguration.androidPay(mBaseConfiguration.androidPay().supportedNetworks(new String[] { "visa", "mastercard", "amex", "discover" })).build();
    final BraintreeFragment fragment = getFragmentWithConfiguration(mActivityTestRule.getActivity(), configuration);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            Collection<Integer> allowedCardNetworks = GooglePayment.getAllowedCardNetworks(fragment);
            assertEquals(4, allowedCardNetworks.size());
            assertTrue(allowedCardNetworks.contains(CardNetwork.VISA));
            assertTrue(allowedCardNetworks.contains(CardNetwork.MASTERCARD));
            assertTrue(allowedCardNetworks.contains(CardNetwork.AMEX));
            assertTrue(allowedCardNetworks.contains(CardNetwork.DISCOVER));
            mLatch.countDown();
        }
    });
    mLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreeFragmentTestUtils.getFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration) BraintreeFragmentTestUtils.getMockFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration) Configuration(com.braintreepayments.api.models.Configuration) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

Configuration (com.braintreepayments.api.models.Configuration)84 Test (org.junit.Test)66 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)19 JSONException (org.json.JSONException)19 Authorization (com.braintreepayments.api.models.Authorization)14 Intent (android.content.Intent)13 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)13 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)12 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)11 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)11 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)11 JSONObject (org.json.JSONObject)11 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)10 SharedPreferencesHelper.writeMockConfiguration (com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration)10 Request (com.paypal.android.sdk.onetouch.core.Request)10 Bundle (android.os.Bundle)9 BraintreeFragmentTestUtils.getMockFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration)6 BraintreeFragmentTestUtils.getFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration)5