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