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());
}
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);
}
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());
}
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();
}
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();
}
Aggregations