Search in sources :

Example 1 with Credentials

use of com.opengamma.sdk.common.auth.Credentials in project JavaSDK by OpenGamma.

the class BasicTest method testAuthGoodHttpFactory.

public void testAuthGoodHttpFactory() {
    AuthClient mockAuth = new TestingAuthClient();
    try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS).httpClientFactory(builder -> builder.addInterceptor(chain -> chain.proceed(chain.request())).followRedirects(false).build()).authClientFactory(inv -> mockAuth).build()) {
        assertEquals(invoker.getServiceUrl(), SERVICE_URL);
        // logging, user-agent & auth plus one from test
        assertEquals(invoker.getHttpClient().interceptors().size(), 4);
        assertEquals(invoker.getHttpClient().followRedirects(), false);
    }
}
Also used : AuthenticationException(com.opengamma.sdk.common.auth.AuthenticationException) Credentials(com.opengamma.sdk.common.auth.Credentials) Request(okhttp3.Request) OkHttpClient(okhttp3.OkHttpClient) SERVICE_URL(com.opengamma.sdk.common.ServiceInvoker.SERVICE_URL) Assert.assertThrows(org.testng.Assert.assertThrows) AuthClient(com.opengamma.sdk.common.auth.AuthClient) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) AuthClient(com.opengamma.sdk.common.auth.AuthClient)

Example 2 with Credentials

use of com.opengamma.sdk.common.auth.Credentials in project JavaSDK by OpenGamma.

the class BasicTest method testAuthGoodHttpClient.

public void testAuthGoodHttpClient() {
    AuthClient mockAuth = new TestingAuthClient();
    try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS).httpClient(new OkHttpClient()).authClientFactory(inv -> mockAuth).build()) {
        assertEquals(invoker.getServiceUrl(), SERVICE_URL);
        // user-agent & auth
        assertEquals(invoker.getHttpClient().interceptors().size(), 2);
    }
}
Also used : AuthenticationException(com.opengamma.sdk.common.auth.AuthenticationException) Credentials(com.opengamma.sdk.common.auth.Credentials) Request(okhttp3.Request) OkHttpClient(okhttp3.OkHttpClient) SERVICE_URL(com.opengamma.sdk.common.ServiceInvoker.SERVICE_URL) Assert.assertThrows(org.testng.Assert.assertThrows) AuthClient(com.opengamma.sdk.common.auth.AuthClient) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) OkHttpClient(okhttp3.OkHttpClient) AuthClient(com.opengamma.sdk.common.auth.AuthClient)

Example 3 with Credentials

use of com.opengamma.sdk.common.auth.Credentials in project JavaSDK by OpenGamma.

the class BasicTest method testAuthGood.

public void testAuthGood() {
    AuthClient mockAuth = new TestingAuthClient();
    @SuppressWarnings("resource") ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS).authClientFactory(inv -> mockAuth).build();
    assertEquals(invoker.getServiceUrl(), SERVICE_URL);
    assertEquals(invoker.getHttpClient().interceptors().size(), 3);
    assertEquals(invoker.getHttpClient().followRedirects(), true);
    assertEquals(invoker.getExecutor().isShutdown(), false);
    invoker.close();
    assertEquals(invoker.getExecutor().isShutdown(), true);
}
Also used : AuthenticationException(com.opengamma.sdk.common.auth.AuthenticationException) Credentials(com.opengamma.sdk.common.auth.Credentials) Request(okhttp3.Request) OkHttpClient(okhttp3.OkHttpClient) SERVICE_URL(com.opengamma.sdk.common.ServiceInvoker.SERVICE_URL) Assert.assertThrows(org.testng.Assert.assertThrows) AuthClient(com.opengamma.sdk.common.auth.AuthClient) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) AuthClient(com.opengamma.sdk.common.auth.AuthClient)

Aggregations

SERVICE_URL (com.opengamma.sdk.common.ServiceInvoker.SERVICE_URL)3 AuthClient (com.opengamma.sdk.common.auth.AuthClient)3 AuthenticationException (com.opengamma.sdk.common.auth.AuthenticationException)3 Credentials (com.opengamma.sdk.common.auth.Credentials)3 OkHttpClient (okhttp3.OkHttpClient)3 Request (okhttp3.Request)3 Assert.assertEquals (org.testng.Assert.assertEquals)3 Assert.assertThrows (org.testng.Assert.assertThrows)3 Test (org.testng.annotations.Test)3