Search in sources :

Example 1 with NotFoundException

use of com.ingenico.connect.gateway.sdk.java.NotFoundException 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 2 with NotFoundException

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

the class DefaultConnectionLoggerTest method testNonJson.

@Test
public void testNonJson() 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(setHtmlResponse("notFound.html", 404));
    try {
        client.merchant("1234").services().testconnection();
        Assert.fail("expected NotFoundException");
    } catch (NotFoundException 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", "notFound");
}
Also used : HttpHost(org.apache.http.HttpHost) NotFoundException(com.ingenico.connect.gateway.sdk.java.NotFoundException) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Aggregations

Client (com.ingenico.connect.gateway.sdk.java.Client)2 NotFoundException (com.ingenico.connect.gateway.sdk.java.NotFoundException)2 Test (org.junit.Test)2 Response (com.ingenico.connect.gateway.sdk.java.Response)1 ResponseException (com.ingenico.connect.gateway.sdk.java.ResponseException)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