Search in sources :

Example 1 with DeleteExpansionsOptions

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

the class DiscoveryServiceTest method deleteExpansionsIsSuccessful.

@Test
public void deleteExpansionsIsSuccessful() throws InterruptedException {
    MockResponse desiredResponse = new MockResponse().setResponseCode(200);
    server.enqueue(desiredResponse);
    DeleteExpansionsOptions deleteOptions = new DeleteExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    discoveryService.deleteExpansions(deleteOptions).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(EXPANSIONS_PATH, request.getPath());
    assertEquals(DELETE, request.getMethod());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteExpansionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteExpansionsOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with DeleteExpansionsOptions

use of com.ibm.watson.discovery.v1.model.DeleteExpansionsOptions 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 3 with DeleteExpansionsOptions

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

the class DiscoveryTest method testDeleteExpansionsWOptions.

// Test the deleteExpansions operation with a valid options model parameter
@Test
public void testDeleteExpansionsWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "";
    String deleteExpansionsPath = "/v1/environments/testString/collections/testString/expansions";
    server.enqueue(new MockResponse().setResponseCode(204).setBody(mockResponseBody));
    // Construct an instance of the DeleteExpansionsOptions model
    DeleteExpansionsOptions deleteExpansionsOptionsModel = new DeleteExpansionsOptions.Builder().environmentId("testString").collectionId("testString").build();
    // Invoke deleteExpansions() with a valid options model and verify the result
    Response<Void> response = discoveryService.deleteExpansions(deleteExpansionsOptionsModel).execute();
    assertNotNull(response);
    Void responseObj = response.getResult();
    assertNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "DELETE");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteExpansionsPath);
    // 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) DeleteExpansionsOptions(com.ibm.watson.discovery.v1.model.DeleteExpansionsOptions) Test(org.testng.annotations.Test)

Example 4 with DeleteExpansionsOptions

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

the class DiscoveryServiceTest method deleteExpansionsIsSuccessful.

/**
 * Delete expansions is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void deleteExpansionsIsSuccessful() throws InterruptedException {
    MockResponse desiredResponse = new MockResponse().setResponseCode(200);
    server.enqueue(desiredResponse);
    DeleteExpansionsOptions deleteOptions = new DeleteExpansionsOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    discoveryService.deleteExpansions(deleteOptions).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(EXPANSIONS_PATH, request.getPath());
    assertEquals(DELETE, request.getMethod());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteExpansionsOptions(com.ibm.watson.discovery.v1.model.DeleteExpansionsOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 DeleteExpansionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteExpansionsOptions)2 DeleteExpansionsOptions (com.ibm.watson.discovery.v1.model.DeleteExpansionsOptions)2 Test (org.junit.Test)2 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 Expansion (com.ibm.watson.developer_cloud.discovery.v1.model.Expansion)1 Expansions (com.ibm.watson.developer_cloud.discovery.v1.model.Expansions)1 ListExpansionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListExpansionsOptions)1 Test (org.testng.annotations.Test)1