Search in sources :

Example 6 with ApiException

use of com.ingenico.connect.gateway.sdk.java.ApiException in project connect-sdk-java by Ingenico-ePayments.

the class PaymentsClientTest method testCreateInvalidAuthorization.

/**
 * Tests that a 401 failure response without a payment result will throw a {@link ApiException}.
 */
@Test
@SuppressWarnings("resource")
public void testCreateInvalidAuthorization() {
    Client client = Factory.createClient(session);
    String responseBody = getResource("invalid_authorization.json");
    whenPost().thenReturn(new Response(401, responseBody, null));
    CreatePaymentRequest body = createRequest();
    try {
        client.merchant("merchantId").payments().create(body);
        Assert.fail("Expected ApiException");
    } catch (ApiException e) {
        Assert.assertTrue(e.toString().contains(responseBody));
    }
}
Also used : Response(com.ingenico.connect.gateway.sdk.java.Response) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) Client(com.ingenico.connect.gateway.sdk.java.Client) ApiException(com.ingenico.connect.gateway.sdk.java.ApiException) Test(org.junit.Test)

Aggregations

ApiException (com.ingenico.connect.gateway.sdk.java.ApiException)6 Client (com.ingenico.connect.gateway.sdk.java.Client)4 AmountOfMoney (com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney)3 PersonalName (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.PersonalName)3 CommunicationException (com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException)2 Address (com.ingenico.connect.gateway.sdk.java.domain.definitions.Address)2 BankAccountIban (com.ingenico.connect.gateway.sdk.java.domain.definitions.BankAccountIban)2 CompanyInformation (com.ingenico.connect.gateway.sdk.java.domain.definitions.CompanyInformation)2 ContactDetailsBase (com.ingenico.connect.gateway.sdk.java.domain.definitions.ContactDetailsBase)2 CreatePaymentRequest (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest)2 CreatePaymentResponse (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse)2 AddressPersonal (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.AddressPersonal)2 DeclinedPaymentException (com.ingenico.connect.gateway.sdk.java.DeclinedPaymentException)1 DeclinedPayoutException (com.ingenico.connect.gateway.sdk.java.DeclinedPayoutException)1 DeclinedRefundException (com.ingenico.connect.gateway.sdk.java.DeclinedRefundException)1 Response (com.ingenico.connect.gateway.sdk.java.Response)1 Card (com.ingenico.connect.gateway.sdk.java.domain.definitions.Card)1 CardPaymentMethodSpecificInput (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.CardPaymentMethodSpecificInput)1 ContactDetails (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.ContactDetails)1 Customer (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Customer)1