use of com.ibm.watson.assistant.v1.model.ListDialogNodesOptions in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT method testListDialogNodes.
/**
* Test listDialogNodes.
*/
@Test
public void testListDialogNodes() {
String dialogNodeName = "Test" + UUID.randomUUID().toString();
try {
ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder(workspaceId).build();
DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getDialogNodes());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
// nextUrl may be null
// Now add a dialog node and make sure we get it back
String dialogNodeDescription = "Description of " + dialogNodeName;
Date start = new Date();
CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
service.createDialogNode(createOptions).execute();
long count = response.getDialogNodes().size();
ListDialogNodesOptions listOptions2 = new ListDialogNodesOptions.Builder(workspaceId).pageLimit(count + 1).includeAudit(true).build();
DialogNodeCollection response2 = service.listDialogNodes(listOptions2).execute();
assertNotNull(response2);
assertNotNull(response2.getDialogNodes());
List<DialogNode> dialogNodes = response2.getDialogNodes();
assertTrue(dialogNodes.size() > count);
DialogNode dialogResponse = null;
for (DialogNode node : dialogNodes) {
if (node.getDialogNodeId().equals(dialogNodeName)) {
dialogResponse = node;
break;
}
}
assertNotNull(dialogResponse);
assertNotNull(dialogResponse.getDescription());
assertEquals(dialogResponse.getDescription(), dialogNodeDescription);
Date now = new Date();
assertTrue(fuzzyBefore(dialogResponse.getCreated(), now));
assertTrue(fuzzyAfter(dialogResponse.getCreated(), start));
assertTrue(fuzzyBefore(dialogResponse.getUpdated(), now));
assertTrue(fuzzyAfter(dialogResponse.getUpdated(), start));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName).build();
service.deleteDialogNode(deleteOptions).execute();
}
}
use of com.ibm.watson.assistant.v1.model.ListDialogNodesOptions in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testListDialogNodes.
/**
* Test listDialogNodes.
*/
@Test
public void testListDialogNodes() {
String dialogNodeName = "Test" + UUID.randomUUID().toString();
try {
ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder(workspaceId).build();
DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getDialogNodes());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
// nextUrl may be null
// Now add a dialog node and make sure we get it back
String dialogNodeDescription = "Description of " + dialogNodeName;
Date start = new Date();
CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
service.createDialogNode(createOptions).execute();
long count = response.getDialogNodes().size();
ListDialogNodesOptions listOptions2 = new ListDialogNodesOptions.Builder(workspaceId).pageLimit(count + 1).includeAudit(true).build();
DialogNodeCollection response2 = service.listDialogNodes(listOptions2).execute();
assertNotNull(response2);
assertNotNull(response2.getDialogNodes());
List<DialogNode> dialogNodes = response2.getDialogNodes();
assertTrue(dialogNodes.size() > count);
DialogNode dialogResponse = null;
for (DialogNode node : dialogNodes) {
if (node.getDialogNodeId().equals(dialogNodeName)) {
dialogResponse = node;
break;
}
}
assertNotNull(dialogResponse);
assertNotNull(dialogResponse.getDescription());
assertEquals(dialogResponse.getDescription(), dialogNodeDescription);
Date now = new Date();
assertTrue(fuzzyBefore(dialogResponse.getCreated(), now));
assertTrue(fuzzyAfter(dialogResponse.getCreated(), start));
assertTrue(fuzzyBefore(dialogResponse.getUpdated(), now));
assertTrue(fuzzyAfter(dialogResponse.getUpdated(), start));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName).build();
service.deleteDialogNode(deleteOptions).execute();
}
}
use of com.ibm.watson.assistant.v1.model.ListDialogNodesOptions in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT method testListDialogNodesWithPaging.
/**
* Test listDialogNodes with pagination.
*/
@Test
public void testListDialogNodesWithPaging() {
String dialogNodeName1 = "First" + UUID.randomUUID().toString();
String dialogNodeName2 = "Second" + UUID.randomUUID().toString();
CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
service.createDialogNode(createOptions).execute();
service.createDialogNode(createOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
try {
ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder().workspaceId(workspaceId).pageLimit(1L).sort("dialog_node").build();
DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getDialogNodes());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
assertNotNull(response.getPagination().getNextUrl());
assertNotNull(response.getPagination().getCursor());
boolean found1 = false, found2 = false;
while (true) {
assertNotNull(response.getDialogNodes());
assertTrue(response.getDialogNodes().size() == 1);
found1 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName1);
found2 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName2);
// verify sort
assertTrue(found1 || !found2);
if (response.getPagination().getCursor() == null) {
break;
}
String cursor = response.getPagination().getCursor();
response = service.listDialogNodes(listOptions.newBuilder().cursor(cursor).build()).execute();
}
assertTrue(found1 && found2);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
service.deleteDialogNode(deleteOptions).execute();
service.deleteDialogNode(deleteOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
}
}
use of com.ibm.watson.assistant.v1.model.ListDialogNodesOptions in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testListDialogNodesWithPaging.
/**
* Test listDialogNodes with pagination.
*/
@Test
public void testListDialogNodesWithPaging() {
String dialogNodeName1 = "First" + UUID.randomUUID().toString();
String dialogNodeName2 = "Second" + UUID.randomUUID().toString();
CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
service.createDialogNode(createOptions).execute();
service.createDialogNode(createOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
try {
ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder().workspaceId(workspaceId).pageLimit(1L).sort("dialog_node").build();
DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getDialogNodes());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
assertNotNull(response.getPagination().getNextUrl());
assertNotNull(response.getPagination().getCursor());
boolean found1 = false, found2 = false;
while (true) {
assertNotNull(response.getDialogNodes());
assertTrue(response.getDialogNodes().size() == 1);
found1 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName1);
found2 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName2);
// verify sort
assertTrue(found1 || !found2);
if (response.getPagination().getCursor() == null) {
break;
}
String cursor = response.getPagination().getCursor();
response = service.listDialogNodes(listOptions.newBuilder().cursor(cursor).build()).execute();
}
assertTrue(found1 && found2);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
service.deleteDialogNode(deleteOptions).execute();
service.deleteDialogNode(deleteOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
}
}
use of com.ibm.watson.assistant.v1.model.ListDialogNodesOptions in project java-sdk by watson-developer-cloud.
the class AssistantTest method testListDialogNodesWOptions.
// Test the listDialogNodes operation with a valid options model parameter
@Test
public void testListDialogNodesWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"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\"}], \"pagination\": {\"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5, \"matched\": 7, \"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\"}}";
String listDialogNodesPath = "/v1/workspaces/testString/dialog_nodes";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ListDialogNodesOptions model
ListDialogNodesOptions listDialogNodesOptionsModel = new ListDialogNodesOptions.Builder().workspaceId("testString").pageLimit(Long.valueOf("26")).includeCount(false).sort("dialog_node").cursor("testString").includeAudit(false).build();
// Invoke listDialogNodes() with a valid options model and verify the result
Response<DialogNodeCollection> response = assistantService.listDialogNodes(listDialogNodesOptionsModel).execute();
assertNotNull(response);
DialogNodeCollection 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, listDialogNodesPath);
// 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"), "dialog_node");
assertEquals(query.get("cursor"), "testString");
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Aggregations