Search in sources :

Example 1 with UpdateSynonymOptions

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

the class SynonymsIT method testUpdateSynonym.

/**
 * Test updateSynonym.
 */
@Test
public void testUpdateSynonym() {
    String entity = "beverage";
    String entityValue = "coffee";
    String synonym1 = "joe";
    String synonym2 = "mud";
    try {
        CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
        service.createEntity(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    try {
        CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).build();
        service.createValue(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    try {
        CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym1).build();
        service.createSynonym(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    UpdateSynonymOptions updateOptions = new UpdateSynonymOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).synonym(synonym1).newSynonym(synonym2).build();
    Synonym response = service.updateSynonym(updateOptions).execute();
    try {
        assertNotNull(response);
        assertNotNull(response.getSynonymText());
        assertEquals(response.getSynonymText(), synonym2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym2).build();
        service.deleteSynonym(deleteOptions).execute();
    }
}
Also used : DeleteSynonymOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteSynonymOptions) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) CreateValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions) UpdateSynonymOptions(com.ibm.watson.developer_cloud.conversation.v1.model.UpdateSynonymOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) CreateSynonymOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateSynonymOptions) Synonym(com.ibm.watson.developer_cloud.conversation.v1.model.Synonym) Test(org.junit.Test)

Example 2 with UpdateSynonymOptions

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

the class SynonymsIT method testUpdateSynonym.

/**
 * Test updateSynonym.
 */
@Test
public void testUpdateSynonym() {
    String entity = "beverage";
    String entityValue = "coffee";
    String synonym1 = "joe";
    String synonym2 = "mud";
    try {
        CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
        service.createEntity(createOptions).execute().getResult();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    try {
        CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).build();
        service.createValue(createOptions).execute().getResult();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    try {
        CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym1).build();
        service.createSynonym(createOptions).execute().getResult();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    UpdateSynonymOptions updateOptions = new UpdateSynonymOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).synonym(synonym1).newSynonym(synonym2).build();
    Synonym response = service.updateSynonym(updateOptions).execute().getResult();
    try {
        assertNotNull(response);
        assertNotNull(response.synonym());
        assertEquals(response.synonym(), synonym2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym2).build();
        service.deleteSynonym(deleteOptions).execute().getResult();
    }
}
Also used : DeleteSynonymOptions(com.ibm.watson.assistant.v1.model.DeleteSynonymOptions) CreateEntityOptions(com.ibm.watson.assistant.v1.model.CreateEntityOptions) CreateValueOptions(com.ibm.watson.assistant.v1.model.CreateValueOptions) UpdateSynonymOptions(com.ibm.watson.assistant.v1.model.UpdateSynonymOptions) NotFoundException(com.ibm.cloud.sdk.core.service.exception.NotFoundException) CreateSynonymOptions(com.ibm.watson.assistant.v1.model.CreateSynonymOptions) Synonym(com.ibm.watson.assistant.v1.model.Synonym) Test(org.junit.Test)

Example 3 with UpdateSynonymOptions

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

the class SynonymsIT method testUpdateSynonym.

/**
 * Test updateSynonym.
 */
@Test
public void testUpdateSynonym() {
    String entity = "beverage";
    String entityValue = "coffee";
    String synonym1 = "joe";
    String synonym2 = "mud";
    try {
        CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
        service.createEntity(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    try {
        CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).build();
        service.createValue(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    try {
        CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym1).build();
        service.createSynonym(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    UpdateSynonymOptions updateOptions = new UpdateSynonymOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).synonym(synonym1).newSynonym(synonym2).build();
    Synonym response = service.updateSynonym(updateOptions).execute();
    try {
        assertNotNull(response);
        assertNotNull(response.getSynonymText());
        assertEquals(response.getSynonymText(), synonym2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym2).build();
        service.deleteSynonym(deleteOptions).execute();
    }
}
Also used : DeleteSynonymOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteSynonymOptions) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) CreateValueOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions) UpdateSynonymOptions(com.ibm.watson.developer_cloud.assistant.v1.model.UpdateSynonymOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) CreateSynonymOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateSynonymOptions) Synonym(com.ibm.watson.developer_cloud.assistant.v1.model.Synonym) Test(org.junit.Test)

Example 4 with UpdateSynonymOptions

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

the class AssistantTest method testUpdateSynonymWOptions.

// Test the updateSynonym operation with a valid options model parameter
@Test
public void testUpdateSynonymWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"synonym\": \"synonym\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String updateSynonymPath = "/v1/workspaces/testString/entities/testString/values/testString/synonyms/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the UpdateSynonymOptions model
    UpdateSynonymOptions updateSynonymOptionsModel = new UpdateSynonymOptions.Builder().workspaceId("testString").entity("testString").value("testString").synonym("testString").newSynonym("testString").includeAudit(false).build();
    // Invoke updateSynonym() with a valid options model and verify the result
    Response<Synonym> response = assistantService.updateSynonym(updateSynonymOptionsModel).execute();
    assertNotNull(response);
    Synonym 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(), "POST");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateSynonymPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateSynonymOptions(com.ibm.watson.assistant.v1.model.UpdateSynonymOptions) Synonym(com.ibm.watson.assistant.v1.model.Synonym) Test(org.testng.annotations.Test)

Example 5 with UpdateSynonymOptions

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

the class Assistant method updateSynonym.

/**
 * Update entity value synonym.
 *
 * <p>Update an existing entity value synonym with new text.
 *
 * <p>If you want to update multiple synonyms with a single API call, consider using the **[Update
 * entity](#update-entity)** or **[Update entity value](#update-entity-value)** method instead.
 *
 * @param updateSynonymOptions the {@link UpdateSynonymOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Synonym}
 */
public ServiceCall<Synonym> updateSynonym(UpdateSynonymOptions updateSynonymOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateSynonymOptions, "updateSynonymOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateSynonymOptions.workspaceId());
    pathParamsMap.put("entity", updateSynonymOptions.entity());
    pathParamsMap.put("value", updateSynonymOptions.value());
    pathParamsMap.put("synonym", updateSynonymOptions.synonym());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/values/{value}/synonyms/{synonym}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateSynonym");
    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));
    if (updateSynonymOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateSynonymOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateSynonymOptions.newSynonym() != null) {
        contentJson.addProperty("synonym", updateSynonymOptions.newSynonym());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Synonym> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Synonym>() {
    }.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) Synonym(com.ibm.watson.assistant.v1.model.Synonym)

Aggregations

Synonym (com.ibm.watson.assistant.v1.model.Synonym)3 Test (org.junit.Test)3 UpdateSynonymOptions (com.ibm.watson.assistant.v1.model.UpdateSynonymOptions)2 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)1 CreateEntityOptions (com.ibm.watson.assistant.v1.model.CreateEntityOptions)1 CreateSynonymOptions (com.ibm.watson.assistant.v1.model.CreateSynonymOptions)1 CreateValueOptions (com.ibm.watson.assistant.v1.model.CreateValueOptions)1 DeleteSynonymOptions (com.ibm.watson.assistant.v1.model.DeleteSynonymOptions)1 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)1 CreateSynonymOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateSynonymOptions)1 CreateValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions)1 DeleteSynonymOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteSynonymOptions)1 Synonym (com.ibm.watson.developer_cloud.assistant.v1.model.Synonym)1 UpdateSynonymOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateSynonymOptions)1 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)1 CreateSynonymOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateSynonymOptions)1 CreateValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions)1