use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class MockFragmentBuilder method setupSuccessResponses.
private void setupSuccessResponses(BraintreeHttpClient httpClient) {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((HttpResponseCallback) invocation.getArguments()[1]).success(mSuccessResponse);
return null;
}
}).when(httpClient).get(any(String.class), any(HttpResponseCallback.class));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((HttpResponseCallback) invocation.getArguments()[2]).success(mSuccessResponse);
return null;
}
}).when(httpClient).post(anyString(), anyString(), any(HttpResponseCallback.class));
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class AnalyticsSenderUnitTest method deletesDatabaseEventsOnAsynchronousSuccessResponse.
@Test
public void deletesDatabaseEventsOnAsynchronousSuccessResponse() throws InterruptedException {
AnalyticsEvent one = new AnalyticsEvent(RuntimeEnvironment.application, "sessionId", "custom", "started");
AnalyticsEvent two = new AnalyticsEvent(RuntimeEnvironment.application, "sessionId", "custom", "finished");
AnalyticsDatabase database = AnalyticsDatabase.getInstance(RuntimeEnvironment.application);
database.addEvent(one);
database.addEvent(two);
awaitTasksFinished(database);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((HttpResponseCallback) invocation.getArguments()[2]).success("");
return null;
}
}).when(mHttpClient).post(anyString(), anyString(), any(HttpResponseCallback.class));
AnalyticsSender.send(RuntimeEnvironment.application, mAuthorization, mHttpClient, "", false);
List<List<AnalyticsEvent>> pendingEvents = database.getPendingRequests();
assertEquals(0, pendingEvents.size());
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeApiHttpClientTest method setsBaseUrl.
@Test(timeout = 1000)
public void setsBaseUrl() throws IOException, InterruptedException {
BraintreeApiHttpClient client = spy(new BraintreeApiHttpClient("http://localhost", null));
final CountDownLatch latch = new CountDownLatch(1);
client.get("/some-path", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
latch.countDown();
}
@Override
public void failure(Exception exception) {
latch.countDown();
}
});
latch.await();
verify(client).init(eq("http://localhost/some-path"));
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeApiHttpClientTest method getRequestSslCertificateSuccessfulInProduction.
@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInProduction() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
BraintreeApiHttpClient client = new BraintreeApiHttpClient("https://payments.braintree-api.com", null);
client.get("/ping", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
try {
assertEquals("OK", new JSONObject(responseBody).getJSONObject("data").getString("status"));
} catch (JSONException e) {
fail("Response invalid");
}
latch.countDown();
}
@Override
public void failure(Exception exception) {
fail("Request failed");
}
});
latch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeGraphQLHttpClientTest method getRequestSslCertificateSuccessfulInSandbox.
@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInSandbox() throws InterruptedException, InvalidArgumentException {
BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient("https://payments.sandbox.braintree-api.com/graphql", TOKENIZATION_KEY);
httpClient.get("/", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
mCountDownLatch.countDown();
}
@Override
public void failure(Exception exception) {
assertFalse(exception instanceof SSLException);
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
Aggregations