use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method isFetchingConfiguration_isFalseInErrorCallback.
@Test(timeout = 1000)
public void isFetchingConfiguration_isFalseInErrorCallback() throws InterruptedException {
when(mBraintreeFragment.getHttpClient()).thenReturn(new BraintreeHttpClient(mTokenizationKey) {
@Override
public void get(String path, HttpResponseCallback callback) {
if (path.contains(mTokenizationKey.getConfigUrl())) {
callback.failure(new UnexpectedException("Something bad happened"));
}
}
});
ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
fail("Success listener should not have been called for bad request");
}
}, new BraintreeResponseListener<Exception>() {
@Override
public void onResponse(Exception e) {
assertFalse(ConfigurationManager.isFetchingConfiguration());
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.
the class BraintreeFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
if (mContext == null) {
mContext = getActivity().getApplicationContext();
}
mNewActivityNeedsConfiguration = false;
mCrashReporter = CrashReporter.setup(this);
mSessionId = getArguments().getString(EXTRA_SESSION_ID);
mIntegrationType = getArguments().getString(EXTRA_INTEGRATION_TYPE);
mAuthorization = getArguments().getParcelable(EXTRA_AUTHORIZATION_TOKEN);
mAnalyticsDatabase = AnalyticsDatabase.getInstance(getApplicationContext());
if (mHttpClient == null) {
mHttpClient = new BraintreeHttpClient(mAuthorization);
}
if (savedInstanceState != null) {
List<PaymentMethodNonce> paymentMethodNonces = savedInstanceState.getParcelableArrayList(EXTRA_CACHED_PAYMENT_METHOD_NONCES);
if (paymentMethodNonces != null) {
mCachedPaymentMethodNonces.addAll(paymentMethodNonces);
}
mHasFetchedPaymentMethodNonces = savedInstanceState.getBoolean(EXTRA_FETCHED_PAYMENT_METHOD_NONCES);
try {
setConfiguration(Configuration.fromJson(savedInstanceState.getString(EXTRA_CONFIGURATION)));
} catch (JSONException ignored) {
}
} else {
if (mAuthorization instanceof TokenizationKey) {
sendAnalyticsEvent("started.client-key");
} else {
sendAnalyticsEvent("started.client-token");
}
}
fetchConfiguration();
}
use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method getConfiguration_callsErrorListenerWhenHttpFails.
@Test(timeout = 1000)
public void getConfiguration_callsErrorListenerWhenHttpFails() throws InterruptedException {
BraintreeHttpClient fakeClient = new BraintreeHttpClient(mTokenizationKey) {
@Override
public void get(String path, HttpResponseCallback callback) {
if (path.contains(mTokenizationKey.getConfigUrl())) {
callback.failure(new UnexpectedException("Something bad happened"));
}
}
};
when(mBraintreeFragment.getHttpClient()).thenReturn(fakeClient);
ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
fail("Success listener should not have been called for bad request");
}
}, new BraintreeResponseListener<Exception>() {
@Override
public void onResponse(Exception e) {
assertTrue(e instanceof UnexpectedException);
assertEquals("Something bad happened", e.getMessage());
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.
the class MockFragmentBuilder method build.
public BraintreeFragment build() {
BraintreeFragment fragment = mock(BraintreeFragment.class);
when(fragment.getApplicationContext()).thenReturn(mContext);
when(fragment.getAuthorization()).thenReturn(mAuthorization);
when(fragment.getSessionId()).thenReturn(mSessionId);
when(fragment.getReturnUrlScheme()).thenReturn("com.braintreepayments.api.braintree");
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ConfigurationListener) invocation.getArguments()[0]).onConfigurationFetched(mConfiguration);
return null;
}
}).when(fragment).waitForConfiguration(any(ConfigurationListener.class));
when(fragment.getConfiguration()).thenReturn(mConfiguration);
BraintreeHttpClient httpClient = mock(BraintreeHttpClient.class);
if (mSuccessResponse != null) {
setupSuccessResponses(httpClient);
} else if (mErrorResponse != null) {
setupErrorResponses(httpClient);
}
when(fragment.getHttpClient()).thenReturn(httpClient);
BraintreeGraphQLHttpClient graphQLHttpClient = mock(BraintreeGraphQLHttpClient.class);
if (mGraphQLSuccessResponse != null) {
setupGraphQLSuccessResponses(graphQLHttpClient);
} else if (mGraphQLErrorResponse != null) {
setupGraphQLErrorResponses(graphQLHttpClient);
}
when(fragment.getGraphQLHttpClient()).thenReturn(graphQLHttpClient);
return fragment;
}
use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.
the class UnionPayUnitTest method enroll_sendsPayloadToEndpoint.
@Test
public void enroll_sendsPayloadToEndpoint() throws JSONException {
UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("someCardNumber").expirationMonth("expirationMonth").expirationYear("expirationYear").mobileCountryCode("mobileCountryCode").mobilePhoneNumber("mobilePhoneNumber");
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 enrollPayload = new JSONObject(argumentCaptor.getValue());
JSONObject unionPayEnrollment = enrollPayload.getJSONObject("unionPayEnrollment");
assertEquals("someCardNumber", unionPayEnrollment.getString("number"));
assertEquals("expirationMonth", unionPayEnrollment.getString("expirationMonth"));
assertEquals("expirationYear", unionPayEnrollment.getString("expirationYear"));
assertEquals("mobileCountryCode", unionPayEnrollment.getString("mobileCountryCode"));
assertEquals("mobilePhoneNumber", unionPayEnrollment.getString("mobileNumber"));
}
Aggregations