use of com.ibm.watson.discovery.v1.model.Environment in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method setup.
/**
* Setup.
*
* @throws Exception the exception
*/
@Before
public void setup() throws Exception {
super.setUp();
discoveryService = new Discovery(VERSION, new NoAuthAuthenticator());
discoveryService.setServiceUrl(getMockWebServerUrl());
environmentId = "mock_envid";
environmentName = "my_environment";
environmentDesc = "My environment";
uniqueConfigName = "my-config";
configurationId = "mock_confid";
uniqueCollectionName = "mock_collname";
collectionId = "mock_collid";
documentId = "mock_docid";
queryId = "mock_queryid";
date = new Date();
testStream = new FileInputStream(RESOURCE + "get_env_resp.json");
envResp = loadFixture(RESOURCE + "get_env_resp.json", Environment.class);
envsResp = loadFixture(RESOURCE + "get_envs_resp.json", ListEnvironmentsResponse.class);
createEnvResp = loadFixture(RESOURCE + "create_env_resp.json", Environment.class);
deleteEnvResp = loadFixture(RESOURCE + "delete_env_resp.json", DeleteEnvironmentResponse.class);
updateEnvResp = loadFixture(RESOURCE + "update_env_resp.json", Environment.class);
createConfResp = loadFixture(RESOURCE + "create_conf_resp.json", Configuration.class);
getConfsResp = loadFixture(RESOURCE + "get_confs_resp.json", ListConfigurationsResponse.class);
getConfResp = loadFixture(RESOURCE + "get_conf_resp.json", Configuration.class);
deleteConfResp = loadFixture(RESOURCE + "delete_conf_resp.json", DeleteConfigurationResponse.class);
updateConfResp = loadFixture(RESOURCE + "update_conf_resp.json", Configuration.class);
createCollResp = loadFixture(RESOURCE + "create_coll_resp.json", Collection.class);
getCollsResp = loadFixture(RESOURCE + "get_coll_resp.json", ListCollectionsResponse.class);
getCollResp = loadFixture(RESOURCE + "get_coll1_resp.json", Collection.class);
deleteCollResp = loadFixture(RESOURCE + "delete_coll_resp.json", DeleteCollectionResponse.class);
listfieldsCollResp = loadFixture(RESOURCE + "listfields_coll_resp.json", ListCollectionFieldsResponse.class);
createDocResp = loadFixture(RESOURCE + "create_doc_resp.json", DocumentAccepted.class);
updateDocResp = loadFixture(RESOURCE + "update_doc_resp.json", DocumentAccepted.class);
getDocResp = loadFixture(RESOURCE + "get_doc_resp.json", DocumentStatus.class);
deleteDocResp = loadFixture(RESOURCE + "delete_doc_resp.json", DeleteDocumentResponse.class);
queryResp = loadFixture(RESOURCE + "query1_resp.json", QueryResponse.class);
queryNoticesResp = loadFixture(RESOURCE + "query1_resp.json", QueryNoticesResponse.class);
addTrainingQueryResp = loadFixture(RESOURCE + "add_training_query_resp.json", TrainingQuery.class);
listTrainingDataResp = loadFixture(RESOURCE + "list_training_data_resp.json", TrainingDataSet.class);
createTrainingExampleResp = loadFixture(RESOURCE + "add_training_example_resp.json", TrainingExample.class);
getTrainingDataResp = loadFixture(RESOURCE + "get_training_data_resp.json", TrainingQuery.class);
getTrainingExampleResp = loadFixture(RESOURCE + "get_training_example_resp.json", TrainingExample.class);
updateTrainingExampleResp = loadFixture(RESOURCE + "update_training_example_resp.json", TrainingExample.class);
listTrainingExamplesResp = loadFixture(RESOURCE + "list_training_examples_resp.json", TrainingExampleList.class);
listFieldsResp = loadFixture(RESOURCE + "list_fields_resp.json", ListCollectionFieldsResponse.class);
expansionsResp = loadFixture(RESOURCE + "expansions_resp.json", Expansions.class);
credentialsResp = loadFixture(RESOURCE + "credentials_resp.json", Credentials.class);
listCredentialsResp = loadFixture(RESOURCE + "list_credentials_resp.json", CredentialsList.class);
deleteCredentialsResp = loadFixture(RESOURCE + "delete_credentials_resp.json", DeleteCredentials.class);
createEventResp = loadFixture(RESOURCE + "create_event_resp.json", CreateEventResponse.class);
metricResp = loadFixture(RESOURCE + "metric_resp.json", MetricResponse.class);
metricTokenResp = loadFixture(RESOURCE + "metric_token_resp.json", MetricTokenResponse.class);
logQueryResp = loadFixture(RESOURCE + "log_query_resp.json", LogQueryResponse.class);
tokenDictStatusResponse = loadFixture(RESOURCE + "token_dict_status_resp.json", TokenDictStatusResponse.class);
tokenDictStatusResponseStopwords = loadFixture(RESOURCE + "token_dict_status_resp_stopwords.json", TokenDictStatusResponse.class);
gatewayResponse = loadFixture(RESOURCE + "gateway_resp.json", Gateway.class);
listGatewaysResponse = loadFixture(RESOURCE + "list_gateways_resp.json", GatewayList.class);
deleteGatewayResponse = loadFixture(RESOURCE + "delete_gateway_resp.json", GatewayDelete.class);
}
use of com.ibm.watson.discovery.v1.model.Environment in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method deleteEnvironmentIsSuccessful.
// Deleted test for createEnvironment with null name as this does not fail in the current SDK
/**
* Delete environment is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void deleteEnvironmentIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(deleteEnvResp));
DeleteEnvironmentOptions deleteRequest = new DeleteEnvironmentOptions.Builder(environmentId).build();
DeleteEnvironmentResponse response = discoveryService.deleteEnvironment(deleteRequest).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(ENV1_PATH, request.getPath());
assertEquals(DELETE, request.getMethod());
assertEquals(deleteEnvResp.getEnvironmentId(), response.getEnvironmentId());
assertEquals(deleteEnvResp.getStatus(), response.getStatus());
}
use of com.ibm.watson.discovery.v1.model.Environment in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testCreateEnvironmentWOptions.
// Test the createEnvironment operation with a valid options model parameter
@Test
public void testCreateEnvironmentWOptions() 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 createEnvironmentPath = "/v1/environments";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the CreateEnvironmentOptions model
CreateEnvironmentOptions createEnvironmentOptionsModel = new CreateEnvironmentOptions.Builder().name("testString").description("testString").size("LT").build();
// Invoke createEnvironment() with a valid options model and verify the result
Response<Environment> response = discoveryService.createEnvironment(createEnvironmentOptionsModel).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(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, createEnvironmentPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
}
use of com.ibm.watson.discovery.v1.model.Environment in project java-sdk by watson-developer-cloud.
the class Discovery method getEnvironment.
/**
* Get environment info.
*
* @param getEnvironmentOptions the {@link GetEnvironmentOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link Environment}
*/
public ServiceCall<Environment> getEnvironment(GetEnvironmentOptions getEnvironmentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getEnvironmentOptions, "getEnvironmentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", getEnvironmentOptions.environmentId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getEnvironment");
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<Environment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Environment>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations