Search in sources :

Example 26 with ConfigurationListener

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

the class MockFragmentBuilder method build.

public BraintreeFragment build() {
    BraintreeFragment fragment = mock(BraintreeFragment.class);
    when(fragment.getApplicationContext()).thenReturn(mContext);
    when(fragment.getAuthorization()).thenReturn(mAuthorization);
    when(fragment.getSessionId()).thenReturn(mSessionId);
    when(fragment.getReturnUrlScheme()).thenReturn("com.braintreepayments.api.braintree");
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((ConfigurationListener) invocation.getArguments()[0]).onConfigurationFetched(mConfiguration);
            return null;
        }
    }).when(fragment).waitForConfiguration(any(ConfigurationListener.class));
    when(fragment.getConfiguration()).thenReturn(mConfiguration);
    BraintreeHttpClient httpClient = mock(BraintreeHttpClient.class);
    if (mSuccessResponse != null) {
        setupSuccessResponses(httpClient);
    } else if (mErrorResponse != null) {
        setupErrorResponses(httpClient);
    }
    when(fragment.getHttpClient()).thenReturn(httpClient);
    BraintreeGraphQLHttpClient graphQLHttpClient = mock(BraintreeGraphQLHttpClient.class);
    if (mGraphQLSuccessResponse != null) {
        setupGraphQLSuccessResponses(graphQLHttpClient);
    } else if (mGraphQLErrorResponse != null) {
        setupGraphQLErrorResponses(graphQLHttpClient);
    }
    when(fragment.getGraphQLHttpClient()).thenReturn(graphQLHttpClient);
    return fragment;
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) BraintreeGraphQLHttpClient(com.braintreepayments.api.internal.BraintreeGraphQLHttpClient) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient)

Example 27 with ConfigurationListener

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

the class BraintreeFragmentTest method fetchConfiguration_worksWithATokenizationKey.

@Test(timeout = 10000)
public void fetchConfiguration_worksWithATokenizationKey() throws InterruptedException {
    final BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, TOKENIZATION_KEY);
    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 28 with ConfigurationListener

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

the class GooglePaymentTest method getTokenizationParameters_returnsCorrectParameters.

@Test(timeout = 5000)
public void getTokenizationParameters_returnsCorrectParameters() throws Exception {
    String config = mBaseConfiguration.withAnalytics().build();
    final BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, config);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            Bundle tokenizationParameters = GooglePayment.getTokenizationParameters(fragment).getParameters();
            assertEquals("braintree", tokenizationParameters.getString("gateway"));
            assertEquals(configuration.getMerchantId(), tokenizationParameters.getString("braintree:merchantId"));
            assertEquals(configuration.getAndroidPay().getGoogleAuthorizationFingerprint(), tokenizationParameters.getString("braintree:authorizationFingerprint"));
            assertEquals("v1", tokenizationParameters.getString("braintree:apiVersion"));
            assertEquals(BuildConfig.VERSION_NAME, tokenizationParameters.getString("braintree:sdkVersion"));
            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) Bundle(android.os.Bundle) Test(org.junit.Test)

Example 29 with ConfigurationListener

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

the class GooglePaymentTest method getTokenizationParameters_doesNotIncludeATokenizationKeyWhenNotPresent.

@Test(timeout = 5000)
public void getTokenizationParameters_doesNotIncludeATokenizationKeyWhenNotPresent() throws Exception {
    final BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), stringFromFixture("client_token.json"), mBaseConfiguration.build());
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            Bundle tokenizationParameters = GooglePayment.getTokenizationParameters(fragment).getParameters();
            assertNull(tokenizationParameters.getString("braintree:clientKey"));
            mLatch.countDown();
        }
    });
    mLatch.countDown();
}
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) Bundle(android.os.Bundle) Test(org.junit.Test)

Example 30 with ConfigurationListener

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

the class DataCollector method startDeviceCollector.

private static void startDeviceCollector(final BraintreeFragment fragment, final String merchantId, final String deviceSessionId, @Nullable final BraintreeResponseListener<String> listener) throws ClassNotFoundException, NumberFormatException {
    fragment.sendAnalyticsEvent("data-collector.kount.started");
    Class.forName(com.kount.api.DataCollector.class.getName());
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            final com.kount.api.DataCollector dataCollector = com.kount.api.DataCollector.getInstance();
            dataCollector.setContext(fragment.getApplicationContext());
            dataCollector.setMerchantID(Integer.parseInt(merchantId));
            dataCollector.setLocationCollectorConfig(com.kount.api.DataCollector.LocationConfig.COLLECT);
            dataCollector.setEnvironment(getDeviceCollectorEnvironment(configuration.getEnvironment()));
            dataCollector.collectForSession(deviceSessionId, new com.kount.api.DataCollector.CompletionHandler() {

                @Override
                public void completed(String sessionID) {
                    fragment.sendAnalyticsEvent("data-collector.kount.succeeded");
                    if (listener != null) {
                        listener.onResponse(sessionID);
                    }
                }

                @Override
                public void failed(String sessionID, final com.kount.api.DataCollector.Error error) {
                    fragment.sendAnalyticsEvent("data-collector.kount.failed");
                    if (listener != null) {
                        listener.onResponse(sessionID);
                    }
                }
            });
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) PayPalDataCollector(com.paypal.android.sdk.data.collector.PayPalDataCollector)

Aggregations

ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)37 Configuration (com.braintreepayments.api.models.Configuration)36 Test (org.junit.Test)21 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)15 JSONException (org.json.JSONException)12 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)10 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)10 SharedPreferencesHelper.writeMockConfiguration (com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration)10 ConfigurationException (com.braintreepayments.api.exceptions.ConfigurationException)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 BraintreeFragmentTestUtils.getFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration)4 BraintreeFragmentTestUtils.getMockFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration)4 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)4 BraintreeHttpClient (com.braintreepayments.api.internal.BraintreeHttpClient)4 JSONObject (org.json.JSONObject)4 Bundle (android.os.Bundle)3 Intent (android.content.Intent)2 BraintreeResponseListener (com.braintreepayments.api.interfaces.BraintreeResponseListener)2 UnionPayConfiguration (com.braintreepayments.api.models.UnionPayConfiguration)2 Uri (android.net.Uri)1