Search in sources :

Example 1 with GlobalCollectException

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

the class PaymentsClientTest method testCreateInternalServerErrorWithoutBody.

/**
 * Tests that a 500 response with a JSON response with no body will throw a {@link GlobalCollectException} and not a {@link NullPointerException}.
 */
@Test
@SuppressWarnings("resource")
public void testCreateInternalServerErrorWithoutBody() {
    Client client = Factory.createClient(session);
    String responseBody = null;
    whenPost().thenReturn(new Response(500, responseBody, Arrays.asList(new ResponseHeader("content-type", "text/html"))));
    CreatePaymentRequest body = createRequest();
    try {
        client.merchant("merchantId").payments().create(body);
        Assert.fail("Expected GlobalCollectException");
    } catch (GlobalCollectException e) {
        Assert.assertEquals(responseBody, e.getResponseBody());
        Assert.assertNull(e.getErrorId());
        Assert.assertEquals(0, e.getErrors().size());
    }
}
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) GlobalCollectException(com.ingenico.connect.gateway.sdk.java.GlobalCollectException) 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 GlobalCollectException

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

the class DefaultConnectionLoggerTest method testLoggingUnknownServerError.

@Test
public void testLoggingUnknownServerError() throws Exception {
    // an exception is thrown after logging the response
    serverBootstrap.registerHandler("/v1/1234/services/testconnection", requestHandler);
    HttpHost host = start();
    Client client = createClient(host);
    TestLogger logger = new TestLogger();
    client.enableLogging(logger);
    setupRequestHandler(setJsonResponse("unknownServerError.json", 500));
    try {
        client.merchant("1234").services().testconnection();
        Assert.fail("expected GlobalCollectException");
    } catch (GlobalCollectException e) {
    // expected
    } finally {
        client.close();
    }
    Assert.assertEquals(2, logger.entries.size());
    TestLoggerEntry requestEntry = logger.entries.get(0);
    Assert.assertNotNull(requestEntry.message);
    Assert.assertNull(requestEntry.thrown);
    TestLoggerEntry responseEntry = logger.entries.get(1);
    Assert.assertNotNull(responseEntry.message);
    Assert.assertNull(responseEntry.thrown);
    assertRequestAndResponse(requestEntry.message, responseEntry.message, "testConnection", "unknownServerError");
}
Also used : GlobalCollectException(com.ingenico.connect.gateway.sdk.java.GlobalCollectException) HttpHost(org.apache.http.HttpHost) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Aggregations

Client (com.ingenico.connect.gateway.sdk.java.Client)2 GlobalCollectException (com.ingenico.connect.gateway.sdk.java.GlobalCollectException)2 Test (org.junit.Test)2 Response (com.ingenico.connect.gateway.sdk.java.Response)1 ResponseHeader (com.ingenico.connect.gateway.sdk.java.ResponseHeader)1 CreatePaymentRequest (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest)1 CreatePaymentResponse (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse)1 HttpHost (org.apache.http.HttpHost)1