Search in sources :

Example 1 with TestIdealConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder 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);
}
Also used : BraintreeApiHttpClient(com.braintreepayments.api.internal.BraintreeApiHttpClient) TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Before(org.junit.Before)

Example 2 with TestIdealConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder in project braintree_android by braintree.

the class IdealUnitTest method fetchIssuingBanks_postsConfigurationExceptionWhenBraintreeApiNotEnabled.

@Test
public void fetchIssuingBanks_postsConfigurationExceptionWhenBraintreeApiNotEnabled() throws InvalidArgumentException, InterruptedException {
    Configuration configuration = new TestConfigurationBuilder().ideal(new TestIdealConfigurationBuilder().routeId("some-route-id")).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("Your access is restricted and cannot use this part of the Braintree API.", e.getMessage());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) IdealBank(com.braintreepayments.api.models.IdealBank) List(java.util.List) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) JSONException(org.json.JSONException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with TestIdealConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder 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();
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeApiHttpClient(com.braintreepayments.api.internal.BraintreeApiHttpClient) Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) IdealResult(com.braintreepayments.api.models.IdealResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with TestIdealConfigurationBuilder

use of com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder 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();
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeApiHttpClient(com.braintreepayments.api.internal.BraintreeApiHttpClient) Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) IdealResult(com.braintreepayments.api.models.IdealResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)4 TestIdealConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder)4 BraintreeApiHttpClient (com.braintreepayments.api.internal.BraintreeApiHttpClient)3 Configuration (com.braintreepayments.api.models.Configuration)3 TestBraintreeApiConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)2 IdealResult (com.braintreepayments.api.models.IdealResult)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JSONObject (org.json.JSONObject)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)2 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)1 IdealBank (com.braintreepayments.api.models.IdealBank)1 IOException (java.io.IOException)1 List (java.util.List)1 JSONException (org.json.JSONException)1 Before (org.junit.Before)1