Search in sources :

Example 56 with Configuration

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

the class PayPalRequestUnitTest method getCheckoutRequest_buildsWithCustomStageUrl.

@Test
public void getCheckoutRequest_buildsWithCustomStageUrl() throws JSONException {
    Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_custom_paypal.json"));
    BraintreeFragment fragment = mMockFragmentBuilder.configuration(configuration).build();
    Request request = PayPal.getCheckoutRequest(fragment, null);
    assertEquals("custom", request.getEnvironment());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) Request(com.paypal.android.sdk.onetouch.core.Request) BillingAgreementRequest(com.paypal.android.sdk.onetouch.core.BillingAgreementRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Test(org.junit.Test)

Example 57 with Configuration

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

the class PayPalUnitTest method setup.

@Before
public void setup() throws Exception {
    spy(PayPal.class);
    doReturn(true).when(PayPal.class, "isManifestValid", any(Context.class));
    spy(Recipe.class);
    doReturn(true).when(Recipe.class, "isValidBrowserTarget", any(Context.class), anyString(), anyString());
    Authorization authorization = mock(Authorization.class);
    when(authorization.getBearer()).thenReturn("authorization");
    when(authorization.toString()).thenReturn("authorization");
    Configuration configuration = new TestConfigurationBuilder().withAnalytics().paypal(new TestPayPalConfigurationBuilder(true).environment("offline").billingAgreementsEnabled(false)).buildConfiguration();
    mMockFragmentBuilder = new MockFragmentBuilder().authorization(authorization).configuration(configuration);
}
Also used : Context(android.content.Context) Authorization(com.braintreepayments.api.models.Authorization) TestPayPalConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestPayPalConfigurationBuilder) Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Before(org.junit.Before)

Example 58 with Configuration

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

the class BraintreeFragmentUnitTest method waitForConfiguration_postsCallbackWhenFragmentIsAttached.

@Test
public void waitForConfiguration_postsCallbackWhenFragmentIsAttached() throws JSONException, InvalidArgumentException {
    final Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/configuration.json"));
    mockConfigurationManager(configuration);
    final BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration returnedConfiguration) {
            assertTrue(fragment.isAdded());
            mCalled.set(true);
        }
    });
    assertTrue(mCalled.get());
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 59 with Configuration

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

the class ConfigurationManagerUnitTest method getConfiguration_callsErrorListenerWhenHttpFails.

@Test(timeout = 1000)
public void getConfiguration_callsErrorListenerWhenHttpFails() throws InterruptedException {
    BraintreeHttpClient fakeClient = new BraintreeHttpClient(mTokenizationKey) {

        @Override
        public void get(String path, HttpResponseCallback callback) {
            if (path.contains(mTokenizationKey.getConfigUrl())) {
                callback.failure(new UnexpectedException("Something bad happened"));
            }
        }
    };
    when(mBraintreeFragment.getHttpClient()).thenReturn(fakeClient);
    ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            fail("Success listener should not have been called for bad request");
        }
    }, new BraintreeResponseListener<Exception>() {

        @Override
        public void onResponse(Exception e) {
            assertTrue(e instanceof UnexpectedException);
            assertEquals("Something bad happened", e.getMessage());
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) SharedPreferencesHelper.writeMockConfiguration(com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration) Configuration(com.braintreepayments.api.models.Configuration) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 60 with Configuration

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

the class ConfigurationManagerUnitTest method getConfiguration_takesClientTokenIntoAccountForCache.

@Test(timeout = 1000)
public void getConfiguration_takesClientTokenIntoAccountForCache() throws InvalidArgumentException, InterruptedException {
    ClientToken clientToken = (ClientToken) Authorization.fromString(stringFromFixture("client_token_with_authorization_fingerprint_options.json"));
    when(mBraintreeFragment.getAuthorization()).thenReturn(clientToken);
    writeMockConfiguration(RuntimeEnvironment.application, clientToken.getConfigUrl(), clientToken.getAuthorizationFingerprint(), stringFromFixture("configuration/configuration.json"), System.currentTimeMillis());
    ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            assertEquals(stringFromFixture("configuration/configuration.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) ClientToken(com.braintreepayments.api.models.ClientToken) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) 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