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));
}
}
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));
}
}
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());
}
}
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;
}
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");
}
Aggregations