Search in sources :

Example 61 with Configuration

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

the class ConfigurationManagerUnitTest method getConfiguration_getsConfigFromGatewayWhenTimeoutExpired.

@Test(timeout = 1000)
public void getConfiguration_getsConfigFromGatewayWhenTimeoutExpired() throws InterruptedException {
    writeMockConfiguration(RuntimeEnvironment.application, mTokenizationKey.getConfigUrl(), mTokenizationKey.getBearer(), stringFromFixture("configuration/configuration.json"), System.currentTimeMillis() - (ConfigurationManager.TTL + 1));
    stubConfigurationFromGateway(stringFromFixture("configuration/with_analytics.json"));
    ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            assertEquals(stringFromFixture("configuration/with_analytics.json"), configuration.toJson());
            mCountDownLatch.countDown();
        }
    }, new BraintreeResponseListener<Exception>() {

        @Override
        public void onResponse(Exception e) {
            fail(e.getMessage());
        }
    });
    mCountDownLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) SharedPreferencesHelper.writeMockConfiguration(com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration) Configuration(com.braintreepayments.api.models.Configuration) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 62 with Configuration

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

the class ConfigurationManagerUnitTest method isFetchingConfiguration_isFalseInSuccessCallback.

@Test(timeout = 1000)
public void isFetchingConfiguration_isFalseInSuccessCallback() throws InterruptedException {
    stubConfigurationFromGateway(stringFromFixture("configuration/with_analytics.json"));
    ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            assertFalse(ConfigurationManager.isFetchingConfiguration());
            mCountDownLatch.countDown();
        }
    }, new BraintreeResponseListener<Exception>() {

        @Override
        public void onResponse(Exception e) {
            fail(e.getMessage());
        }
    });
    mCountDownLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) SharedPreferencesHelper.writeMockConfiguration(com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration) Configuration(com.braintreepayments.api.models.Configuration) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 63 with Configuration

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

the class ConfigurationManagerUnitTest method getConfiguration_fetchesConfigFromGatewayWhenCacheIsEmpty.

@Test(timeout = 1000)
public void getConfiguration_fetchesConfigFromGatewayWhenCacheIsEmpty() throws InterruptedException {
    stubConfigurationFromGateway(stringFromFixture("configuration/with_analytics.json"));
    ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            assertEquals(stringFromFixture("configuration/with_analytics.json"), configuration.toJson());
            mCountDownLatch.countDown();
        }
    }, new BraintreeResponseListener<Exception>() {

        @Override
        public void onResponse(Exception e) {
            fail(e.getMessage());
        }
    });
    mCountDownLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) SharedPreferencesHelper.writeMockConfiguration(com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration) Configuration(com.braintreepayments.api.models.Configuration) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 64 with Configuration

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

the class VenmoUnitTest method performAppSwitch_whenProfileIdIsNull_appSwitchesWithMerchantId.

@Test
public void performAppSwitch_whenProfileIdIsNull_appSwitchesWithMerchantId() throws InvalidArgumentException, JSONException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).authorization(clientToken).configuration(configuration).build();
    when(fragment.getSessionId()).thenReturn("a-session-id");
    when(fragment.getIntegrationType()).thenReturn("custom");
    Venmo.authorizeAccount(fragment, false, null);
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).startActivityForResult(captor.capture(), eq(BraintreeRequestCodes.VENMO));
    assertEquals("com.venmo/com.venmo.controller.SetupMerchantActivity", captor.getValue().getComponent().flattenToString());
    Bundle extras = captor.getValue().getExtras();
    assertEquals("merchant-id", extras.getString(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", extras.getString(Venmo.EXTRA_ACCESS_TOKEN));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) Bundle(android.os.Bundle) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 65 with Configuration

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

the class VenmoUnitTest method performAppSwitch_persistsIfVaultFalse.

@Test
public void performAppSwitch_persistsIfVaultFalse() throws InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(clientToken).build();
    Venmo.authorizeAccount(fragment, false);
    SharedPreferences prefs = SharedPreferencesHelper.getSharedPreferences(fragment.getApplicationContext());
    assertFalse(prefs.getBoolean("com.braintreepayments.api.Venmo.VAULT_VENMO_KEY", true));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) SharedPreferencesHelper.clearSharedPreferences(com.braintreepayments.testutils.SharedPreferencesHelper.clearSharedPreferences) SharedPreferences(android.content.SharedPreferences) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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