Search in sources :

Example 11 with GetValueOptions

use of com.ibm.watson.assistant.v1.model.GetValueOptions in project java-sdk by watson-developer-cloud.

the class ValuesIT method testDeleteValue.

/**
 * Test deleteValue.
 */
@Test
public void testDeleteValue() {
    String entity = "beverage";
    String entityValue = "coffee" + UUID.randomUUID().toString();
    try {
        CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
        service.createEntity(createOptions).execute().getResult();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).build();
    Value response = service.createValue(createOptions).execute().getResult();
    try {
        assertNotNull(response);
        assertNotNull(response.value());
        assertEquals(response.value(), entityValue);
        assertNull(response.metadata());
    } catch (Exception ex) {
        // Clean up
        DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue).build();
        service.deleteValue(deleteOptions).execute().getResult();
        fail(ex.getMessage());
    }
    DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).build();
    service.deleteValue(deleteOptions).execute().getResult();
    try {
        GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue).build();
        service.getValue(getOptions).execute().getResult();
        fail("deleteValue failed");
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
    }
}
Also used : GetValueOptions(com.ibm.watson.assistant.v1.model.GetValueOptions) CreateEntityOptions(com.ibm.watson.assistant.v1.model.CreateEntityOptions) DeleteValueOptions(com.ibm.watson.assistant.v1.model.DeleteValueOptions) CreateValueOptions(com.ibm.watson.assistant.v1.model.CreateValueOptions) Value(com.ibm.watson.assistant.v1.model.Value) NotFoundException(com.ibm.cloud.sdk.core.service.exception.NotFoundException) NotFoundException(com.ibm.cloud.sdk.core.service.exception.NotFoundException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)6 Value (com.ibm.watson.assistant.v1.model.Value)5 GetValueOptions (com.ibm.watson.assistant.v1.model.GetValueOptions)4 HashMap (java.util.HashMap)4 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)3 CreateEntityOptions (com.ibm.watson.assistant.v1.model.CreateEntityOptions)3 CreateValueOptions (com.ibm.watson.assistant.v1.model.CreateValueOptions)3 DeleteValueOptions (com.ibm.watson.assistant.v1.model.DeleteValueOptions)3 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)3 CreateValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions)3 DeleteValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteValueOptions)3 GetValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.GetValueOptions)3 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)3 CreateValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions)3 DeleteValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteValueOptions)3 GetValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.GetValueOptions)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Value (com.ibm.watson.developer_cloud.assistant.v1.model.Value)2