use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeGraphQLHttpClientTest method getRequestBadCertificateCheck.
@Test(timeout = 5000)
public void getRequestBadCertificateCheck() throws InterruptedException, InvalidArgumentException {
if (!BuildConfig.RUN_ALL_TESTS) {
return;
}
String baseUrl = "https://" + EnvironmentHelper.getLocalhostIp() + ":9443";
BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, TOKENIZATION_KEY);
httpClient.get("/", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
mCountDownLatch.countDown();
}
@Override
public void failure(Exception exception) {
assertEquals("java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.", exception.getMessage());
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeHttpClientTest method getRequestSslCertificateSuccessfulInSandbox.
@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInSandbox() throws InterruptedException, InvalidArgumentException {
BraintreeHttpClient httpClient = new BraintreeHttpClient(TokenizationKey.fromString(TOKENIZATION_KEY));
httpClient.setBaseUrl("https://api.sandbox.braintreegateway.com");
httpClient.get("/", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request failed");
}
@Override
public void failure(Exception exception) {
assertTrue(exception instanceof AuthorizationException);
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeHttpClientTest method getRequestSslCertificateSuccessfulInProduction.
@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInProduction() throws InterruptedException, InvalidArgumentException {
BraintreeHttpClient httpClient = new BraintreeHttpClient(TokenizationKey.fromString(TOKENIZATION_KEY));
httpClient.setBaseUrl("https://api.braintreegateway.com");
httpClient.get("/", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request failed");
}
@Override
public void failure(Exception exception) {
assertTrue(exception instanceof AuthorizationException);
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeHttpClientTest method postsErrorWhenBaseUrlIsNotSet.
@Test(timeout = 1000)
public void postsErrorWhenBaseUrlIsNotSet() throws InterruptedException, IOException, InvalidArgumentException {
BraintreeHttpClient httpClient = new BraintreeHttpClient(TokenizationKey.fromString(TOKENIZATION_KEY));
final CountDownLatch countDownLatch = new CountDownLatch(2);
httpClient.get("/", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
}
@Override
public void failure(Exception exception) {
assertEquals(MalformedURLException.class, exception.getClass());
countDownLatch.countDown();
}
});
httpClient.post("/", "{}", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
}
@Override
public void failure(Exception exception) {
assertEquals(MalformedURLException.class, exception.getClass());
countDownLatch.countDown();
}
});
countDownLatch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeHttpClientTest method postsErrorWhenClientTokenIsUsedAndInvalidJsonIsSent.
@Test(timeout = 1000)
public void postsErrorWhenClientTokenIsUsedAndInvalidJsonIsSent() throws InvalidArgumentException, InterruptedException {
BraintreeHttpClient httpClient = new BraintreeHttpClient(Authorization.fromString(stringFromFixture("client_token.json")));
httpClient.post("/", "not json", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
}
@Override
public void failure(Exception exception) {
assertTrue(exception instanceof JSONException);
assertEquals("Value not of type java.lang.String cannot be converted to JSONObject", exception.getMessage());
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
Aggregations