use of com.ibm.watson.assistant.v1.model.Value in project java-sdk by watson-developer-cloud.
the class AssistantTest method testListSynonymsWOptions.
// Test the listSynonyms operation with a valid options model parameter
@Test
public void testListSynonymsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"synonyms\": [{\"synonym\": \"synonym\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}], \"pagination\": {\"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5, \"matched\": 7, \"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\"}}";
String listSynonymsPath = "/v1/workspaces/testString/entities/testString/values/testString/synonyms";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ListSynonymsOptions model
ListSynonymsOptions listSynonymsOptionsModel = new ListSynonymsOptions.Builder().workspaceId("testString").entity("testString").value("testString").pageLimit(Long.valueOf("26")).includeCount(false).sort("synonym").cursor("testString").includeAudit(false).build();
// Invoke listSynonyms() with a valid options model and verify the result
Response<SynonymCollection> response = assistantService.listSynonyms(listSynonymsOptionsModel).execute();
assertNotNull(response);
SynonymCollection 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, listSynonymsPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(Long.valueOf(query.get("page_limit")), Long.valueOf("26"));
assertEquals(Boolean.valueOf(query.get("include_count")), Boolean.valueOf(false));
assertEquals(query.get("sort"), "synonym");
assertEquals(query.get("cursor"), "testString");
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
use of com.ibm.watson.assistant.v1.model.Value in project java-sdk by watson-developer-cloud.
the class AssistantTest method testCreateSynonymWOptions.
// Test the createSynonym operation with a valid options model parameter
@Test
public void testCreateSynonymWOptions() 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 createSynonymPath = "/v1/workspaces/testString/entities/testString/values/testString/synonyms";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the CreateSynonymOptions model
CreateSynonymOptions createSynonymOptionsModel = new CreateSynonymOptions.Builder().workspaceId("testString").entity("testString").value("testString").synonym("testString").includeAudit(false).build();
// Invoke createSynonym() with a valid options model and verify the result
Response<Synonym> response = assistantService.createSynonym(createSynonymOptionsModel).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, createSynonymPath);
// 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.Value in project java-sdk by watson-developer-cloud.
the class AssistantTest method testUpdateEntityWOptions.
// Test the updateEntity operation with a valid options model parameter
@Test
public void testUpdateEntityWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"entity\": \"entity\", \"description\": \"description\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"fuzzy_match\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"values\": [{\"value\": \"value\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"type\": \"synonyms\", \"synonyms\": [\"synonym\"], \"patterns\": [\"pattern\"], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}";
String updateEntityPath = "/v1/workspaces/testString/entities/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the CreateValue model
CreateValue createValueModel = new CreateValue.Builder().value("testString").metadata(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).type("synonyms").synonyms(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).patterns(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
// Construct an instance of the UpdateEntityOptions model
UpdateEntityOptions updateEntityOptionsModel = new UpdateEntityOptions.Builder().workspaceId("testString").entity("testString").newEntity("testString").newDescription("testString").newMetadata(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).newFuzzyMatch(true).newValues(new java.util.ArrayList<CreateValue>(java.util.Arrays.asList(createValueModel))).append(false).includeAudit(false).build();
// Invoke updateEntity() with a valid options model and verify the result
Response<Entity> response = assistantService.updateEntity(updateEntityOptionsModel).execute();
assertNotNull(response);
Entity 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, updateEntityPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(Boolean.valueOf(query.get("append")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
use of com.ibm.watson.assistant.v1.model.Value in project java-sdk by watson-developer-cloud.
the class AssistantTest method testListWorkspacesWOptions.
// Test the listWorkspaces operation with a valid options model parameter
@Test
public void testListWorkspacesWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"workspaces\": [{\"name\": \"name\", \"description\": \"description\", \"language\": \"language\", \"workspace_id\": \"workspaceId\", \"dialog_nodes\": [{\"dialog_node\": \"dialogNode\", \"description\": \"description\", \"conditions\": \"conditions\", \"parent\": \"parent\", \"previous_sibling\": \"previousSibling\", \"output\": {\"generic\": [{\"response_type\": \"video\", \"source\": \"source\", \"title\": \"title\", \"description\": \"description\", \"channels\": [{\"channel\": \"chat\"}], \"channel_options\": {\"mapKey\": \"anyValue\"}, \"alt_text\": \"altText\"}], \"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}, \"modifiers\": {\"overwrite\": true}}, \"context\": {\"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}}, \"metadata\": {\"mapKey\": \"anyValue\"}, \"next_step\": {\"behavior\": \"get_user_input\", \"dialog_node\": \"dialogNode\", \"selector\": \"condition\"}, \"title\": \"title\", \"type\": \"standard\", \"event_name\": \"focus\", \"variable\": \"variable\", \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"digress_in\": \"not_available\", \"digress_out\": \"allow_returning\", \"digress_out_slots\": \"not_allowed\", \"user_label\": \"userLabel\", \"disambiguation_opt_out\": false, \"disabled\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}], \"counterexamples\": [{\"text\": \"text\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"learning_opt_out\": false, \"system_settings\": {\"tooling\": {\"store_generic_responses\": false}, \"disambiguation\": {\"prompt\": \"prompt\", \"none_of_the_above_prompt\": \"noneOfTheAbovePrompt\", \"enabled\": false, \"sensitivity\": \"auto\", \"randomize\": false, \"max_suggestions\": 1, \"suggestion_text_policy\": \"suggestionTextPolicy\"}, \"human_agent_assist\": {\"mapKey\": \"anyValue\"}, \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"system_entities\": {\"enabled\": false}, \"off_topic\": {\"enabled\": false}}, \"status\": \"Non Existent\", \"webhooks\": [{\"url\": \"url\", \"name\": \"name\", \"headers\": [{\"name\": \"name\", \"value\": \"value\"}]}], \"intents\": [{\"intent\": \"intent\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"examples\": [{\"text\": \"text\", \"mentions\": [{\"entity\": \"entity\", \"location\": [8]}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}], \"entities\": [{\"entity\": \"entity\", \"description\": \"description\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"fuzzy_match\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"values\": [{\"value\": \"value\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"type\": \"synonyms\", \"synonyms\": [\"synonym\"], \"patterns\": [\"pattern\"], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}]}], \"pagination\": {\"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5, \"matched\": 7, \"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\"}}";
String listWorkspacesPath = "/v1/workspaces";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ListWorkspacesOptions model
ListWorkspacesOptions listWorkspacesOptionsModel = new ListWorkspacesOptions.Builder().pageLimit(Long.valueOf("26")).includeCount(false).sort("name").cursor("testString").includeAudit(false).build();
// Invoke listWorkspaces() with a valid options model and verify the result
Response<WorkspaceCollection> response = assistantService.listWorkspaces(listWorkspacesOptionsModel).execute();
assertNotNull(response);
WorkspaceCollection 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, listWorkspacesPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(Long.valueOf(query.get("page_limit")), Long.valueOf("26"));
assertEquals(Boolean.valueOf(query.get("include_count")), Boolean.valueOf(false));
assertEquals(query.get("sort"), "name");
assertEquals(query.get("cursor"), "testString");
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
use of com.ibm.watson.assistant.v1.model.Value in project java-sdk by watson-developer-cloud.
the class Assistant method createSynonym.
/**
* Create entity value synonym.
*
* <p>Add a new synonym to an entity value.
*
* <p>If you want to create multiple synonyms with a single API call, consider using the **[Update
* entity](#update-entity)** or **[Update entity value](#update-entity-value)** method instead.
*
* @param createSynonymOptions the {@link CreateSynonymOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link Synonym}
*/
public ServiceCall<Synonym> createSynonym(CreateSynonymOptions createSynonymOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createSynonymOptions, "createSynonymOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("workspace_id", createSynonymOptions.workspaceId());
pathParamsMap.put("entity", createSynonymOptions.entity());
pathParamsMap.put("value", createSynonymOptions.value());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/values/{value}/synonyms", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "createSynonym");
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 (createSynonymOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(createSynonymOptions.includeAudit()));
}
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("synonym", createSynonymOptions.synonym());
builder.bodyJson(contentJson);
ResponseConverter<Synonym> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Synonym>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations