Search in sources :

Example 26 with Environment

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);
}
Also used : NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) Configuration(com.ibm.watson.discovery.v1.model.Configuration) QueryNoticesResponse(com.ibm.watson.discovery.v1.model.QueryNoticesResponse) LogQueryResponse(com.ibm.watson.discovery.v1.model.LogQueryResponse) GatewayList(com.ibm.watson.discovery.v1.model.GatewayList) MetricResponse(com.ibm.watson.discovery.v1.model.MetricResponse) Gateway(com.ibm.watson.discovery.v1.model.Gateway) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) TrainingDataSet(com.ibm.watson.discovery.v1.model.TrainingDataSet) ListCollectionFieldsResponse(com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse) DeleteEnvironmentResponse(com.ibm.watson.discovery.v1.model.DeleteEnvironmentResponse) ListCollectionsResponse(com.ibm.watson.discovery.v1.model.ListCollectionsResponse) DocumentAccepted(com.ibm.watson.discovery.v1.model.DocumentAccepted) DeleteDocumentResponse(com.ibm.watson.discovery.v1.model.DeleteDocumentResponse) TrainingExampleList(com.ibm.watson.discovery.v1.model.TrainingExampleList) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials) ListConfigurationsResponse(com.ibm.watson.discovery.v1.model.ListConfigurationsResponse) MetricTokenResponse(com.ibm.watson.discovery.v1.model.MetricTokenResponse) CreateEventResponse(com.ibm.watson.discovery.v1.model.CreateEventResponse) DeleteCollectionResponse(com.ibm.watson.discovery.v1.model.DeleteCollectionResponse) Date(java.util.Date) FileInputStream(java.io.FileInputStream) TrainingQuery(com.ibm.watson.discovery.v1.model.TrainingQuery) Expansions(com.ibm.watson.discovery.v1.model.Expansions) GatewayDelete(com.ibm.watson.discovery.v1.model.GatewayDelete) ListEnvironmentsResponse(com.ibm.watson.discovery.v1.model.ListEnvironmentsResponse) DocumentStatus(com.ibm.watson.discovery.v1.model.DocumentStatus) CredentialsList(com.ibm.watson.discovery.v1.model.CredentialsList) LogQueryResponse(com.ibm.watson.discovery.v1.model.LogQueryResponse) QueryResponse(com.ibm.watson.discovery.v1.model.QueryResponse) Environment(com.ibm.watson.discovery.v1.model.Environment) DeleteConfigurationResponse(com.ibm.watson.discovery.v1.model.DeleteConfigurationResponse) Collection(com.ibm.watson.discovery.v1.model.Collection) TokenDictStatusResponse(com.ibm.watson.discovery.v1.model.TokenDictStatusResponse) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials)

Example 27 with Environment

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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeleteEnvironmentResponse(com.ibm.watson.discovery.v1.model.DeleteEnvironmentResponse) DeleteEnvironmentOptions(com.ibm.watson.discovery.v1.model.DeleteEnvironmentOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 28 with Environment

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");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateEnvironmentOptions(com.ibm.watson.discovery.v1.model.CreateEnvironmentOptions) Environment(com.ibm.watson.discovery.v1.model.Environment) Test(org.testng.annotations.Test)

Example 29 with Environment

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Environment(com.ibm.watson.discovery.v1.model.Environment)

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