Search in sources :

Example 1 with UpdateEnvironmentOptions

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

the class DiscoveryServiceTest method updateEnvironmentIsSuccessful.

/**
 * Update environment is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void updateEnvironmentIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(updateEnvResp));
    UpdateEnvironmentOptions updateOptions = new UpdateEnvironmentOptions.Builder(environmentId).name(environmentName).description(environmentDesc).size(UpdateEnvironmentOptions.Size.L).build();
    assertEquals(environmentId, updateOptions.environmentId());
    assertEquals(environmentName, updateOptions.name());
    assertEquals(environmentDesc, updateOptions.description());
    assertEquals(UpdateEnvironmentOptions.Size.L, updateOptions.size());
    Environment response = discoveryService.updateEnvironment(updateOptions).execute().getResult();
    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.discovery.v1.model.UpdateEnvironmentOptions) Environment(com.ibm.watson.discovery.v1.model.Environment) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 2 with UpdateEnvironmentOptions

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

the class DiscoveryTest method testUpdateEnvironmentWOptions.

// Test the updateEnvironment operation with a valid options model parameter
@Test
public void testUpdateEnvironmentWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"environment_id\": \"environmentId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"status\": \"active\", \"read_only\": true, \"size\": \"LT\", \"requested_size\": \"requestedSize\", \"index_capacity\": {\"documents\": {\"available\": 9, \"maximum_allowed\": 14}, \"disk_usage\": {\"used_bytes\": 9, \"maximum_allowed_bytes\": 19}, \"collections\": {\"available\": 9, \"maximum_allowed\": 14}}, \"search_status\": {\"scope\": \"scope\", \"status\": \"NO_DATA\", \"status_description\": \"statusDescription\", \"last_trained\": \"2019-01-01\"}}";
    String updateEnvironmentPath = "/v1/environments/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the UpdateEnvironmentOptions model
    UpdateEnvironmentOptions updateEnvironmentOptionsModel = new UpdateEnvironmentOptions.Builder().environmentId("testString").name("testString").description("testString").size("S").build();
    // Invoke updateEnvironment() with a valid options model and verify the result
    Response<Environment> response = discoveryService.updateEnvironment(updateEnvironmentOptionsModel).execute();
    assertNotNull(response);
    Environment responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PUT");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateEnvironmentPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateEnvironmentOptions(com.ibm.watson.discovery.v1.model.UpdateEnvironmentOptions) Environment(com.ibm.watson.discovery.v1.model.Environment) Test(org.testng.annotations.Test)

Example 3 with UpdateEnvironmentOptions

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

Aggregations

Environment (com.ibm.watson.discovery.v1.model.Environment)3 UpdateEnvironmentOptions (com.ibm.watson.discovery.v1.model.UpdateEnvironmentOptions)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1