Search in sources :

Example 1 with CreateEnvironmentOptions

use of com.ibm.watson.discovery.v1.model.CreateEnvironmentOptions 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 CreateEnvironmentOptions

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

the class Discovery method createEnvironment.

/**
 * Create an environment.
 *
 * <p>Creates a new environment for private data. An environment must be created before
 * collections can be created.
 *
 * <p>**Note**: You can create only one environment for private data per service instance. An
 * attempt to create another environment results in an error.
 *
 * @param createEnvironmentOptions the {@link CreateEnvironmentOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Environment}
 */
public ServiceCall<Environment> createEnvironment(CreateEnvironmentOptions createEnvironmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createEnvironmentOptions, "createEnvironmentOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createEnvironment");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", createEnvironmentOptions.name());
    if (createEnvironmentOptions.description() != null) {
        contentJson.addProperty("description", createEnvironmentOptions.description());
    }
    if (createEnvironmentOptions.size() != null) {
        contentJson.addProperty("size", createEnvironmentOptions.size());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Environment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Environment>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Environment(com.ibm.watson.discovery.v1.model.Environment)

Example 3 with CreateEnvironmentOptions

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

the class DiscoveryServiceIT method createEnvironmentIsSuccessful.

@Test
@Ignore("Only 1 BYOD environment allowed per service instance, so we cannot create more")
public void createEnvironmentIsSuccessful() {
    String environmentName = uniqueName + "-environment";
    CreateEnvironmentOptions createOptions = new CreateEnvironmentOptions.Builder().name(environmentName).size(FREE).build();
    Environment createResponse = createEnvironment(createOptions);
    assertEquals(environmentName, createResponse.getName());
}
Also used : CreateEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) Ignore(org.junit.Ignore) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 4 with CreateEnvironmentOptions

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

the class DiscoveryServiceIT method deleteEnvironmentIsSuccessful.

@Test
@Ignore("Only 1 BYOD environment allowed per service instance, so do not delete it")
public void deleteEnvironmentIsSuccessful() {
    String environmentName = uniqueName + "-environment";
    CreateEnvironmentOptions createOptions = new CreateEnvironmentOptions.Builder().name(environmentName).size(FREE).build();
    Environment createResponse = createEnvironment(createOptions);
    DeleteEnvironmentOptions deleteOptions = new DeleteEnvironmentOptions.Builder(createResponse.getEnvironmentId()).build();
    deleteEnvironment(deleteOptions);
}
Also used : CreateEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) DeleteEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteEnvironmentOptions) Ignore(org.junit.Ignore) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 5 with CreateEnvironmentOptions

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

the class DiscoveryServiceIT method updateEnvironmentIsSuccessful.

@Test
@Ignore("Only 1 BYOD environment allowed per service instance, so we cannot create more")
public void updateEnvironmentIsSuccessful() {
    String environmentName = uniqueName + "-environment";
    CreateEnvironmentOptions createOptions = new CreateEnvironmentOptions.Builder().name(environmentName).size(FREE).build();
    Environment createResponse = createEnvironment(createOptions);
    String randomDescription = UUID.randomUUID().toString() + " appbuilder tests";
    UpdateEnvironmentOptions.Builder updateBuilder = new UpdateEnvironmentOptions.Builder(createResponse.getEnvironmentId()).name(environmentName);
    updateBuilder.description(randomDescription);
    Environment updateResponse = discovery.updateEnvironment(updateBuilder.build()).execute();
    assertEquals(randomDescription, updateResponse.getDescription());
}
Also used : UpdateEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateEnvironmentOptions) CreateEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) Ignore(org.junit.Ignore) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

CreateEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions)5 Environment (com.ibm.watson.developer_cloud.discovery.v1.model.Environment)5 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)4 Test (org.junit.Test)4 Environment (com.ibm.watson.discovery.v1.model.Environment)3 Ignore (org.junit.Ignore)3 ListEnvironmentsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsOptions)2 ListEnvironmentsResponse (com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse)2 CreateEnvironmentOptions (com.ibm.watson.discovery.v1.model.CreateEnvironmentOptions)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)1 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)1 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