use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method isFetchingConfiguration_isTrueWhenFetchingConfiguration.
@Test
public void isFetchingConfiguration_isTrueWhenFetchingConfiguration() throws InterruptedException {
when(mBraintreeFragment.getHttpClient()).thenReturn(new BraintreeHttpClient(mTokenizationKey) {
@Override
public void get(String path, HttpResponseCallback callback) {
mThreadPool.submit(new Runnable() {
@Override
public void run() {
SystemClock.sleep(1000);
}
});
}
});
ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
}
}, new BraintreeResponseListener<Exception>() {
@Override
public void onResponse(Exception e) {
}
});
assertTrue(ConfigurationManager.isFetchingConfiguration());
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method getConfiguration_writesConfigToDiskWithValidTimestampAfterFetch.
@Test(timeout = 1000)
public void getConfiguration_writesConfigToDiskWithValidTimestampAfterFetch() throws InterruptedException {
stubConfigurationFromGateway(stringFromFixture("configuration/configuration.json"));
ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
String key = Base64.encodeToString(Uri.parse(mTokenizationKey.getConfigUrl()).buildUpon().appendQueryParameter("configVersion", "3").build().toString().concat(mTokenizationKey.getBearer()).getBytes(), 0);
assertEquals(stringFromFixture("configuration/configuration.json"), getSharedPreferences(RuntimeEnvironment.application).getString(key, ""));
assertTrue(System.currentTimeMillis() - getSharedPreferences(RuntimeEnvironment.application).getLong(key + "_timestamp", 0) < 1000);
mCountDownLatch.countDown();
}
}, new BraintreeResponseListener<Exception>() {
@Override
public void onResponse(Exception e) {
fail(e.getMessage());
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method isFetchingConfiguration_isFalseInErrorCallback.
@Test(timeout = 1000)
public void isFetchingConfiguration_isFalseInErrorCallback() throws InterruptedException {
when(mBraintreeFragment.getHttpClient()).thenReturn(new BraintreeHttpClient(mTokenizationKey) {
@Override
public void get(String path, HttpResponseCallback callback) {
if (path.contains(mTokenizationKey.getConfigUrl())) {
callback.failure(new UnexpectedException("Something bad happened"));
}
}
});
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) {
assertFalse(ConfigurationManager.isFetchingConfiguration());
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method getConfiguration_getsConfigFromCacheWhenTimeoutHasNotExpired.
@Test(timeout = 1000)
public void getConfiguration_getsConfigFromCacheWhenTimeoutHasNotExpired() throws InterruptedException {
writeMockConfiguration(RuntimeEnvironment.application, mTokenizationKey.getConfigUrl(), mTokenizationKey.getBearer(), 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();
}
use of com.braintreepayments.api.interfaces.ConfigurationListener 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();
}
Aggregations