use of com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder in project braintree_android by braintree.
the class IdealUnitTest method setUp.
@Before
public void setUp() throws InvalidArgumentException {
mConfiguration = new TestConfigurationBuilder().assetsUrl("http://assets.example.com").ideal(new TestIdealConfigurationBuilder().routeId("some-route-id").assetsUrl("http://assets.example.com")).braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
mBraintreeFragment = getMockFragment(stringFromFixture("client_token.json"), mConfiguration);
mMockApiClient = mock(BraintreeApiHttpClient.class);
when(mBraintreeFragment.getBraintreeApiHttpClient()).thenReturn(mMockApiClient);
}
use of com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder in project braintree_android by braintree.
the class IdealUnitTest method pollForCompletion_pollsUntilMaxRetryCountExceeded.
@Test(timeout = 5000)
public void pollForCompletion_pollsUntilMaxRetryCountExceeded() throws InterruptedException, JSONException, InvalidArgumentException {
Configuration configuration = new TestConfigurationBuilder().ideal(new TestIdealConfigurationBuilder().routeId("some-route-id")).braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
final BraintreeFragment fragment = new MockFragmentBuilder().authorization(Authorization.fromString(stringFromFixture("client_token.json"))).configuration(configuration).build();
BraintreeApiHttpClient apiHttpClient = mock(BraintreeApiHttpClient.class);
when(fragment.getBraintreeApiHttpClient()).thenReturn(apiHttpClient);
final String resultFixture = stringFromFixture("payment_methods/pending_ideal_bank_payment.json");
final CountDownLatch latch = new CountDownLatch(2);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
callback.success(resultFixture);
latch.countDown();
return null;
}
}).when(apiHttpClient).get(eq("/ideal-payments/ideal_payment_id/status"), any(HttpResponseCallback.class));
IdealResult idealResult = IdealResult.fromJson(resultFixture);
putResultIdInPrefs(idealResult.getId());
Ideal.pollForCompletion(fragment, idealResult.getId(), 1, 1000);
// Two retries = three calls to latch.countDown
latch.await();
}
use of com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder in project braintree_android by braintree.
the class IdealUnitTest method fetchIssuingBanks_postsConfigurationExceptionWhenIdealNotEnabled.
@Test
public void fetchIssuingBanks_postsConfigurationExceptionWhenIdealNotEnabled() throws InvalidArgumentException {
Configuration configuration = new TestConfigurationBuilder().braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
BraintreeFragment fragment = getMockFragment(stringFromFixture("client_token.json"), configuration);
Ideal.fetchIssuingBanks(fragment, new BraintreeResponseListener<List<IdealBank>>() {
@Override
public void onResponse(List<IdealBank> idealBanks) {
fail("Success listener called");
}
});
ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
verify(fragment).postCallback(captor.capture());
Exception e = captor.getValue();
assertEquals("iDEAL is not enabled for this merchant.", e.getMessage());
}
use of com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder in project braintree_android by braintree.
the class IdealUnitTest method onActivityResult_checksPaymentStatusOnceBeforeInvokingCallback.
@Test(timeout = 10000)
public void onActivityResult_checksPaymentStatusOnceBeforeInvokingCallback() throws InvalidArgumentException, JSONException, InterruptedException {
Configuration configuration = new TestConfigurationBuilder().ideal(new TestIdealConfigurationBuilder().routeId("some-route-id")).braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
final BraintreeFragment fragment = new MockFragmentBuilder().authorization(Authorization.fromString(stringFromFixture("client_token.json"))).configuration(configuration).build();
BraintreeApiHttpClient apiHttpClient = mock(BraintreeApiHttpClient.class);
when(fragment.getBraintreeApiHttpClient()).thenReturn(apiHttpClient);
final String resultFixture = stringFromFixture("payment_methods/pending_ideal_bank_payment.json");
final CountDownLatch latch = new CountDownLatch(1);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
callback.success(resultFixture);
latch.countDown();
return null;
}
}).when(apiHttpClient).get(eq("/ideal-payments/ideal_payment_id/status"), any(HttpResponseCallback.class));
IdealResult idealResult = IdealResult.fromJson(resultFixture);
putResultIdInPrefs(idealResult.getId());
Ideal.onActivityResult(fragment, Activity.RESULT_OK);
latch.await();
}
use of com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method getBraintreeApiHttpClient_returnsExistingClientIfOneExists.
@Test
public void getBraintreeApiHttpClient_returnsExistingClientIfOneExists() throws Exception {
String configuration = new TestConfigurationBuilder().braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("some-token").url("http://braintree-api.com")).build();
mockConfigurationManager(Configuration.fromJson(configuration));
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
HttpClient client = fragment.getBraintreeApiHttpClient();
HttpClient client2 = fragment.getBraintreeApiHttpClient();
assertSame(client, client2);
}
Aggregations