Search in sources :

Example 1 with CollectionEnrichment

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

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

the class DiscoveryTest method testUpdateCollectionWOptions.

@Test
public void testUpdateCollectionWOptions() 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 updateCollectionPath = "/v2/projects/testString/collections/testString";
    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 UpdateCollectionOptions model
    UpdateCollectionOptions updateCollectionOptionsModel = new UpdateCollectionOptions.Builder().projectId("testString").collectionId("testString").name("testString").description("testString").enrichments(new java.util.ArrayList<CollectionEnrichment>(java.util.Arrays.asList(collectionEnrichmentModel))).build();
    // Invoke operation with valid options model (positive test)
    Response<CollectionDetails> response = discoveryService.updateCollection(updateCollectionOptionsModel).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, updateCollectionPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CollectionEnrichment(com.ibm.watson.discovery.v2.model.CollectionEnrichment) UpdateCollectionOptions(com.ibm.watson.discovery.v2.model.UpdateCollectionOptions) CollectionDetails(com.ibm.watson.discovery.v2.model.CollectionDetails) Test(org.testng.annotations.Test)

Aggregations

CollectionDetails (com.ibm.watson.discovery.v2.model.CollectionDetails)2 CollectionEnrichment (com.ibm.watson.discovery.v2.model.CollectionEnrichment)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Test (org.testng.annotations.Test)2 CreateCollectionOptions (com.ibm.watson.discovery.v2.model.CreateCollectionOptions)1 UpdateCollectionOptions (com.ibm.watson.discovery.v2.model.UpdateCollectionOptions)1