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);
}
}
Aggregations