Search in sources :

Example 1 with ListExpansionsOptions

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

the class DiscoveryServiceIT method expansionsOperationsAreSuccessful.

@Test
public void expansionsOperationsAreSuccessful() {
    List<String> expansion1InputTerms = Arrays.asList("weekday", "week day");
    List<String> expansion1ExpandedTerms = Arrays.asList("monday", "tuesday", "wednesday", "thursday", "friday");
    List<String> expansion2InputTerms = Arrays.asList("weekend", "week end");
    List<String> expansion2ExpandedTerms = Arrays.asList("saturday", "sunday");
    Expansion expansion1 = new Expansion();
    expansion1.setInputTerms(expansion1InputTerms);
    expansion1.setExpandedTerms(expansion1ExpandedTerms);
    Expansion expansion2 = new Expansion();
    expansion2.setInputTerms(expansion2InputTerms);
    expansion2.setExpandedTerms(expansion2ExpandedTerms);
    Expansions expansions = new Expansions();
    expansions.setExpansions(Arrays.asList(expansion1, expansion2));
    CreateExpansionsOptions createOptions = new CreateExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).expansions(expansions).build();
    Expansions createResults = discovery.createExpansions(createOptions).execute();
    assertEquals(createResults.getExpansions().size(), 2);
    assertEquals(createResults.getExpansions().get(0).getInputTerms(), expansion1InputTerms);
    assertEquals(createResults.getExpansions().get(0).getExpandedTerms(), expansion1ExpandedTerms);
    assertEquals(createResults.getExpansions().get(1).getInputTerms(), expansion2InputTerms);
    assertEquals(createResults.getExpansions().get(1).getExpandedTerms(), expansion2ExpandedTerms);
    ListExpansionsOptions listOptions = new ListExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    Expansions listResults = discovery.listExpansions(listOptions).execute();
    assertEquals(listResults.getExpansions().size(), 2);
    DeleteExpansionsOptions deleteOptions = new DeleteExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    discovery.deleteExpansions(deleteOptions).execute();
    Expansions emptyListResults = discovery.listExpansions(listOptions).execute();
    assertTrue(emptyListResults.getExpansions().get(0).getInputTerms() == null || emptyListResults.getExpansions().get(0).getInputTerms().isEmpty());
    assertTrue(emptyListResults.getExpansions().get(0).getExpandedTerms() == null || emptyListResults.getExpansions().get(0).getExpandedTerms().get(0).isEmpty());
}
Also used : ListExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListExpansionsOptions) Expansion(com.ibm.watson.developer_cloud.discovery.v1.model.Expansion) CreateExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateExpansionsOptions) Expansions(com.ibm.watson.developer_cloud.discovery.v1.model.Expansions) DeleteExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteExpansionsOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with ListExpansionsOptions

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

the class DiscoveryTest method testListExpansionsWOptions.

