use of com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue in project java-sdk by watson-developer-cloud.
the class ConversationTest method testCreateEntityOptionsBuilder.
/**
* Test CreateEntityOptions builder.
*/
@Test
public void testCreateEntityOptionsBuilder() {
String entity = "anEntity";
CreateValue entityValue0 = new CreateValue.Builder().value("entityValue0").addPattern("pattern0").build();
CreateValue entityValue1 = new CreateValue.Builder().value("entityValue1").addPattern("pattern1").build();
CreateEntityOptions createOptions = new CreateEntityOptions.Builder().workspaceId(WORKSPACE_ID).entity(entity).addValue(entityValue0).addValue(entityValue1).build();
assertEquals(createOptions.workspaceId(), WORKSPACE_ID);
assertEquals(createOptions.entity(), entity);
assertEquals(createOptions.values().size(), 2);
assertEquals(createOptions.values().get(0), entityValue0);
assertEquals(createOptions.values().get(1), entityValue1);
CreateEntityOptions.Builder builder = createOptions.newBuilder();
CreateValue entityValue2 = new CreateValue.Builder().value("entityValue2").addPattern("pattern2").build();
builder.values(Arrays.asList(entityValue2));
CreateEntityOptions options2 = builder.build();
assertEquals(options2.workspaceId(), WORKSPACE_ID);
assertEquals(options2.entity(), entity);
assertEquals(options2.values().size(), 1);
assertEquals(options2.values().get(0), entityValue2);
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue in project java-sdk by watson-developer-cloud.
the class ConversationTest method testUpdateEntityOptionsBuilder.
/**
* Test UpdateEntityOptions builder.
*/
@Test
public void testUpdateEntityOptionsBuilder() {
String entity = "anEntity";
String newEntity = "renamedEntity";
CreateValue entityValue0 = new CreateValue.Builder().value("entityValue0").addPattern("pattern0").build();
CreateValue entityValue1 = new CreateValue.Builder().value("entityValue1").addPattern("pattern1").build();
UpdateEntityOptions updateOptions = new UpdateEntityOptions.Builder().workspaceId(WORKSPACE_ID).entity(entity).newEntity(newEntity).addValue(entityValue0).addValue(entityValue1).build();
assertEquals(updateOptions.workspaceId(), WORKSPACE_ID);
assertEquals(updateOptions.entity(), entity);
assertEquals(updateOptions.newEntity(), newEntity);
assertEquals(updateOptions.newValues().size(), 2);
assertEquals(updateOptions.newValues().get(0), entityValue0);
assertEquals(updateOptions.newValues().get(1), entityValue1);
UpdateEntityOptions.Builder builder = updateOptions.newBuilder();
CreateValue entityValue2 = new CreateValue.Builder().value("entityValue2").addPattern("pattern2").build();
builder.newValues(Arrays.asList(entityValue2));
UpdateEntityOptions options2 = builder.build();
assertEquals(options2.workspaceId(), WORKSPACE_ID);
assertEquals(options2.entity(), entity);
assertEquals(options2.newEntity(), newEntity);
assertEquals(options2.newValues().size(), 1);
assertEquals(options2.newValues().get(0), entityValue2);
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue in project java-sdk by watson-developer-cloud.
the class ValuesIT method testCreateValue.
/**
* Test createValue.
*/
@Test
public void testCreateValue() {
String entity = "beverage";
String entityValue = "coffee" + UUID.randomUUID().toString();
// metadata
Map<String, Object> valueMetadata = new HashMap<String, Object>();
String metadataValue = "value for " + entityValue;
valueMetadata.put("key", metadataValue);
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"));
}
CreateValueOptions createOptions = new CreateValueOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).metadata(valueMetadata).build();
Value response = service.createValue(createOptions).execute();
try {
assertNotNull(response);
assertNotNull(response.getValueText());
assertEquals(response.getValueText(), entityValue);
assertNotNull(response.getMetadata());
// metadata
assertNotNull(response.getMetadata());
assertNotNull(response.getMetadata().get("key"));
assertEquals(response.getMetadata().get("key"), metadataValue);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue).build();
service.deleteValue(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue in project java-sdk by watson-developer-cloud.
the class AssistantTest method testUpdateEntityOptionsBuilder.
/**
* Test UpdateEntityOptions builder.
*/
@Test
public void testUpdateEntityOptionsBuilder() {
String entity = "anEntity";
String newEntity = "renamedEntity";
CreateValue entityValue0 = new CreateValue.Builder().value("entityValue0").addPattern("pattern0").build();
CreateValue entityValue1 = new CreateValue.Builder().value("entityValue1").addPattern("pattern1").build();
UpdateEntityOptions updateOptions = new UpdateEntityOptions.Builder().workspaceId(WORKSPACE_ID).entity(entity).newEntity(newEntity).addValue(entityValue0).addValue(entityValue1).build();
assertEquals(updateOptions.workspaceId(), WORKSPACE_ID);
assertEquals(updateOptions.entity(), entity);
assertEquals(updateOptions.newEntity(), newEntity);
assertEquals(updateOptions.newValues().size(), 2);
assertEquals(updateOptions.newValues().get(0), entityValue0);
assertEquals(updateOptions.newValues().get(1), entityValue1);
UpdateEntityOptions.Builder builder = updateOptions.newBuilder();
CreateValue entityValue2 = new CreateValue.Builder().value("entityValue2").addPattern("pattern2").build();
builder.newValues(Arrays.asList(entityValue2));
UpdateEntityOptions options2 = builder.build();
assertEquals(options2.workspaceId(), WORKSPACE_ID);
assertEquals(options2.entity(), entity);
assertEquals(options2.newEntity(), newEntity);
assertEquals(options2.newValues().size(), 1);
assertEquals(options2.newValues().get(0), entityValue2);
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue in project java-sdk by watson-developer-cloud.
the class AssistantTest method testCreateEntityOptionsBuilder.
/**
* Test CreateEntityOptions builder.
*/
@Test
public void testCreateEntityOptionsBuilder() {
String entity = "anEntity";
CreateValue entityValue0 = new CreateValue.Builder().value("entityValue0").addPattern("pattern0").build();
CreateValue entityValue1 = new CreateValue.Builder().value("entityValue1").addPattern("pattern1").build();
CreateEntityOptions createOptions = new CreateEntityOptions.Builder().workspaceId(WORKSPACE_ID).entity(entity).addValue(entityValue0).addValue(entityValue1).build();
assertEquals(createOptions.workspaceId(), WORKSPACE_ID);
assertEquals(createOptions.entity(), entity);
assertEquals(createOptions.values().size(), 2);
assertEquals(createOptions.values().get(0), entityValue0);
assertEquals(createOptions.values().get(1), entityValue1);
CreateEntityOptions.Builder builder = createOptions.newBuilder();
CreateValue entityValue2 = new CreateValue.Builder().value("entityValue2").addPattern("pattern2").build();
builder.values(Arrays.asList(entityValue2));
CreateEntityOptions options2 = builder.build();
assertEquals(options2.workspaceId(), WORKSPACE_ID);
assertEquals(options2.entity(), entity);
assertEquals(options2.values().size(), 1);
assertEquals(options2.values().get(0), entityValue2);
}
Aggregations