use of com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount in project connect-sdk-java by Ingenico-ePayments.
the class SystemProxyTest method test.
/**
* Smoke test for using a proxy configured through system properties.
*/
@Test
public void test() throws URISyntaxException, IOException {
final boolean[] authenticationCalled = { false };
final String username = System.getProperty("http.proxyUser");
final String password = System.getProperty("http.proxyPass");
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
authenticationCalled[0] = true;
return new PasswordAuthentication(username, password.toCharArray());
}
});
ConvertAmountParams request = new ConvertAmountParams();
request.setAmount(123L);
request.setSource("USD");
request.setTarget("EUR");
CommunicatorConfiguration configuration = getCommunicatorConfiguration().withProxyConfiguration(null);
Client client = Factory.createClient(configuration);
try {
ConvertAmount response = client.merchant("9991").services().convertAmount(request);
Assert.assertNotNull(response.getConvertedAmount());
} finally {
client.close();
}
// for https, authentication may not be required
if ("http".equalsIgnoreCase(configuration.getApiEndpoint().getScheme())) {
Assert.assertTrue("getPasswordAuthentication() should have been called", authenticationCalled[0]);
}
}
use of com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnectionLoggerTest method testLoggingConvertAmount.
@Test
public void testLoggingConvertAmount() throws Exception {
// GET with query params
serverBootstrap.registerHandler("/v1/1234/services/convert/amount", requestHandler);
HttpHost host = start();
Client client = createClient(host);
TestLogger logger = new TestLogger();
client.enableLogging(logger);
setupRequestHandler(setOKJsonResponse("convertAmount.json"));
try {
ConvertAmountParams query = new ConvertAmountParams();
query.setAmount(1000L);
query.setSource("EUR");
query.setTarget("USD");
ConvertAmount response = client.merchant("1234").services().convertAmount(query);
Assert.assertNotNull(response);
Assert.assertNotNull(response.getConvertedAmount());
} 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, "convertAmount");
}
use of com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount in project connect-sdk-java by Ingenico-ePayments.
the class ConvertAmountExample method example.
@SuppressWarnings("unused")
public void example() throws URISyntaxException, IOException {
Client client = getClient();
try {
ConvertAmountParams query = new ConvertAmountParams();
query.setSource("EUR");
query.setTarget("USD");
query.setAmount(100L);
ConvertAmount response = client.merchant("merchantId").services().convertAmount(query);
} finally {
client.close();
}
}
use of com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount in project connect-sdk-java by Ingenico-ePayments.
the class ConvertAmountTest method test.
/**
* Smoke test for convert amount service.
*/
@Test
public void test() throws URISyntaxException, IOException {
ConvertAmountParams request = new ConvertAmountParams();
request.setAmount(123L);
request.setSource("USD");
request.setTarget("EUR");
Client client = getClient();
try {
ConvertAmount response = client.merchant("9991").services().convertAmount(request);
Assert.assertNotNull(response.getConvertedAmount());
} finally {
client.close();
}
}
use of com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount in project connect-sdk-java by Ingenico-ePayments.
the class SDKProxyTest method test.
/**
* Smoke test for using a proxy configured through SDK properties.
*/
@Test
public void test() throws URISyntaxException, IOException {
ConvertAmountParams request = new ConvertAmountParams();
request.setAmount(123L);
request.setSource("USD");
request.setTarget("EUR");
Client client = getClientWithProxy();
try {
ServicesClient services = client.merchant("9991").services();
CommunicatorConfiguration configuration = getCommunicatorConfigurationWithProxy();
Assert.assertNotNull(configuration.getProxyConfiguration());
assertProxySet(services, configuration.getProxyConfiguration());
ConvertAmount response = services.convertAmount(request);
Assert.assertNotNull(response.getConvertedAmount());
} finally {
client.close();
}
}
Aggregations