Search in sources :

Example 1 with ConvertAmountParams

use of com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams 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]);
    }
}
Also used : ConvertAmountParams(com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams) ConvertAmount(com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount) CommunicatorConfiguration(com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration) Client(com.ingenico.connect.gateway.sdk.java.Client) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 2 with ConvertAmountParams

use of com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams 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");
}
Also used : ConvertAmountParams(com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams) ConvertAmount(com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount) HttpHost(org.apache.http.HttpHost) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 3 with ConvertAmountParams

use of com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams 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();
    }
}
Also used : ConvertAmountParams(com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams) ConvertAmount(com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 4 with ConvertAmountParams

use of com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams 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();
    }
}
Also used : ConvertAmountParams(com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams) ConvertAmount(com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount) ServicesClient(com.ingenico.connect.gateway.sdk.java.merchant.services.ServicesClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Client(com.ingenico.connect.gateway.sdk.java.Client) ServicesClient(com.ingenico.connect.gateway.sdk.java.merchant.services.ServicesClient) CommunicatorConfiguration(com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration) Test(org.junit.Test)

Aggregations

Client (com.ingenico.connect.gateway.sdk.java.Client)4 ConvertAmount (com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount)4 ConvertAmountParams (com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams)4 Test (org.junit.Test)4 CommunicatorConfiguration (com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration)2 ServicesClient (com.ingenico.connect.gateway.sdk.java.merchant.services.ServicesClient)1 Authenticator (java.net.Authenticator)1 PasswordAuthentication (java.net.PasswordAuthentication)1 HttpHost (org.apache.http.HttpHost)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1