Search in sources :

Example 1 with DefaultConnection

use of com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnection in project connect-sdk-java by Ingenico-ePayments.

the class SDKProxyTest method assertProxySet.

@SuppressWarnings("resource")
private void assertProxySet(ApiResource resource, ProxyConfiguration proxyConfiguration) {
    Communicator communicator = getField(resource, "communicator", Communicator.class);
    Session session = getField(communicator, "session", Session.class);
    DefaultConnection connection = getField(session, "connection", DefaultConnection.class);
    CloseableHttpClient httpClient = getField(connection, "httpClient", CloseableHttpClient.class);
    DefaultProxyRoutePlanner routePlanner = getField(httpClient, "routePlanner", DefaultProxyRoutePlanner.class);
    HttpHost proxy = getField(routePlanner, "proxy", HttpHost.class);
    Assert.assertEquals(proxyConfiguration.getScheme(), proxy.getSchemeName());
    Assert.assertEquals(proxyConfiguration.getPort(), proxy.getPort());
    BasicCredentialsProvider credentialsProvider = getField(httpClient, "credentialsProvider", BasicCredentialsProvider.class);
    AuthScope authScope = new AuthScope(proxy);
    Credentials credentials = credentialsProvider.getCredentials(authScope);
    Assert.assertTrue(credentials instanceof UsernamePasswordCredentials);
    UsernamePasswordCredentials usernamePasswordCredentials = (UsernamePasswordCredentials) credentials;
    Assert.assertEquals(proxyConfiguration.getUsername(), usernamePasswordCredentials.getUserName());
    Assert.assertEquals(proxyConfiguration.getPassword(), usernamePasswordCredentials.getPassword());
}
Also used : Communicator(com.ingenico.connect.gateway.sdk.java.Communicator) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) DefaultConnection(com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnection) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) DefaultProxyRoutePlanner(org.apache.http.impl.conn.DefaultProxyRoutePlanner) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Credentials(org.apache.http.auth.Credentials) Session(com.ingenico.connect.gateway.sdk.java.Session) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with DefaultConnection

use of com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnection in project connect-sdk-java by Ingenico-ePayments.

the class FactoryTest method testCreateCommunicator.

@Test
public void testCreateCommunicator() {
    @SuppressWarnings("resource") Communicator communicator = Factory.createCommunicator(PROPERTIES_URI, API_KEY_ID, SECRET_API_KEY);
    Assert.assertSame(DefaultMarshaller.INSTANCE, communicator.getMarshaller());
    Session session = ReflectionUtil.getField(communicator, "session", Session.class);
    @SuppressWarnings("resource") Connection connection = session.getConnection();
    Assert.assertTrue(connection instanceof DefaultConnection);
    DefaultConnectionTest.assertConnection((DefaultConnection) connection, -1, -1, 100, null);
    Authenticator authenticator = session.getAuthenticator();
    Assert.assertTrue(authenticator instanceof DefaultAuthenticator);
    Assert.assertEquals(AuthorizationType.V1HMAC, ReflectionUtil.getField(authenticator, "authorizationType", AuthorizationType.class));
    Assert.assertEquals(API_KEY_ID, ReflectionUtil.getField(authenticator, "apiKeyId", String.class));
    Assert.assertEquals(SECRET_API_KEY, ReflectionUtil.getField(authenticator, "secretApiKey", String.class));
    MetaDataProvider metaDataProvider = session.getMetaDataProvider();
    Assert.assertEquals(MetaDataProvider.class, metaDataProvider.getClass());
    Collection<RequestHeader> requestHeaders = metaDataProvider.getServerMetaDataHeaders();
    Assert.assertEquals(1, requestHeaders.size());
    RequestHeader requestHeader = requestHeaders.iterator().next();
    Assert.assertEquals("X-GCS-ServerMetaInfo", requestHeader.getName());
}
Also used : DefaultConnection(com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnection) DefaultConnection(com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnection) DefaultAuthenticator(com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultAuthenticator) AuthorizationType(com.ingenico.connect.gateway.sdk.java.defaultimpl.AuthorizationType) DefaultAuthenticator(com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultAuthenticator) DefaultConnectionTest(com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnectionTest) Test(org.junit.Test)

Aggregations

DefaultConnection (com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnection)2 Communicator (com.ingenico.connect.gateway.sdk.java.Communicator)1 Session (com.ingenico.connect.gateway.sdk.java.Session)1 AuthorizationType (com.ingenico.connect.gateway.sdk.java.defaultimpl.AuthorizationType)1 DefaultAuthenticator (com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultAuthenticator)1 DefaultConnectionTest (com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnectionTest)1 HttpHost (org.apache.http.HttpHost)1 AuthScope (org.apache.http.auth.AuthScope)1 Credentials (org.apache.http.auth.Credentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 DefaultProxyRoutePlanner (org.apache.http.impl.conn.DefaultProxyRoutePlanner)1 Test (org.junit.Test)1