Search in sources :

Example 1 with ListEnvironmentsResponse

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

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

the class DiscoveryServiceIT method listEnvironmentsIsSuccessful.

@Test
public void listEnvironmentsIsSuccessful() {
    ListEnvironmentsOptions listOptions = new ListEnvironmentsOptions.Builder().build();
    ListEnvironmentsResponse listResponse = discovery.listEnvironments(listOptions).execute();
    assertFalse(listResponse.getEnvironments().isEmpty());
}
Also used : ListEnvironmentsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse) ListEnvironmentsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 3 with ListEnvironmentsResponse

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

the class DiscoveryServiceTest method listEnvironmentsIsSuccessful.

@Test
public void listEnvironmentsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(envsResp));
    ListEnvironmentsResponse response = discoveryService.listEnvironments(null).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(ENV2_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(envsResp, response);
}
Also used : ListEnvironmentsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 4 with ListEnvironmentsResponse

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

the class DiscoveryServiceIT method listEnvironmentsHasNewsEnvironment.

@Test
public void listEnvironmentsHasNewsEnvironment() {
    ListEnvironmentsOptions listOptions = new ListEnvironmentsOptions.Builder().build();
    ListEnvironmentsResponse listResponse = discovery.listEnvironments(listOptions).execute();
    boolean foundNews = false;
    for (Environment environment : listResponse.getEnvironments()) {
        if (environment.isReadOnly()) {
            foundNews = true;
            break;
        }
    }
    assertTrue(foundNews);
}
Also used : ListEnvironmentsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) ListEnvironmentsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 5 with ListEnvironmentsResponse

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

the class DiscoveryTest method testListEnvironmentsWOptions.

// Test the listEnvironments operation with a valid options model parameter
@Test
public void testListEnvironmentsWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"environments\": [{\"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 listEnvironmentsPath = "/v1/environments";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListEnvironmentsOptions model
    ListEnvironmentsOptions listEnvironmentsOptionsModel = new ListEnvironmentsOptions.Builder().name("testString").build();
    // Invoke listEnvironments() with a valid options model and verify the result
    Response<ListEnvironmentsResponse> response = discoveryService.listEnvironments(listEnvironmentsOptionsModel).execute();
    assertNotNull(response);
    ListEnvironmentsResponse 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, listEnvironmentsPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(query.get("name"), "testString");
}
Also used : ListEnvironmentsResponse(com.ibm.watson.discovery.v1.model.ListEnvironmentsResponse) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListEnvironmentsOptions(com.ibm.watson.discovery.v1.model.ListEnvironmentsOptions) Test(org.testng.annotations.Test)

Aggregations

ListEnvironmentsResponse (com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse)7 ListEnvironmentsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsOptions)5 Test (org.junit.Test)5 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)4 Environment (com.ibm.watson.developer_cloud.discovery.v1.model.Environment)4 ListEnvironmentsResponse (com.ibm.watson.discovery.v1.model.ListEnvironmentsResponse)4 CreateEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions)2 GetEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetEnvironmentOptions)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 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 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)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