Search in sources :

Example 1 with AuthClient

use of com.opengamma.sdk.common.auth.AuthClient 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 AuthClient

use of com.opengamma.sdk.common.auth.AuthClient 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 AuthClient

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

the class BasicTest method testAuthBad.

public void testAuthBad() {
    AuthClient mockAuth = new TestingAuthClient();
    try (ServiceInvoker serviceInvoker = ServiceInvoker.builder(BAD_CREDENTIALS).authClientFactory(inv -> mockAuth).build()) {
        Request testRequest = new Request.Builder().url(serviceInvoker.getServiceUrl().resolve("/test")).get().build();
        assertThrows(AuthenticationException.class, () -> serviceInvoker.getHttpClient().newCall(testRequest).execute());
    }
}
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) Request(okhttp3.Request)

Example 4 with AuthClient

use of com.opengamma.sdk.common.auth.AuthClient 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)4 AuthClient (com.opengamma.sdk.common.auth.AuthClient)4 AuthenticationException (com.opengamma.sdk.common.auth.AuthenticationException)4 Credentials (com.opengamma.sdk.common.auth.Credentials)4 OkHttpClient (okhttp3.OkHttpClient)4 Request (okhttp3.Request)4 Assert.assertEquals (org.testng.Assert.assertEquals)4 Assert.assertThrows (org.testng.Assert.assertThrows)4 Test (org.testng.annotations.Test)4