Search in sources :

Example 11 with Request

use of com.paypal.android.sdk.onetouch.core.Request in project braintree_android by braintree.

the class AppSwitchHelperUnitTest method parseAppSwitchResponse_parsesErrorAndReturnsResult.

@Test
public void parseAppSwitchResponse_parsesErrorAndReturnsResult() {
    Request request = mock(AuthorizationRequest.class);
    when(request.validateV1V2Response(any(ContextInspector.class), any(Bundle.class))).thenReturn(true);
    Intent intent = new Intent().putExtra("error", "there was an error");
    Result result = AppSwitchHelper.parseAppSwitchResponse(mContextInspector, request, intent);
    verify(request).trackFpti(any(Context.class), eq(TrackingPoint.Return), isNull(Protocol.class));
    assertTrue(result.getError() instanceof WalletSwitchException);
    assertEquals("there was an error", result.getError().getMessage());
}
Also used : Context(android.content.Context) ContextInspector(com.paypal.android.sdk.onetouch.core.base.ContextInspector) TestSetupHelper.getMockContextInspector(com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector) Bundle(android.os.Bundle) Request(com.paypal.android.sdk.onetouch.core.Request) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Intent(android.content.Intent) WalletSwitchException(com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException) Protocol(com.paypal.android.sdk.onetouch.core.enums.Protocol) Result(com.paypal.android.sdk.onetouch.core.Result) Test(org.junit.Test)

Example 12 with Request

use of com.paypal.android.sdk.onetouch.core.Request in project braintree_android by braintree.

the class AppSwitchHelperUnitTest method buildAppSwitchIntent_buildsIntent.

@Test
public void buildAppSwitchIntent_buildsIntent() {
    Request request = mock(CheckoutRequest.class);
    when(request.getEnvironment()).thenReturn("test");
    when(request.getClientMetadataId()).thenReturn("client-metadata-id");
    when(request.getClientId()).thenReturn("client-id");
    Intent intent = AppSwitchHelper.getAppSwitchIntent(mContextInspector, mConfigManager, request, getMockRecipe(2));
    assertEquals("installation-guid", intent.getStringExtra("app_guid"));
    assertEquals("client-metadata-id", intent.getStringExtra("client_metadata_id"));
    assertEquals("client-id", intent.getStringExtra("client_id"));
    assertEquals("application-name", intent.getStringExtra("app_name"));
    assertEquals("test", intent.getStringExtra("environment"));
    assertEquals("test", intent.getStringExtra("environment_url"));
}
Also used : Request(com.paypal.android.sdk.onetouch.core.Request) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Intent(android.content.Intent) Test(org.junit.Test)

Example 13 with Request

use of com.paypal.android.sdk.onetouch.core.Request in project braintree_android by braintree.

the class AppSwitchHelperUnitTest method parseAppSwitchResponse_returnsErrorWhenResponseCouldNotBeParsed.

@Test
public void parseAppSwitchResponse_returnsErrorWhenResponseCouldNotBeParsed() {
    Request request = mock(AuthorizationRequest.class);
    when(request.validateV1V2Response(any(ContextInspector.class), any(Bundle.class))).thenReturn(false);
    Intent intent = new Intent().putExtra("braintree", "nonce");
    Result result = AppSwitchHelper.parseAppSwitchResponse(mContextInspector, request, intent);
    verify(request).trackFpti(any(Context.class), eq(TrackingPoint.Error), isNull(Protocol.class));
    assertTrue(result.getError() instanceof ResponseParsingException);
    assertEquals("invalid wallet response", result.getError().getMessage());
}
Also used : Context(android.content.Context) ContextInspector(com.paypal.android.sdk.onetouch.core.base.ContextInspector) TestSetupHelper.getMockContextInspector(com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector) Bundle(android.os.Bundle) ResponseParsingException(com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException) Request(com.paypal.android.sdk.onetouch.core.Request) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Intent(android.content.Intent) Protocol(com.paypal.android.sdk.onetouch.core.enums.Protocol) Result(com.paypal.android.sdk.onetouch.core.Result) Test(org.junit.Test)

Example 14 with Request

use of com.paypal.android.sdk.onetouch.core.Request in project braintree_android by braintree.

the class AppSwitchHelperUnitTest method buildAppSwitchIntent_buildsIntentForProtocolV1.

@Test
public void buildAppSwitchIntent_buildsIntentForProtocolV1() {
    Request request = mock(CheckoutRequest.class);
    when(request.getEnvironment()).thenReturn("test");
    Intent intent = AppSwitchHelper.getAppSwitchIntent(mContextInspector, mConfigManager, request, getMockRecipe(1));
    assertEquals("com.paypal.android.lib.authenticator.activity.v1.TouchActivity", intent.getAction());
    assertEquals("com.paypal.android.p2pmobile", intent.getPackage());
    assertEquals("1.0", intent.getStringExtra("version"));
}
Also used : Request(com.paypal.android.sdk.onetouch.core.Request) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Intent(android.content.Intent) Test(org.junit.Test)

Example 15 with Request

use of com.paypal.android.sdk.onetouch.core.Request in project braintree_android by braintree.

the class AppSwitchHelperUnitTest method parseAppSwitchResponse_parsesErrorForErrorResponses.

@Test
public void parseAppSwitchResponse_parsesErrorForErrorResponses() {
    Request request = mock(AuthorizationRequest.class);
    when(request.validateV1V2Response(any(ContextInspector.class), any(Bundle.class))).thenReturn(false);
    Intent intent = new Intent().putExtra("error", "there was an error");
    Result result = AppSwitchHelper.parseAppSwitchResponse(mContextInspector, request, intent);
    verify(request).trackFpti(any(Context.class), eq(TrackingPoint.Error), isNull(Protocol.class));
    assertTrue(result.getError() instanceof WalletSwitchException);
    assertEquals("there was an error", result.getError().getMessage());
}
Also used : Context(android.content.Context) ContextInspector(com.paypal.android.sdk.onetouch.core.base.ContextInspector) TestSetupHelper.getMockContextInspector(com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector) Bundle(android.os.Bundle) Request(com.paypal.android.sdk.onetouch.core.Request) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Intent(android.content.Intent) WalletSwitchException(com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException) Protocol(com.paypal.android.sdk.onetouch.core.enums.Protocol) Result(com.paypal.android.sdk.onetouch.core.Result) Test(org.junit.Test)

Aggregations

AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)26 Request (com.paypal.android.sdk.onetouch.core.Request)26 Test (org.junit.Test)23 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)21 Intent (android.content.Intent)12 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)12 Configuration (com.braintreepayments.api.models.Configuration)10 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)8 PayPalApprovalCallback (com.braintreepayments.api.interfaces.PayPalApprovalCallback)6 PayPalApprovalHandler (com.braintreepayments.api.interfaces.PayPalApprovalHandler)6 Result (com.paypal.android.sdk.onetouch.core.Result)6 Context (android.content.Context)5 Bundle (android.os.Bundle)5 ContextInspector (com.paypal.android.sdk.onetouch.core.base.ContextInspector)5 Protocol (com.paypal.android.sdk.onetouch.core.enums.Protocol)5 TestSetupHelper.getMockContextInspector (com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)3 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)3 PaymentMethodBuilder (com.braintreepayments.api.models.PaymentMethodBuilder)3