Search in sources :

Example 1 with Environment

use of com.ibm.watson.developer_cloud.discovery.v1.model.environment.Environment in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    // get the properties
    dummyTest = new DiscoveryServiceIT();
    String username = dummyTest.getProperty("discovery.username");
    Assume.assumeFalse("config.properties doesn't have valid credentials.", (username == null) || username.equals(PLACEHOLDER));
    dummyTest.setup();
    ListEnvironmentsOptions listOptions = new ListEnvironmentsOptions.Builder().build();
    ListEnvironmentsResponse listResponse = dummyTest.discovery.listEnvironments(listOptions).execute();
    for (Environment environment : listResponse.getEnvironments()) {
        // look for an existing environment that isn't read only
        if (!environment.isReadOnly()) {
            environmentId = environment.getEnvironmentId();
            break;
        }
    }
    if (environmentId == null) {
        // no environment found, create a new one (assuming we are a FREE plan)
        String environmentName = "watson_developer_cloud_test_environment";
        CreateEnvironmentOptions createOptions = new CreateEnvironmentOptions.Builder().name(environmentName).size(FREE).build();
        Environment createResponse = dummyTest.discovery.createEnvironment(createOptions).execute();
        environmentId = createResponse.getEnvironmentId();
        WaitFor.Condition environmentReady = new EnvironmentReady(dummyTest.discovery, environmentId);
        WaitFor.waitFor(environmentReady, 30, TimeUnit.SECONDS, 500);
    }
    collectionId = dummyTest.setupTestDocuments();
}
Also used : ListEnvironmentsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse) WaitFor(com.ibm.watson.developer_cloud.util.WaitFor) CreateEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) ListEnvironmentsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsOptions) BeforeClass(org.junit.BeforeClass)

Example 2 with Environment

use of com.ibm.watson.developer_cloud.discovery.v1.model.environment.Environment in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method getEnvironmentIsSuccessful.

@Test
public void getEnvironmentIsSuccessful() {
    GetEnvironmentOptions getOptions = new GetEnvironmentOptions.Builder(environmentId).build();
    Environment getResponse = discovery.getEnvironment(getOptions).execute();
    assertEquals(environmentId, getResponse.getEnvironmentId());
}
Also used : GetEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetEnvironmentOptions) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 3 with Environment

use of com.ibm.watson.developer_cloud.discovery.v1.model.environment.Environment in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method createEnvironmentIsSuccessful.

// Deleted test for listEnvironments with null name as this does not fail in the current SDK
@Test
public void createEnvironmentIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(createEnvResp));
    CreateEnvironmentOptions.Builder createRequestBuilder = new CreateEnvironmentOptions.Builder().name(environmentName).size(THREE);
    createRequestBuilder.description(environmentDesc);
    Environment response = discoveryService.createEnvironment(createRequestBuilder.build()).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(ENV2_PATH, request.getPath());
    assertEquals(POST, request.getMethod());
    assertEquals(createEnvResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) CreateEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 4 with Environment

use of com.ibm.watson.developer_cloud.discovery.v1.model.environment.Environment in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method listEnvironmentsHasNewsEnvironment.

@Test
public void listEnvironmentsHasNewsEnvironment() {
    ListEnvironmentsOptions listOptions = new ListEnvironmentsOptions.Builder().build();
    ListEnvironmentsResponse listResponse = discovery.listEnvironments(listOptions).execute();
    boolean foundNews = false;
    for (Environment environment : listResponse.getEnvironments()) {
        if (environment.isReadOnly()) {
            foundNews = true;
            break;
        }
    }
    assertTrue(foundNews);
}
Also used : ListEnvironmentsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) ListEnvironmentsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 5 with Environment

use of com.ibm.watson.developer_cloud.discovery.v1.model.environment.Environment in project java-sdk by watson-developer-cloud.

the class Discovery method getEnvironment.

/**
 * Get environment info.
 *
 * @param getEnvironmentOptions the {@link GetEnvironmentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Environment}
 */
public ServiceCall<Environment> getEnvironment(GetEnvironmentOptions getEnvironmentOptions) {
    Validator.notNull(getEnvironmentOptions, "getEnvironmentOptions cannot be null");
    String[] pathSegments = { "v1/environments" };
    String[] pathParameters = { getEnvironmentOptions.environmentId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Environment.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment)

Aggregations

Environment (com.ibm.watson.developer_cloud.discovery.v1.model.Environment)15 Test (org.junit.Test)11 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)7 CreateEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions)6 GetEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetEnvironmentOptions)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 ListEnvironmentsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsOptions)4 ListEnvironmentsResponse (com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse)4 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Ignore (org.junit.Ignore)3 JsonObject (com.google.gson.JsonObject)2 UpdateEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.UpdateEnvironmentOptions)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)1 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)1 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)1 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)1 DeleteCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteCollectionOptions)1