Search in sources :

Example 1 with GetConfigurationOptions

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

the class DiscoveryServiceIT method getConfigurationIsSuccessful.

@Test
public void getConfigurationIsSuccessful() {
    Configuration createResponse = createTestConfig();
    GetConfigurationOptions getOptions = new GetConfigurationOptions.Builder(environmentId, createResponse.getConfigurationId()).build();
    Configuration getResponse = discovery.getConfiguration(getOptions).execute();
    assertEquals(createResponse.getName(), getResponse.getName());
}
Also used : Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) GetConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetConfigurationOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with GetConfigurationOptions

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

the class DiscoveryServiceTest method getConfigurationIsSuccessful.

@Test
public void getConfigurationIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(getConfResp));
    GetConfigurationOptions getRequest = new GetConfigurationOptions.Builder(environmentId, configurationId).build();
    Configuration response = discoveryService.getConfiguration(getRequest).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(CONF2_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(getConfResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetConfigurationOptions) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 3 with GetConfigurationOptions

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

the class DiscoveryTest method testGetConfigurationWOptions.

// Test the getConfiguration operation with a valid options model parameter
@Test
public void testGetConfigurationWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"configuration_id\": \"configurationId\", \"name\": \"name\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"description\": \"description\", \"conversions\": {\"pdf\": {\"heading\": {\"fonts\": [{\"level\": 5, \"min_size\": 7, \"max_size\": 7, \"bold\": true, \"italic\": true, \"name\": \"name\"}]}}, \"word\": {\"heading\": {\"fonts\": [{\"level\": 5, \"min_size\": 7, \"max_size\": 7, \"bold\": true, \"italic\": true, \"name\": \"name\"}], \"styles\": [{\"level\": 5, \"names\": [\"names\"]}]}}, \"html\": {\"exclude_tags_completely\": [\"excludeTagsCompletely\"], \"exclude_tags_keep_content\": [\"excludeTagsKeepContent\"], \"keep_content\": {\"xpaths\": [\"xpaths\"]}, \"exclude_content\": {\"xpaths\": [\"xpaths\"]}, \"keep_tag_attributes\": [\"keepTagAttributes\"], \"exclude_tag_attributes\": [\"excludeTagAttributes\"]}, \"segment\": {\"enabled\": false, \"selector_tags\": [\"selectorTags\"], \"annotated_fields\": [\"annotatedFields\"]}, \"json_normalizations\": [{\"operation\": \"copy\", \"source_field\": \"sourceField\", \"destination_field\": \"destinationField\"}], \"image_text_recognition\": true}, \"enrichments\": [{\"description\": \"description\", \"destination_field\": \"destinationField\", \"source_field\": \"sourceField\", \"overwrite\": false, \"enrichment\": \"enrichment\", \"ignore_downstream_errors\": false, \"options\": {\"features\": {\"keywords\": {\"sentiment\": false, \"emotion\": false, \"limit\": 5}, \"entities\": {\"sentiment\": false, \"emotion\": false, \"limit\": 5, \"mentions\": true, \"mention_types\": true, \"sentence_locations\": false, \"model\": \"model\"}, \"sentiment\": {\"document\": true, \"targets\": [\"target\"]}, \"emotion\": {\"document\": true, \"targets\": [\"target\"]}, \"categories\": {\"mapKey\": \"anyValue\"}, \"semantic_roles\": {\"entities\": true, \"keywords\": true, \"limit\": 5}, \"relations\": {\"model\": \"model\"}, \"concepts\": {\"limit\": 5}}, \"language\": \"ar\", \"model\": \"model\"}}], \"normalizations\": [{\"operation\": \"copy\", \"source_field\": \"sourceField\", \"destination_field\": \"destinationField\"}], \"source\": {\"type\": \"box\", \"credential_id\": \"credentialId\", \"schedule\": {\"enabled\": true, \"time_zone\": \"America/New_York\", \"frequency\": \"daily\"}, \"options\": {\"folders\": [{\"owner_user_id\": \"ownerUserId\", \"folder_id\": \"folderId\", \"limit\": 5}], \"objects\": [{\"name\": \"name\", \"limit\": 5}], \"site_collections\": [{\"site_collection_path\": \"siteCollectionPath\", \"limit\": 5}], \"urls\": [{\"url\": \"url\", \"limit_to_starting_hosts\": true, \"crawl_speed\": \"normal\", \"allow_untrusted_certificate\": false, \"maximum_hops\": 11, \"request_timeout\": 14, \"override_robots_txt\": false, \"blacklist\": [\"blacklist\"]}], \"buckets\": [{\"name\": \"name\", \"limit\": 5}], \"crawl_all_buckets\": false}}}";
    String getConfigurationPath = "/v1/environments/testString/configurations/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetConfigurationOptions model
    GetConfigurationOptions getConfigurationOptionsModel = new GetConfigurationOptions.Builder().environmentId("testString").configurationId("testString").build();
    // Invoke getConfiguration() with a valid options model and verify the result
    Response<Configuration> response = discoveryService.getConfiguration(getConfigurationOptionsModel).execute();
    assertNotNull(response);
    Configuration 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, getConfigurationPath);
    // 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) GetConfigurationOptions(com.ibm.watson.discovery.v1.model.GetConfigurationOptions) Configuration(com.ibm.watson.discovery.v1.model.Configuration) Test(org.testng.annotations.Test)

