Search in sources :

Example 1 with NoAuthAuthenticator

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

the class SdkTimeoutTest method testNoAuthTimeout.

// Test implementations
@Test
void testNoAuthTimeout() throws NoSuchFieldException, IllegalAccessException {
    NoAuthAuthenticator noAuth = new NoAuthAuthenticator();
    CloudantBaseService myService = createCloudantBaseService(noAuth, "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 : NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) RealCall(okhttp3.internal.connection.RealCall) Request(okhttp3.Request) Test(org.testng.annotations.Test)

Example 2 with NoAuthAuthenticator

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

the class ValidationTest method validatesDocumentIdAtLongServicePath.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".+_testDocument.+")
void validatesDocumentIdAtLongServicePath() {
    CloudantBaseService cloudantBaseService = new CloudantBaseService(null, new NoAuthAuthenticator()) {
    };
    cloudantBaseService.setServiceUrl("https://cloudant.example/some/proxy/path");
    HttpUrl requestUrl = HttpUrl.parse(cloudantBaseService.getServiceUrl()).newBuilder().addPathSegment(dbName).addPathSegment(docId).build();
    Request.Builder rb = new Request.Builder().url(requestUrl).get();
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        rb.header(header.getKey(), header.getValue());
    }
    cloudantBaseService.createServiceCall(rb.build(), null);
}
Also used : NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.testng.annotations.Test)

Example 3 with NoAuthAuthenticator

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

the class ValidationTest method validatesDocumentIdAtLongServicePathAfterChange.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".+_testDocument.+")
void validatesDocumentIdAtLongServicePathAfterChange() {
    CloudantBaseService cloudantBaseService = new CloudantBaseService(null, new NoAuthAuthenticator()) {
    };
    cloudantBaseService.setServiceUrl("https://cloudant.example");
    HttpUrl requestUrl = HttpUrl.parse(cloudantBaseService.getServiceUrl()).newBuilder().addPathSegment(dbName).addPathSegment(docId).build();
    Request.Builder rb = new Request.Builder().url(requestUrl).get();
    cloudantBaseService.createServiceCall(rb.build(), null);
    cloudantBaseService.setServiceUrl("https://cloudant.example/some/proxy/path");
    requestUrl = HttpUrl.parse(cloudantBaseService.getServiceUrl()).newBuilder().addPathSegment(dbName).addPathSegment(docId).build();
    rb = new Request.Builder().url(requestUrl).get();
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        rb.header(header.getKey(), header.getValue());
    }
    cloudantBaseService.createServiceCall(rb.build(), null);
}
Also used : NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.testng.annotations.Test)

Example 4 with NoAuthAuthenticator

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

the class ValidationTest method validatesDocumentId.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".+_testDocument.+")
void validatesDocumentId() {
    CloudantBaseService cloudantBaseService = new CloudantBaseService(null, new NoAuthAuthenticator()) {
    };
    cloudantBaseService.setServiceUrl("https://cloudant.example");
    HttpUrl requestUrl = HttpUrl.parse(cloudantBaseService.getServiceUrl()).newBuilder().addPathSegment(dbName).addPathSegment(docId).build();
    Request.Builder rb = new Request.Builder().url(requestUrl).get();
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        rb.header(header.getKey(), header.getValue());
    }
    cloudantBaseService.createServiceCall(rb.build(), null);
}
Also used : NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.testng.annotations.Test)

Example 5 with NoAuthAuthenticator

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

the class NaturalLanguageClassifierTest method constructClientService.

public void constructClientService() throws Throwable {
    final String serviceName = "testService";
    final Authenticator authenticator = new NoAuthAuthenticator();
    naturalLanguageClassifierService = new NaturalLanguageClassifier(serviceName, authenticator);
    String url = server.url("/").toString();
    naturalLanguageClassifierService.setServiceUrl(url);
}
Also used : NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator)

Aggregations

NoAuthAuthenticator (com.ibm.cloud.sdk.core.security.NoAuthAuthenticator)20 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)14 Test (org.testng.annotations.Test)5 Request (okhttp3.Request)4 HttpUrl (okhttp3.HttpUrl)3 Collection (com.ibm.watson.discovery.v1.model.Collection)1 Configuration (com.ibm.watson.discovery.v1.model.Configuration)1 CreateEventResponse (com.ibm.watson.discovery.v1.model.CreateEventResponse)1 Credentials (com.ibm.watson.discovery.v1.model.Credentials)1 CredentialsList (com.ibm.watson.discovery.v1.model.CredentialsList)1 DeleteCollectionResponse (com.ibm.watson.discovery.v1.model.DeleteCollectionResponse)1 DeleteConfigurationResponse (com.ibm.watson.discovery.v1.model.DeleteConfigurationResponse)1 DeleteCredentials (com.ibm.watson.discovery.v1.model.DeleteCredentials)1 DeleteDocumentResponse (com.ibm.watson.discovery.v1.model.DeleteDocumentResponse)1 DeleteEnvironmentResponse (com.ibm.watson.discovery.v1.model.DeleteEnvironmentResponse)1 DocumentAccepted (com.ibm.watson.discovery.v1.model.DocumentAccepted)1 DocumentStatus (com.ibm.watson.discovery.v1.model.DocumentStatus)1 Environment (com.ibm.watson.discovery.v1.model.Environment)1 Expansions (com.ibm.watson.discovery.v1.model.Expansions)1 Gateway (com.ibm.watson.discovery.v1.model.Gateway)1