Search in sources :

Example 1 with Enrichments

use of com.ibm.watson.discovery.v2.model.Enrichments 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 Enrichments

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

the class Discovery method createCollection.

/**
 * Create a collection.
 *
 * <p>Create a new collection in the specified project.
 *
 * @param createCollectionOptions the {@link CreateCollectionOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link CollectionDetails}
 */
public ServiceCall<CollectionDetails> createCollection(CreateCollectionOptions createCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createCollectionOptions, "createCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", createCollectionOptions.projectId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "createCollection");
    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));
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", createCollectionOptions.name());
    if (createCollectionOptions.description() != null) {
        contentJson.addProperty("description", createCollectionOptions.description());
    }
    if (createCollectionOptions.language() != null) {
        contentJson.addProperty("language", createCollectionOptions.language());
    }
    if (createCollectionOptions.enrichments() != null) {
        contentJson.add("enrichments", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createCollectionOptions.enrichments()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<CollectionDetails> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CollectionDetails>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) CollectionDetails(com.ibm.watson.discovery.v2.model.CollectionDetails)

Example 3 with Enrichments

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

the class DiscoveryTest method testCreateCollectionWOptions.

@Test
public void testCreateCollectionWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"language\": \"en\", \"enrichments\": [{\"enrichment_id\": \"enrichmentId\", \"fields\": [\"fields\"]}]}";
    String createCollectionPath = "/v2/projects/testString/collections";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the CollectionEnrichment model
    CollectionEnrichment collectionEnrichmentModel = new CollectionEnrichment.Builder().enrichmentId("testString").fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the CreateCollectionOptions model
    CreateCollectionOptions createCollectionOptionsModel = new CreateCollectionOptions.Builder().projectId("testString").name("testString").description("testString").language("en").enrichments(new java.util.ArrayList<CollectionEnrichment>(java.util.Arrays.asList(collectionEnrichmentModel))).build();
    // Invoke operation with valid options model (positive test)
    Response<CollectionDetails> response = discoveryService.createCollection(createCollectionOptionsModel).execute();
    assertNotNull(response);
    CollectionDetails responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // 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, createCollectionPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CollectionEnrichment(com.ibm.watson.discovery.v2.model.CollectionEnrichment) CreateCollectionOptions(com.ibm.watson.discovery.v2.model.CreateCollectionOptions) CollectionDetails(com.ibm.watson.discovery.v2.model.CollectionDetails) Test(org.testng.annotations.Test)

Example 4 with Enrichments

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

the class DiscoveryTest method testListEnrichmentsWOptions.

@Test
public void testListEnrichmentsWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"enrichments\": [{\"enrichment_id\": \"enrichmentId\", \"name\": \"name\", \"description\": \"description\", \"type\": \"part_of_speech\", \"options\": {\"languages\": [\"languages\"], \"entity_type\": \"entityType\", \"regular_expression\": \"regularExpression\", \"result_field\": \"resultField\"}}]}";
    String listEnrichmentsPath = "/v2/projects/testString/enrichments";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ListEnrichmentsOptions model
    ListEnrichmentsOptions listEnrichmentsOptionsModel = new ListEnrichmentsOptions.Builder().projectId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Enrichments> response = discoveryService.listEnrichments(listEnrichmentsOptionsModel).execute();
    assertNotNull(response);
    Enrichments 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, listEnrichmentsPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListEnrichmentsOptions(com.ibm.watson.discovery.v2.model.ListEnrichmentsOptions) Enrichments(com.ibm.watson.discovery.v2.model.Enrichments) Test(org.testng.annotations.Test)

Example 5 with Enrichments

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

the class DiscoveryTest method testCreateEnrichmentWOptions.

@Test
public void testCreateEnrichmentWOptions() 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 createEnrichmentPath = "/v2/projects/testString/enrichments";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the EnrichmentOptions model
    EnrichmentOptions enrichmentOptionsModel = new EnrichmentOptions.Builder().languages(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).entityType("testString").regularExpression("testString").resultField("testString").build();
    // Construct an instance of the CreateEnrichment model
    CreateEnrichment createEnrichmentModel = new CreateEnrichment.Builder().name("testString").description("testString").type("dictionary").options(enrichmentOptionsModel).build();
    // Construct an instance of the CreateEnrichmentOptions model
    CreateEnrichmentOptions createEnrichmentOptionsModel = new CreateEnrichmentOptions.Builder().projectId("testString").enrichment(createEnrichmentModel).file(TestUtilities.createMockStream("This is a mock file.")).build();
    // Invoke operation with valid options model (positive test)
    Response<Enrichment> response = discoveryService.createEnrichment(createEnrichmentOptionsModel).execute();
    assertNotNull(response);
    Enrichment responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // 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, createEnrichmentPath);
}
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) CreateEnrichmentOptions(com.ibm.watson.discovery.v2.model.CreateEnrichmentOptions) DeleteEnrichmentOptions(com.ibm.watson.discovery.v2.model.DeleteEnrichmentOptions) GetEnrichmentOptions(com.ibm.watson.discovery.v2.model.GetEnrichmentOptions) EnrichmentOptions(com.ibm.watson.discovery.v2.model.EnrichmentOptions) UpdateEnrichmentOptions(com.ibm.watson.discovery.v2.model.UpdateEnrichmentOptions) CreateEnrichmentOptions(com.ibm.watson.discovery.v2.model.CreateEnrichmentOptions) CreateEnrichment(com.ibm.watson.discovery.v2.model.CreateEnrichment) Test(org.testng.annotations.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 Test (org.testng.annotations.Test)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)6 Enrichment (com.ibm.watson.discovery.v2.model.Enrichment)6 HashMap (java.util.HashMap)6 CollectionDetails (com.ibm.watson.discovery.v2.model.CollectionDetails)5 CollectionEnrichment (com.ibm.watson.discovery.v2.model.CollectionEnrichment)5 JsonObject (com.google.gson.JsonObject)3 CreateEnrichment (com.ibm.watson.discovery.v2.model.CreateEnrichment)3 DeleteEnrichmentOptions (com.ibm.watson.discovery.v2.model.DeleteEnrichmentOptions)2 Enrichments (com.ibm.watson.discovery.v2.model.Enrichments)2 GetEnrichmentOptions (com.ibm.watson.discovery.v2.model.GetEnrichmentOptions)2 UpdateEnrichmentOptions (com.ibm.watson.discovery.v2.model.UpdateEnrichmentOptions)2 CreateCollectionOptions (com.ibm.watson.discovery.v2.model.CreateCollectionOptions)1 CreateEnrichmentOptions (com.ibm.watson.discovery.v2.model.CreateEnrichmentOptions)1 EnrichmentOptions (com.ibm.watson.discovery.v2.model.EnrichmentOptions)1 GetCollectionOptions (com.ibm.watson.discovery.v2.model.GetCollectionOptions)1 ListEnrichmentsOptions (com.ibm.watson.discovery.v2.model.ListEnrichmentsOptions)1 UpdateCollectionOptions (com.ibm.watson.discovery.v2.model.UpdateCollectionOptions)1