Example 4 with GetConfigurationOptions

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

the class Discovery method getConfiguration.

/**
 * Get configuration details.
 *
 * @param getConfigurationOptions the {@link GetConfigurationOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Configuration}
 */
public ServiceCall<Configuration> getConfiguration(GetConfigurationOptions getConfigurationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getConfigurationOptions, "getConfigurationOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", getConfigurationOptions.environmentId());
    pathParamsMap.put("configuration_id", getConfigurationOptions.configurationId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/configurations/{configuration_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getConfiguration");
    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<Configuration> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Configuration>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) Configuration(com.ibm.watson.discovery.v1.model.Configuration) HashMap(java.util.HashMap)

Example 5 with GetConfigurationOptions

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

the class DiscoveryServiceIT method issueNumber518.

@Test
public void issueNumber518() {
    String[] operations = new String[] { Operation.MOVE, Operation.COPY, Operation.MERGE, Operation.REMOVE, Operation.REMOVE_NULLS };
    String uniqueConfigName = uniqueName + "-config";
    CreateConfigurationOptions.Builder createBuilder = new CreateConfigurationOptions.Builder(environmentId);
    Configuration configuration = getTestConfiguration(DISCOVERY2_TEST_CONFIG_FILE);
    configuration.setName(uniqueConfigName);
    createBuilder.configuration(configuration);
    Configuration createResponse = createConfiguration(createBuilder.build());
    GetConfigurationOptions getOptions = new GetConfigurationOptions.Builder(environmentId, createResponse.getConfigurationId()).build();
    Configuration getResponse = discovery.getConfiguration(getOptions).execute();
    // verify getResponse deserializes the operations appropriately
    for (NormalizationOperation normalization : getResponse.getNormalizations()) {
        String operation = normalization.getOperation();
        assertEquals(true, Arrays.asList(operations).contains(operation));
    }
}
Also used : CreateConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) GetConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetConfigurationOptions) NormalizationOperation(com.ibm.watson.developer_cloud.discovery.v1.model.NormalizationOperation) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)4 GetConfigurationOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetConfigurationOptions)4 Test (org.junit.Test)4 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)3 Configuration (com.ibm.watson.discovery.v1.model.Configuration)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 CreateConfigurationOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions)2 GetConfigurationOptions (com.ibm.watson.discovery.v1.model.GetConfigurationOptions)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 NormalizationOperation (com.ibm.watson.developer_cloud.discovery.v1.model.NormalizationOperation)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1