Search in sources :

Example 1 with GetEnrichmentOptions

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

the class DiscoveryTest method testGetEnrichmentWOptions.

@Test
public void testGetEnrichmentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"enrichment_id\": \"enrichmentId\", \"name\": \"name\", \"description\": \"description\", \"type\": \"part_of_speech\", \"options\": {\"languages\": [\"languages\"], \"entity_type\": \"entityType\", \"regular_expression\": \"regularExpression\", \"result_field\": \"resultField\"}}";
    String getEnrichmentPath = "/v2/projects/testString/enrichments/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetEnrichmentOptions model
    GetEnrichmentOptions getEnrichmentOptionsModel = new GetEnrichmentOptions.Builder().projectId("testString").enrichmentId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Enrichment> response = discoveryService.getEnrichment(getEnrichmentOptionsModel).execute();
    assertNotNull(response);
    Enrichment responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getEnrichmentPath);
}
Also used : CollectionEnrichment(com.ibm.watson.discovery.v2.model.CollectionEnrichment) Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) CreateEnrichment(com.ibm.watson.discovery.v2.model.CreateEnrichment) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetEnrichmentOptions(com.ibm.watson.discovery.v2.model.GetEnrichmentOptions) Test(org.testng.annotations.Test)

Example 2 with GetEnrichmentOptions

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

the class Discovery method getEnrichment.

/**
 * Get enrichment.
 *
 * <p>Get details about a specific enrichment.
 *
 * @param getEnrichmentOptions the {@link GetEnrichmentOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Enrichment}
 */
public ServiceCall<Enrichment> getEnrichment(GetEnrichmentOptions getEnrichmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getEnrichmentOptions, "getEnrichmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", getEnrichmentOptions.projectId());
    pathParamsMap.put("enrichment_id", getEnrichmentOptions.enrichmentId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/enrichments/{enrichment_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "getEnrichment");
    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<Enrichment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Enrichment>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Aggregations

Enrichment (com.ibm.watson.discovery.v2.model.Enrichment)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 CollectionEnrichment (com.ibm.watson.discovery.v2.model.CollectionEnrichment)1 CreateEnrichment (com.ibm.watson.discovery.v2.model.CreateEnrichment)1 GetEnrichmentOptions (com.ibm.watson.discovery.v2.model.GetEnrichmentOptions)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1