Search in sources :

Example 1 with CreateValue

use of com.ibm.watson.developer_cloud.assistant.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);
}
Also used : CreateValue(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with CreateValue

use of com.ibm.watson.developer_cloud.assistant.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);
}
Also used : CreateValue(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue) UpdateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.UpdateEntityOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 3 with CreateValue

use of com.ibm.watson.developer_cloud.assistant.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();
    }
}
Also used : HashMap(java.util.HashMap) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) DeleteValueOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteValueOptions) CreateValueOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions) Value(com.ibm.watson.developer_cloud.assistant.v1.model.Value) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 4 with CreateValue

use of com.ibm.watson.developer_cloud.assistant.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);
}
Also used : CreateValue(com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue) UpdateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.UpdateEntityOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 5 with CreateValue

use of com.ibm.watson.developer_cloud.assistant.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);
}
Also used : CreateValue(com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 CreateValue (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue)4 CreateValue (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue)4 ArrayList (java.util.ArrayList)4 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)3 HashMap (java.util.HashMap)3 Value (com.ibm.watson.developer_cloud.assistant.v1.model.Value)2 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)2 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)2 Date (java.util.Date)2 JsonObject (com.google.gson.JsonObject)1 CreateCounterexample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample)1 CreateEntity (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntity)1 CreateExample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateExample)1 CreateIntent (com.ibm.watson.developer_cloud.assistant.v1.model.CreateIntent)1 CreateValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions)1 CreateWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateWorkspaceOptions)1 DeleteEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteEntityOptions)1