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