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