Search in sources :

Example 1 with BasicAuthenticator

use of com.ibm.cloud.sdk.core.security.BasicAuthenticator in project cloudant-java-sdk by IBM.

the class SdkTimeoutTest method testBasicAuthTimeout.

@Test
void testBasicAuthTimeout() throws NoSuchFieldException, IllegalAccessException {
    BasicAuthenticator basicAuth = new BasicAuthenticator.Builder().username("user").password("psw").build();
    CloudantBaseService myService = createCloudantBaseService(basicAuth, "https://cloudant.example");
    Request testRequest = createTestRequest(myService);
    for (int i = 0; i < 2; i++) {
        if (i == 1) {
            setCustomTimeout(myService, testCases[i]);
        }
        RealCall testRequestCall = createServiceCall(myService, testRequest);
        assertEquals(TimeUnit.MILLISECONDS.toSeconds(testRequestCall.getClient().readTimeoutMillis()), testCases[i]);
    }
}
Also used : RealCall(okhttp3.internal.connection.RealCall) BasicAuthenticator(com.ibm.cloud.sdk.core.security.BasicAuthenticator) Request(okhttp3.Request) Test(org.testng.annotations.Test)

Example 2 with BasicAuthenticator

use of com.ibm.cloud.sdk.core.security.BasicAuthenticator in project java-sdk by watson-developer-cloud.

the class AssistantServiceIT method pingBadCredentialsThrowsException.

/**
 * Ping bad credentials throws exception.
 */
@Test(expected = UnauthorizedException.class)
public void pingBadCredentialsThrowsException() {
    Assistant badService = new Assistant("2019-02-28", new BasicAuthenticator("foo", "bar"));
    MessageOptions options = new MessageOptions.Builder(workspaceId).build();
    badService.message(options).execute().getResult();
}
Also used : BasicAuthenticator(com.ibm.cloud.sdk.core.security.BasicAuthenticator) Test(org.junit.Test)

Example 3 with BasicAuthenticator

use of com.ibm.cloud.sdk.core.security.BasicAuthenticator in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method badCredentialsThrowsException.

/**
 * Bad credentials throws exception.
 */
@Test(expected = UnauthorizedException.class)
public void badCredentialsThrowsException() {
    Discovery badService = new Discovery("2019-04-30", new BasicAuthenticator("foo", "bar"));
    badService.listEnvironments(null).execute().getResult();
}
Also used : BasicAuthenticator(com.ibm.cloud.sdk.core.security.BasicAuthenticator) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Aggregations

BasicAuthenticator (com.ibm.cloud.sdk.core.security.BasicAuthenticator)3 Test (org.junit.Test)2 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 Request (okhttp3.Request)1 RealCall (okhttp3.internal.connection.RealCall)1 Test (org.testng.annotations.Test)1