Search in sources :

Example 1 with BraintreeHttpClient

use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.

the class UnionPayUnitTest method tokenize_optionalSmsCode_sendsPayloadToEndpoint.

@Test
public void tokenize_optionalSmsCode_sendsPayloadToEndpoint() throws JSONException {
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("someCardNumber").expirationMonth("expirationMonth").expirationYear("expirationYear").cvv("cvv").enrollmentId("enrollmentId").validate(true);
    BraintreeHttpClient httpClient = mock(BraintreeHttpClient.class);
    doNothing().when(httpClient).get(anyString(), any(HttpResponseCallback.class));
    when(mBraintreeFragment.getHttpClient()).thenReturn(httpClient);
    ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
    UnionPay.tokenize(mBraintreeFragment, unionPayCardBuilder);
    verify(httpClient).post(eq("/v1/payment_methods/credit_cards"), argumentCaptor.capture(), any(HttpResponseCallback.class));
    JSONObject tokenizePayload = new JSONObject(argumentCaptor.getValue());
    JSONObject creditCardPayload = tokenizePayload.getJSONObject("creditCard");
    JSONObject optionsPayload = creditCardPayload.getJSONObject("options");
    JSONObject unionPayEnrollmentPayload = optionsPayload.getJSONObject("unionPayEnrollment");
    assertEquals("someCardNumber", creditCardPayload.getString("number"));
    assertEquals("expirationMonth", creditCardPayload.getString("expirationMonth"));
    assertEquals("expirationYear", creditCardPayload.getString("expirationYear"));
    assertEquals("cvv", creditCardPayload.getString("cvv"));
    assertFalse(optionsPayload.has("validate"));
    assertEquals("enrollmentId", unionPayEnrollmentPayload.getString("id"));
    assertFalse(unionPayEnrollmentPayload.has("smsCode"));
}
Also used : JSONObject(org.json.JSONObject) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) Matchers.anyString(org.mockito.Matchers.anyString) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with BraintreeHttpClient

use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.

the class UnionPayUnitTest method enroll_doesNotPassCvvToEnrollmentPayloadIfCvvExists.

@Test
public void enroll_doesNotPassCvvToEnrollmentPayloadIfCvvExists() throws JSONException {
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("some-card-number").cvv("123");
    BraintreeHttpClient httpClient = mock(BraintreeHttpClient.class);
    doNothing().when(httpClient).get(anyString(), any(HttpResponseCallback.class));
    when(mBraintreeFragment.getHttpClient()).thenReturn(httpClient);
    ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
    UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
    verify(httpClient).post(eq("/v1/union_pay_enrollments"), argumentCaptor.capture(), any(HttpResponseCallback.class));
    JSONObject enrollmentPayload = new JSONObject(argumentCaptor.getValue());
    JSONObject unionPayEnrollmentPayload = enrollmentPayload.getJSONObject("unionPayEnrollment");
    assertFalse(unionPayEnrollmentPayload.has("cvv"));
}
Also used : JSONObject(org.json.JSONObject) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) Matchers.anyString(org.mockito.Matchers.anyString) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with BraintreeHttpClient

use of com.braintreepayments.api.internal.BraintreeHttpClient 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());
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) SharedPreferencesHelper.writeMockConfiguration(com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration) Configuration(com.braintreepayments.api.models.Configuration) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 4 with BraintreeHttpClient

use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.

the class ConfigurationManagerUnitTest method setup.

@Before
public void setup() throws InvalidArgumentException {
    clearSharedPreferences(RuntimeEnvironment.application);
    ConfigurationManager.sFetchingConfiguration = false;
    mTokenizationKey = Authorization.fromString(TestTokenizationKey.TOKENIZATION_KEY);
    mCountDownLatch = new CountDownLatch(1);
    mBraintreeFragment = mock(BraintreeFragment.class);
    when(mBraintreeFragment.getAuthorization()).thenReturn(mTokenizationKey);
    when(mBraintreeFragment.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
    when(mBraintreeFragment.getHttpClient()).thenReturn(new BraintreeHttpClient(mTokenizationKey));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient) Before(org.junit.Before)

Example 5 with BraintreeHttpClient

use of com.braintreepayments.api.internal.BraintreeHttpClient 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);
}
Also used : HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient)

Aggregations

BraintreeHttpClient (com.braintreepayments.api.internal.BraintreeHttpClient)12 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)9 Test (org.junit.Test)8 Matchers.anyString (org.mockito.Matchers.anyString)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)4 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)4 JSONObject (org.json.JSONObject)4 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)3 Configuration (com.braintreepayments.api.models.Configuration)3 SharedPreferencesHelper.writeMockConfiguration (com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration)3 BraintreeGraphQLHttpClient (com.braintreepayments.api.internal.BraintreeGraphQLHttpClient)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1 TokenizationKey (com.braintreepayments.api.models.TokenizationKey)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 JSONException (org.json.JSONException)1 Before (org.junit.Before)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1