Search in sources :

Example 66 with Client

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

the class PaymentsClientTest method testCreateReferenceError.

/**
 * Tests that a 409 failure response with a duplicate request code but without an idempotence key will throw a
 * {@link ReferenceException}.
 */
@Test
@SuppressWarnings("resource")
public void testCreateReferenceError() {
    Client client = Factory.createClient(session);
    String responseBody = getResource("duplicate_request.json");
    whenPost().thenReturn(new Response(409, responseBody, null));
    CreatePaymentRequest body = createRequest();
    try {
        client.merchant("merchantId").payments().create(body);
        Assert.fail("Expected ApiException");
    } catch (ReferenceException 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) ReferenceException(com.ingenico.connect.gateway.sdk.java.ReferenceException) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 67 with Client

use of com.ingenico.connect.gateway.sdk.java.Client 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)

Example 68 with Client

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

the class PaymentsClientTest method testCreateIdempotenceError.

/**
 * Tests that a 409 failure response with a duplicate request code and an idempotence key will throw an {@link IdempotenceException}.
 */
@Test
@SuppressWarnings("resource")
public void testCreateIdempotenceError() {
    Client client = Factory.createClient(session);
    String responseBody = getResource("duplicate_request.json");
    whenPost().thenReturn(new Response(409, responseBody, null));
    CreatePaymentRequest body = createRequest();
    CallContext context = new CallContext().withIdempotenceKey("key");
    try {
        client.merchant("merchantId").payments().create(body, context);
        Assert.fail("Expected ApiException");
    } catch (IdempotenceException e) {
        Assert.assertTrue(e.toString().contains(responseBody));
        Assert.assertEquals(context.getIdempotenceKey(), e.getIdempotenceKey());
    }
}
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) CallContext(com.ingenico.connect.gateway.sdk.java.CallContext) IdempotenceException(com.ingenico.connect.gateway.sdk.java.IdempotenceException) Test(org.junit.Test)

Example 69 with Client

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

the class DefaultConnectionIdempotenceTest method createClient.

@SuppressWarnings("resource")
private Client createClient(HttpHost host) {
    Connection connection = new DefaultConnection(500, 500);
    Authenticator authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret");
    MetaDataProvider metaDataProvider = new MetaDataProvider("Ingenico");
    Session session = new Session(URI.create(host.toURI()), connection, authenticator, metaDataProvider);
    Communicator communicator = Factory.createCommunicator(session);
    Client client = Factory.createClient(communicator);
    return client;
}
Also used : MetaDataProvider(com.ingenico.connect.gateway.sdk.java.MetaDataProvider) Communicator(com.ingenico.connect.gateway.sdk.java.Communicator) Connection(com.ingenico.connect.gateway.sdk.java.Connection) Client(com.ingenico.connect.gateway.sdk.java.Client) Authenticator(com.ingenico.connect.gateway.sdk.java.Authenticator) Session(com.ingenico.connect.gateway.sdk.java.Session)

Example 70 with Client

use of com.ingenico.connect.gateway.sdk.java.Client 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)70 Test (org.junit.Test)35 CreatePaymentRequest (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest)19 HttpHost (org.apache.http.HttpHost)17 CreatePaymentResponse (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse)14 Address (com.ingenico.connect.gateway.sdk.java.domain.definitions.Address)12 AmountOfMoney (com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney)11 Response (com.ingenico.connect.gateway.sdk.java.Response)9 CallContext (com.ingenico.connect.gateway.sdk.java.CallContext)7 Customer (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Customer)6 Order (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Order)6 DeclinedPaymentException (com.ingenico.connect.gateway.sdk.java.DeclinedPaymentException)5 ConvertAmount (com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount)5 HashMap (java.util.HashMap)5 ApiException (com.ingenico.connect.gateway.sdk.java.ApiException)4 Card (com.ingenico.connect.gateway.sdk.java.domain.definitions.Card)4 CompanyInformation (com.ingenico.connect.gateway.sdk.java.domain.definitions.CompanyInformation)4 TestConnection (com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection)4 ConvertAmountParams (com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams)4 ArrayList (java.util.ArrayList)4