use of com.braintreepayments.api.models.Configuration 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.models.Configuration 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.models.Configuration 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.models.Configuration 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.models.Configuration in project braintree_android by braintree.
the class AnalyticsIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
if (intent == null) {
return;
}
try {
Authorization authorization = Authorization.fromString(intent.getStringExtra(EXTRA_AUTHORIZATION));
Configuration configuration = Configuration.fromJson(intent.getStringExtra(EXTRA_CONFIGURATION));
AnalyticsSender.send(this, authorization, new BraintreeHttpClient(authorization), configuration.getAnalytics().getUrl(), true);
} catch (InvalidArgumentException | JSONException ignored) {
}
}
Aggregations