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();
}
}
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();
}
}
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();
}
}
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));
}
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);
}
Aggregations