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();
}
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);
}
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());
}
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);
}
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());
}
Aggregations