use of com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode 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.developer_cloud.conversation.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT method testUpdateDialogNode.
/**
* Test updateDialogNode.
*/
@Test
public void testUpdateDialogNode() {
String dialogNodeName = "Test" + UUID.randomUUID().toString();
String dialogNodeDescription = "Description of " + dialogNodeName;
CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
service.createDialogNode(createOptions).execute();
String dialogNodeName2 = "Test2" + UUID.randomUUID().toString();
try {
String dialogNodeDescription2 = "Updated description of " + dialogNodeName;
UpdateDialogNodeOptions updateOptions = new UpdateDialogNodeOptions.Builder().workspaceId(workspaceId).dialogNode(dialogNodeName).newDialogNode(dialogNodeName2).newDescription(dialogNodeDescription2).build();
DialogNode response = service.updateDialogNode(updateOptions).execute();
assertNotNull(response);
assertNotNull(response.getDialogNodeId());
assertEquals(response.getDialogNodeId(), dialogNodeName2);
assertNotNull(response.getDescription());
assertEquals(response.getDescription(), dialogNodeDescription2);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName2).build();
service.deleteDialogNode(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class ConversationTest method testUpdateWorkspaceOptionsBuilder.
/**
* Test UpdateWorkspaceOptions builder.
*/
@Test
public void testUpdateWorkspaceOptionsBuilder() {
String workspaceName = "Builder Test";
String workspaceDescription = "Description of " + workspaceName;
String workspaceLanguage = "en";
// intents
CreateIntent testIntent = new CreateIntent.Builder("testIntent").build();
// entities
CreateEntity testEntity = new CreateEntity.Builder("testEntity").build();
// counterexamples
CreateCounterexample testCounterexample = new CreateCounterexample.Builder("testCounterexample").build();
// dialognodes
CreateDialogNode testDialogNode = new CreateDialogNode.Builder("dialogNode").build();
// metadata
Map<String, Object> workspaceMetadata = new HashMap<String, Object>();
String metadataValue = "value for " + workspaceName;
workspaceMetadata.put("key", metadataValue);
UpdateWorkspaceOptions.Builder builder = new UpdateWorkspaceOptions.Builder(WORKSPACE_ID);
builder.name(workspaceName);
builder.description(workspaceDescription);
builder.language(workspaceLanguage);
builder.addIntent(testIntent);
builder.addEntity(testEntity);
builder.addCounterexample(testCounterexample);
builder.addDialogNode(testDialogNode);
builder.metadata(workspaceMetadata);
UpdateWorkspaceOptions options = builder.build();
assertEquals(options.name(), workspaceName);
assertEquals(options.description(), workspaceDescription);
assertEquals(options.language(), workspaceLanguage);
assertNotNull(options.intents());
assertEquals(options.intents().size(), 1);
assertEquals(options.intents().get(0), testIntent);
assertNotNull(options.entities());
assertEquals(options.entities().size(), 1);
assertEquals(options.entities().get(0), testEntity);
assertNotNull(options.counterexamples());
assertEquals(options.counterexamples().size(), 1);
assertEquals(options.counterexamples().get(0), testCounterexample);
assertNotNull(options.dialogNodes());
assertEquals(options.dialogNodes().size(), 1);
assertEquals(options.dialogNodes().get(0), testDialogNode);
assertNotNull(options.metadata());
assertEquals(options.metadata(), workspaceMetadata);
UpdateWorkspaceOptions.Builder builder2 = options.newBuilder();
CreateIntent testIntent2 = new CreateIntent.Builder("testIntent2").build();
CreateEntity testEntity2 = new CreateEntity.Builder("testEntity2").build();
CreateCounterexample testCounterexample2 = new CreateCounterexample.Builder("testCounterexample2").build();
CreateDialogNode testDialogNode2 = new CreateDialogNode.Builder("dialogNode2").build();
builder2.intents(new ArrayList<CreateIntent>());
builder2.addIntent(testIntent2);
builder2.entities(new ArrayList<CreateEntity>());
builder2.addEntity(testEntity2);
builder2.counterexamples(new ArrayList<CreateCounterexample>());
builder2.addCounterexample(testCounterexample2);
builder2.dialogNodes(new ArrayList<CreateDialogNode>());
builder2.addDialogNode(testDialogNode2);
UpdateWorkspaceOptions options2 = builder2.build();
assertNotNull(options2.intents());
assertEquals(options2.intents().size(), 1);
assertEquals(options2.intents().get(0), testIntent2);
assertNotNull(options2.entities());
assertEquals(options2.entities().size(), 1);
assertEquals(options2.entities().get(0), testEntity2);
assertNotNull(options2.counterexamples());
assertEquals(options2.counterexamples().size(), 1);
assertEquals(options2.counterexamples().get(0), testCounterexample2);
assertNotNull(options2.dialogNodes());
assertEquals(options2.dialogNodes().size(), 1);
assertEquals(options2.dialogNodes().get(0), testDialogNode2);
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class ConversationTest method testCreateDialogNodeOptionsBuilder.
/**
* Test CreateDialogNodeOptions builder.
*/
@Test
public void testCreateDialogNodeOptionsBuilder() {
String dialogNodeName = "aDialogNode";
DialogNodeAction action0 = new DialogNodeAction();
action0.setName("action0");
action0.setCredentials("credential0");
DialogNodeAction action1 = new DialogNodeAction();
action1.setName("action1");
action1.setCredentials("credential1");
CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder().workspaceId(WORKSPACE_ID).dialogNode(dialogNodeName).addActions(action0).addActions(action1).build();
assertEquals(createOptions.workspaceId(), WORKSPACE_ID);
assertEquals(createOptions.dialogNode(), dialogNodeName);
assertEquals(createOptions.actions().size(), 2);
assertEquals(createOptions.actions().get(0), action0);
assertEquals(createOptions.actions().get(0).getCredentials(), "credential0");
assertEquals(createOptions.actions().get(1), action1);
assertEquals(createOptions.actions().get(1).getCredentials(), "credential1");
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class Conversation method getDialogNode.
/**
* Get dialog node.
*
* Get information about a dialog node.
*
* @param getDialogNodeOptions the {@link GetDialogNodeOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link DialogNode}
*/
public ServiceCall<DialogNode> getDialogNode(GetDialogNodeOptions getDialogNodeOptions) {
Validator.notNull(getDialogNodeOptions, "getDialogNodeOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
String[] pathParameters = { getDialogNodeOptions.workspaceId(), getDialogNodeOptions.dialogNode() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (getDialogNodeOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(getDialogNodeOptions.includeAudit()));
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNode.class));
}
Aggregations