Search in sources :

Example 1 with Response

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

the class PaymentsClientTest method testCreateInvalidRequest.

/**
 * Tests that a 400 failure response without a payment result will throw a {@link ValidationException}.
 */
@Test
@SuppressWarnings("resource")
public void testCreateInvalidRequest() {
    Client client = Factory.createClient(session);
    String responseBody = getResource("invalid_request.json");
    whenPost().thenReturn(new Response(400, responseBody, null));
    CreatePaymentRequest body = createRequest();
    try {
        client.merchant("merchantId").payments().create(body);
        Assert.fail("Expected ValidationException");
    } catch (ValidationException 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) ValidationException(com.ingenico.connect.gateway.sdk.java.ValidationException) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 2 with Response

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

the class PaymentsClientTest method testCreateNotFound.

/**
 * Tests that a 404 response with a non-JSON response will throw a {@link NotFoundException}.
 */
@Test
@SuppressWarnings("resource")
public void testCreateNotFound() {
    Client client = Factory.createClient(session);
    String responseBody = getResource("not_found.html");
    whenPost().thenReturn(new Response(404, responseBody, Arrays.asList(new ResponseHeader("content-type", "text/html"))));
    CreatePaymentRequest body = createRequest();
    try {
        client.merchant("merchantId").payments().create(body);
        Assert.fail("Expected NotFoundException");
    } catch (NotFoundException e) {
        Assert.assertNotNull(e.getCause());
        Assert.assertEquals(ResponseException.class, e.getCause().getClass());
        Assert.assertTrue(e.getCause().toString().contains(responseBody));
    }
}
Also used : Response(com.ingenico.connect.gateway.sdk.java.Response) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse) ResponseHeader(com.ingenico.connect.gateway.sdk.java.ResponseHeader) ResponseException(com.ingenico.connect.gateway.sdk.java.ResponseException) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) NotFoundException(com.ingenico.connect.gateway.sdk.java.NotFoundException) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 3 with Response

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

the class PaymentsClientTest method testCreateMethodNotAllowed.

/**
 * Tests that a 405 response with a non-JSON response will throw a {@link CommunicationException}.
 */
@Test
@SuppressWarnings("resource")
public void testCreateMethodNotAllowed() {
    Client client = Factory.createClient(session);
    String responseBody = getResource("method_not_allowed.html");
    whenPost().thenReturn(new Response(405, responseBody, Arrays.asList(new ResponseHeader("content-type", "text/html"))));
    CreatePaymentRequest body = createRequest();
    try {
        client.merchant("merchantId").payments().create(body);
        Assert.fail("Expected CommunicationException");
    } catch (CommunicationException e) {
        Assert.assertNotNull(e.getCause());
        Assert.assertEquals(ResponseException.class, e.getCause().getClass());
        Assert.assertTrue(e.getCause().toString().contains(responseBody));
    }
}
Also used : Response(com.ingenico.connect.gateway.sdk.java.Response) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse) ResponseHeader(com.ingenico.connect.gateway.sdk.java.ResponseHeader) CommunicationException(com.ingenico.connect.gateway.sdk.java.CommunicationException) ResponseException(com.ingenico.connect.gateway.sdk.java.ResponseException) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 4 with Response

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

the class PaymentsClientTest method testCreateRejected.

/**
 * Tests that a failure response with a payment result will throw a {@link DeclinedPaymentException}.
 */
@Test
@SuppressWarnings("resource")
public void testCreateRejected() {
    Client client = Factory.createClient(session);
    String responseBody = getResource("rejected.json");
    whenPost().thenReturn(new Response(400, responseBody, null));
    CreatePaymentRequest body = createRequest();
    try {
        client.merchant("merchantId").payments().create(body);
        Assert.fail("Expected DeclinedPaymentException");
    } catch (DeclinedPaymentException e) {
        Assert.assertTrue(e.toString().contains("payment '000002000020142544360000100001'"));
        Assert.assertTrue(e.toString().contains("status 'REJECTED'"));
        Assert.assertTrue(e.toString().contains(responseBody));
        Assert.assertNotNull(e.getCreatePaymentResult());
        Assert.assertEquals("000002000020142544360000100001", e.getCreatePaymentResult().getPayment().getId());
        Assert.assertEquals("REJECTED", e.getCreatePaymentResult().getPayment().getStatus());
    }
}
Also used : Response(com.ingenico.connect.gateway.sdk.java.Response) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse) DeclinedPaymentException(com.ingenico.connect.gateway.sdk.java.DeclinedPaymentException) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 5 with Response

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

the class PaymentsClientTest method testCreateSuccess.

/**
 * Tests that a non-failure response will not throw an exception.
 */
@Test
@SuppressWarnings("resource")
public void testCreateSuccess() {
    Client client = Factory.createClient(session);
    String responseBody = getResource("pending_approval.json");
    whenPost().thenReturn(new Response(201, responseBody, null));
    CreatePaymentRequest body = createRequest();
    CreatePaymentResponse response = client.merchant("merchantId").payments().create(body);
    Assert.assertEquals("000002000020142549460000100001", response.getPayment().getId());
    Assert.assertEquals("PENDING_APPROVAL", response.getPayment().getStatus());
}
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) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse) Test(org.junit.Test)

Aggregations

Response (com.ingenico.connect.gateway.sdk.java.Response)10 Client (com.ingenico.connect.gateway.sdk.java.Client)9 CreatePaymentRequest (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest)9 CreatePaymentResponse (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse)9 Test (org.junit.Test)9 ResponseHeader (com.ingenico.connect.gateway.sdk.java.ResponseHeader)4 CommunicationException (com.ingenico.connect.gateway.sdk.java.CommunicationException)2 ResponseException (com.ingenico.connect.gateway.sdk.java.ResponseException)2 ApiException (com.ingenico.connect.gateway.sdk.java.ApiException)1 CallContext (com.ingenico.connect.gateway.sdk.java.CallContext)1 DeclinedPaymentException (com.ingenico.connect.gateway.sdk.java.DeclinedPaymentException)1 GlobalCollectException (com.ingenico.connect.gateway.sdk.java.GlobalCollectException)1 IdempotenceException (com.ingenico.connect.gateway.sdk.java.IdempotenceException)1 NotFoundException (com.ingenico.connect.gateway.sdk.java.NotFoundException)1 ReferenceException (com.ingenico.connect.gateway.sdk.java.ReferenceException)1 ValidationException (com.ingenico.connect.gateway.sdk.java.ValidationException)1 IOException (java.io.IOException)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1