Search in sources :

Example 1 with TestConnection

use of com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnectionLoggerTest method testLogRequestOnly.

@Test
public void testLogRequestOnly() throws Exception {
    // logging is disabled after the request is logged but before the response is logged
    serverBootstrap.registerHandler("/v1/1234/services/testconnection", requestHandler);
    HttpHost host = start();
    Client client = createClient(host);
    TestLogger logger = new TestLogger();
    client.enableLogging(logger);
    setupRequestHandler(disableLogging(setOKJsonResponse("testConnection.json"), client));
    try {
        TestConnection response = client.merchant("1234").services().testconnection();
        Assert.assertNotNull(response);
        Assert.assertEquals("OK", response.getResult());
    } finally {
        client.close();
    }
    Assert.assertEquals(1, logger.entries.size());
    TestLoggerEntry requestEntry = logger.entries.get(0);
    Assert.assertNotNull(requestEntry.message);
    Assert.assertNull(requestEntry.thrown);
    assertRequest(requestEntry.message, "testConnection");
}
Also used : HttpHost(org.apache.http.HttpHost) Client(com.ingenico.connect.gateway.sdk.java.Client) TestConnection(com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection) Test(org.junit.Test)

Example 2 with TestConnection

use of com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnectionLoggerTest method testLogResponseOnly.

@Test
public void testLogResponseOnly() throws Exception {
    // logging is enabled after the request is logged but before the response is logged
    serverBootstrap.registerHandler("/v1/1234/services/testconnection", requestHandler);
    HttpHost host = start();
    Client client = createClient(host);
    TestLogger logger = new TestLogger();
    setupRequestHandler(enableLogging(setOKJsonResponse("testConnection.json"), client, logger));
    try {
        TestConnection response = client.merchant("1234").services().testconnection();
        Assert.assertNotNull(response);
        Assert.assertEquals("OK", response.getResult());
    } finally {
        client.close();
    }
    Assert.assertEquals(1, logger.entries.size());
    TestLoggerEntry responseEntry = logger.entries.get(0);
    Assert.assertNotNull(responseEntry.message);
    Assert.assertNull(responseEntry.thrown);
    assertResponse(responseEntry.message, "testConnection");
}
Also used : HttpHost(org.apache.http.HttpHost) Client(com.ingenico.connect.gateway.sdk.java.Client) TestConnection(com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection) Test(org.junit.Test)

Example 3 with TestConnection

use of com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnectionLoggerTest method testLoggingTestConnection.

@Test
public void testLoggingTestConnection() throws Exception {
    // GET with no query params
    serverBootstrap.registerHandler("/v1/1234/services/testconnection", requestHandler);
    HttpHost host = start();
    Client client = createClient(host);
    TestLogger logger = new TestLogger();
    client.enableLogging(logger);
    setupRequestHandler(setOKJsonResponse("testConnection.json"));
    try {
        TestConnection response = client.merchant("1234").services().testconnection();
        Assert.assertNotNull(response);
        Assert.assertEquals("OK", response.getResult());
    } 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");
}
Also used : HttpHost(org.apache.http.HttpHost) Client(com.ingenico.connect.gateway.sdk.java.Client) TestConnection(com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection) Test(org.junit.Test)

Aggregations

Client (com.ingenico.connect.gateway.sdk.java.Client)3 TestConnection (com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection)3 HttpHost (org.apache.http.HttpHost)3 Test (org.junit.Test)3