Search in sources :

Example 11 with Environment

use of com.ibm.watson.discovery.v1.model.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
/**
 * Creates the environment is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void createEnvironmentIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(createEnvResp));
    CreateEnvironmentOptions.Builder createRequestBuilder = new CreateEnvironmentOptions.Builder().name(environmentName).size(CreateEnvironmentOptions.Size.XS);
    createRequestBuilder.description(environmentDesc);
    Environment response = discoveryService.createEnvironment(createRequestBuilder.build()).execute().getResult();
    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.discovery.v1.model.CreateEnvironmentOptions) Environment(com.ibm.watson.discovery.v1.model.Environment) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 12 with Environment

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

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

the class Discovery method updateEnvironment.

/**
 * Update an environment.
 *
 * <p>Updates an environment. The environment's **name** and **description** parameters can be
 * changed. You must specify a **name** for the environment.
 *
 * @param updateEnvironmentOptions the {@link UpdateEnvironmentOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Environment}
 */
public ServiceCall<Environment> updateEnvironment(UpdateEnvironmentOptions updateEnvironmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateEnvironmentOptions, "updateEnvironmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", updateEnvironmentOptions.environmentId());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "updateEnvironment");
    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();
    if (updateEnvironmentOptions.name() != null) {
        contentJson.addProperty("name", updateEnvironmentOptions.name());
    }
    if (updateEnvironmentOptions.description() != null) {
        contentJson.addProperty("description", updateEnvironmentOptions.description());
    }
    if (updateEnvironmentOptions.size() != null) {
        contentJson.addProperty("size", updateEnvironmentOptions.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) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Environment(com.ibm.watson.discovery.v1.model.Environment)

Example 14 with Environment

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

the class Discovery method deleteEnvironment.

/**
 * Delete environment.
 *
 * @param deleteEnvironmentOptions the {@link DeleteEnvironmentOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link DeleteEnvironmentResponse}
 */
public ServiceCall<DeleteEnvironmentResponse> deleteEnvironment(DeleteEnvironmentOptions deleteEnvironmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteEnvironmentOptions, "deleteEnvironmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", deleteEnvironmentOptions.environmentId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "deleteEnvironment");
    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));
    ResponseConverter<DeleteEnvironmentResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteEnvironmentResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DeleteEnvironmentResponse(com.ibm.watson.discovery.v1.model.DeleteEnvironmentResponse)

Example 15 with Environment

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

the class DiscoveryServiceTest method updateEnvironmentIsSuccessful.

@Test
public void updateEnvironmentIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(updateEnvResp));
    UpdateEnvironmentOptions.Builder updateBuilder = new UpdateEnvironmentOptions.Builder(environmentId).name(environmentName);
    updateBuilder.description(environmentDesc);
    Environment response = discoveryService.updateEnvironment(updateBuilder.build()).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(ENV1_PATH, request.getPath());
    assertEquals(PUT, request.getMethod());
    assertEquals(updateEnvResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UpdateEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateEnvironmentOptions) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

Environment (com.ibm.watson.developer_cloud.discovery.v1.model.Environment)15 Environment (com.ibm.watson.discovery.v1.model.Environment)12 Test (org.junit.Test)11 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)10 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)7 CreateEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions)6 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 GetEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetEnvironmentOptions)5 JsonObject (com.google.gson.JsonObject)4 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)4 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 CreateEnvironmentOptions (com.ibm.watson.discovery.v1.model.CreateEnvironmentOptions)3 DeleteEnvironmentResponse (com.ibm.watson.discovery.v1.model.DeleteEnvironmentResponse)3 GetEnvironmentOptions (com.ibm.watson.discovery.v1.model.GetEnvironmentOptions)3 Ignore (org.junit.Ignore)3 UpdateEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.UpdateEnvironmentOptions)2 Collection (com.ibm.watson.discovery.v1.model.Collection)2