Search in sources :

Example 6 with Environment

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

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

the class DiscoveryTest method testGetEnvironmentWOptions.

// Test the getEnvironment operation with a valid options model parameter
@Test
public void testGetEnvironmentWOptions() 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 getEnvironmentPath = "/v1/environments/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetEnvironmentOptions model
    GetEnvironmentOptions getEnvironmentOptionsModel = new GetEnvironmentOptions.Builder().environmentId("testString").build();
    // Invoke getEnvironment() with a valid options model and verify the result
    Response<Environment> response = discoveryService.getEnvironment(getEnvironmentOptionsModel).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(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getEnvironmentPath);
    // 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) GetEnvironmentOptions(com.ibm.watson.discovery.v1.model.GetEnvironmentOptions) Environment(com.ibm.watson.discovery.v1.model.Environment) Test(org.testng.annotations.Test)

Example 8 with Environment

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

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

the class DiscoveryServiceTest method getEnvironmentFails1.

/**
 * Gets the environment fails 1.
 */
@Test(expected = IllegalArgumentException.class)
public void getEnvironmentFails1() {
    GetEnvironmentOptions getRequest = new GetEnvironmentOptions.Builder().build();
    @SuppressWarnings("unused") Environment response = discoveryService.getEnvironment(getRequest).execute().getResult();
}
Also used : GetEnvironmentOptions(com.ibm.watson.discovery.v1.model.GetEnvironmentOptions) Environment(com.ibm.watson.discovery.v1.model.Environment) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 10 with Environment

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

the class DiscoveryServiceTest method getEnvironmentIsSuccessful.

/**
 * Gets the environment is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
// Environment tests
@Test
public void getEnvironmentIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(envResp));
    GetEnvironmentOptions getRequest = new GetEnvironmentOptions.Builder(environmentId).build();
    Environment response = discoveryService.getEnvironment(getRequest).execute().getResult();
    final RecordedRequest request = server.takeRequest();
    assertEquals(ENV1_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(envResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetEnvironmentOptions(com.ibm.watson.discovery.v1.model.GetEnvironmentOptions) Environment(com.ibm.watson.discovery.v1.model.Environment) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

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