// Test the listExpansions operation with a valid options model parameter
@Test
public void testListExpansionsWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"expansions\": [{\"input_terms\": [\"inputTerms\"], \"expanded_terms\": [\"expandedTerms\"]}]}";
    String listExpansionsPath = "/v1/environments/testString/collections/testString/expansions";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListExpansionsOptions model
    ListExpansionsOptions listExpansionsOptionsModel = new ListExpansionsOptions.Builder().environmentId("testString").collectionId("testString").build();
    // Invoke listExpansions() with a valid options model and verify the result
    Response<Expansions> response = discoveryService.listExpansions(listExpansionsOptionsModel).execute();
    assertNotNull(response);
    Expansions 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, listExpansionsPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : ListExpansionsOptions(com.ibm.watson.discovery.v1.model.ListExpansionsOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Expansions(com.ibm.watson.discovery.v1.model.Expansions) Test(org.testng.annotations.Test)

Example 3 with ListExpansionsOptions

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

the class DiscoveryServiceTest method listExpansionsIsSuccessful.

@Test
public void listExpansionsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(expansionsResp));
    List<String> expansion1InputTerms = Arrays.asList("weekday", "week day");
    List<String> expansion1ExpandedTerms = Arrays.asList("monday", "tuesday", "wednesday", "thursday", "friday");
    List<String> expansion2InputTerms = Arrays.asList("weekend", "week end");
    List<String> expansion2ExpandedTerms = Arrays.asList("saturday", "sunday");
    Expansion expansion1 = new Expansion();
    expansion1.setInputTerms(expansion1InputTerms);
    expansion1.setExpandedTerms(expansion1ExpandedTerms);
    Expansion expansion2 = new Expansion();
    expansion2.setInputTerms(expansion2InputTerms);
    expansion2.setExpandedTerms(expansion2ExpandedTerms);
    ListExpansionsOptions listOptions = new ListExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    Expansions listResults = discoveryService.listExpansions(listOptions).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(EXPANSIONS_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(expansion1, listResults.getExpansions().get(0));
    assertEquals(expansion2, listResults.getExpansions().get(1));
}
Also used : ListExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListExpansionsOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Expansion(com.ibm.watson.developer_cloud.discovery.v1.model.Expansion) Expansions(com.ibm.watson.developer_cloud.discovery.v1.model.Expansions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 4 with ListExpansionsOptions

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

the class DiscoveryServiceTest method listExpansionsIsSuccessful.

/**
 * List expansions is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void listExpansionsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(expansionsResp));
    List<String> expansion1InputTerms = Arrays.asList("weekday", "week day");
    List<String> expansion1ExpandedTerms = Arrays.asList("monday", "tuesday", "wednesday", "thursday", "friday");
    List<String> expansion2InputTerms = Arrays.asList("weekend", "week end");
    List<String> expansion2ExpandedTerms = Arrays.asList("saturday", "sunday");
    Expansion expansion1 = new Expansion.Builder().inputTerms(expansion1InputTerms).expandedTerms(expansion1ExpandedTerms).build();
    Expansion expansion2 = new Expansion.Builder().inputTerms(expansion2InputTerms).expandedTerms(expansion2ExpandedTerms).build();
    ListExpansionsOptions listOptions = new ListExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    Expansions listResults = discoveryService.listExpansions(listOptions).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(EXPANSIONS_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(expansion1, listResults.expansions().get(0));
    assertEquals(expansion2, listResults.expansions().get(1));
}
Also used : ListExpansionsOptions(com.ibm.watson.discovery.v1.model.ListExpansionsOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Expansion(com.ibm.watson.discovery.v1.model.Expansion) Expansions(com.ibm.watson.discovery.v1.model.Expansions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 5 with ListExpansionsOptions

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

the class Discovery method listExpansions.

/**
 * Get the expansion list.
 *
 * <p>Returns the current expansion list for the specified collection. If an expansion list is not
 * specified, an object with empty expansion arrays is returned.
 *
 * @param listExpansionsOptions the {@link ListExpansionsOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Expansions}
 */
public ServiceCall<Expansions> listExpansions(ListExpansionsOptions listExpansionsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listExpansionsOptions, "listExpansionsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", listExpansionsOptions.environmentId());
    pathParamsMap.put("collection_id", listExpansionsOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/expansions", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listExpansions");
    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<Expansions> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Expansions>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Expansions(com.ibm.watson.discovery.v1.model.Expansions)

Aggregations

Expansions (com.ibm.watson.discovery.v1.model.Expansions)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Expansion (com.ibm.watson.developer_cloud.discovery.v1.model.Expansion)2 Expansions (com.ibm.watson.developer_cloud.discovery.v1.model.Expansions)2 ListExpansionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListExpansionsOptions)2 ListExpansionsOptions (com.ibm.watson.discovery.v1.model.ListExpansionsOptions)2 Test (org.junit.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 CreateExpansionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateExpansionsOptions)1 DeleteExpansionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteExpansionsOptions)1 Expansion (com.ibm.watson.discovery.v1.model.Expansion)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1