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