use of com.braintreepayments.api.interfaces.HttpResponseCallback 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.HttpResponseCallback in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method stubConfigurationFromGateway.
private void stubConfigurationFromGateway(final String responseString) {
BraintreeHttpClient fakeClient = new BraintreeHttpClient(mBraintreeFragment.getAuthorization()) {
@Override
public void get(String path, HttpResponseCallback callback) {
if (path.contains(mBraintreeFragment.getAuthorization().getConfigUrl())) {
callback.success(responseString);
}
}
};
when(mBraintreeFragment.getHttpClient()).thenReturn(fakeClient);
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback 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.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeApiHttpClientTest method getRequestBadCertificateCheck.
@Test(timeout = 5000)
public void getRequestBadCertificateCheck() throws InterruptedException {
if (!BuildConfig.RUN_ALL_TESTS) {
return;
}
final CountDownLatch latch = new CountDownLatch(1);
BraintreeApiHttpClient client = new BraintreeApiHttpClient("https://" + EnvironmentHelper.getLocalhostIp() + ":9443", null);
client.get("/", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
}
@Override
public void failure(Exception exception) {
assertEquals("java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.", exception.getMessage());
latch.countDown();
}
});
latch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeApiHttpClientTest method throwsBraintreeApiErrorResponseExceptionOn400.
@Test(timeout = 5000)
public void throwsBraintreeApiErrorResponseExceptionOn400() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(2);
final Class expectedException = BraintreeApiErrorResponse.class;
final String expectedMessage = "The provided parameters are invalid; see details for field-specific error messages.";
BraintreeApiHttpClient client = new BraintreeApiHttpClient(null, null);
client = (BraintreeApiHttpClient) stubResponse(client, 400, stringFromFixture("errors/braintree_api_error_response.json"));
client.get("/", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
}
@Override
public void failure(Exception exception) {
assertEquals(expectedException, exception.getClass());
assertEquals(expectedMessage, exception.getMessage());
countDownLatch.countDown();
}
});
client.post("/", "{}", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
}
@Override
public void failure(Exception exception) {
assertEquals(expectedException, exception.getClass());
assertEquals(expectedMessage, exception.getMessage());
countDownLatch.countDown();
}
});
countDownLatch.await();
}
Aggregations