use of com.ibm.watson.assistant.v1.model.Entity in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testDeleteEntity.
/**
* Test deleteEntity.
*/
@Test
public void testDeleteEntity() {
// gotta be unique
String entity = "Hello" + UUID.randomUUID().toString();
CreateEntityOptions options = new CreateEntityOptions.Builder(workspaceId, entity).build();
Entity response = service.createEntity(options).execute();
try {
assertNotNull(response);
assertNotNull(response.getEntityName());
assertEquals(response.getEntityName(), entity);
assertNull(response.getDescription());
assertNull(response.getMetadata());
assertTrue(response.isFuzzyMatch() == null || response.isFuzzyMatch().equals(Boolean.FALSE));
} catch (Exception ex) {
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
service.deleteEntity(deleteOptions).execute();
fail(ex.getMessage());
}
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
service.deleteEntity(deleteOptions).execute();
try {
GetEntityOptions getOptions = new GetEntityOptions.Builder(workspaceId, entity).build();
service.getEntity(getOptions).execute();
fail("deleteEntity failed");
} catch (Exception ex) {
// Expected result
assertTrue(ex instanceof NotFoundException);
}
}
use of com.ibm.watson.assistant.v1.model.Entity in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testUpdateEntity.
/**
* Test updateEntity.
*/
@Test
public void testUpdateEntity() {
// gotta be unique
String entity = "Hello" + UUID.randomUUID().toString();
// gotta be unique
String entity2 = "Goodbye" + UUID.randomUUID().toString();
String entityDescription = "Description of " + entity;
CreateEntityOptions.Builder createOptionsBuilder = new CreateEntityOptions.Builder();
createOptionsBuilder.workspaceId(workspaceId);
createOptionsBuilder.entity(entity);
createOptionsBuilder.description(entityDescription);
service.createEntity(createOptionsBuilder.build()).execute();
try {
String entityDescription2 = "Description of " + entity2;
String entityValue2 = "Value of " + entity2;
Map<String, Object> entityMetadata2 = new HashMap<String, Object>();
String metadataValue2 = "value for " + entity2;
entityMetadata2.put("key", metadataValue2);
UpdateEntityOptions.Builder updateOptionsBuilder = new UpdateEntityOptions.Builder(workspaceId, entity);
updateOptionsBuilder.newEntity(entity2);
updateOptionsBuilder.newDescription(entityDescription2);
updateOptionsBuilder.addValue(new CreateValue.Builder().value(entityValue2).build());
updateOptionsBuilder.newMetadata(entityMetadata2);
updateOptionsBuilder.newFuzzyMatch(true);
Entity response = service.updateEntity(updateOptionsBuilder.build()).execute();
assertNotNull(response);
assertNotNull(response.getEntityName());
assertEquals(response.getEntityName(), entity2);
assertNotNull(response.getDescription());
assertEquals(response.getDescription(), entityDescription2);
assertNotNull(response.getMetadata());
assertNotNull(response.getMetadata().get("key"));
assertEquals(response.getMetadata().get("key"), metadataValue2);
assertNotNull(response.isFuzzyMatch());
assertTrue(response.isFuzzyMatch());
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity2).build();
service.deleteEntity(deleteOptions).execute();
}
}
use of com.ibm.watson.assistant.v1.model.Entity in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testCreateEntity.
/**
* Test createEntity.
*/
@Test
public void testCreateEntity() {
// gotta be unique
String entity = "Hello" + UUID.randomUUID().toString();
String entityDescription = "Description of " + entity;
Map<String, Object> entityMetadata = new HashMap<String, Object>();
String metadataValue = "value for " + entity;
entityMetadata.put("key", metadataValue);
CreateEntityOptions.Builder optionsBuilder = new CreateEntityOptions.Builder();
optionsBuilder.workspaceId(workspaceId);
optionsBuilder.entity(entity);
optionsBuilder.description(entityDescription);
optionsBuilder.metadata(entityMetadata);
// default is false
optionsBuilder.fuzzyMatch(true);
Entity response = service.createEntity(optionsBuilder.build()).execute();
try {
assertNotNull(response);
assertNotNull(response.getEntityName());
assertEquals(response.getEntityName(), entity);
assertNotNull(response.getDescription());
assertEquals(response.getDescription(), entityDescription);
assertNotNull(response.getMetadata());
assertNotNull(response.getMetadata().get("key"));
assertEquals(response.getMetadata().get("key"), metadataValue);
assertNotNull(response.isFuzzyMatch());
assertTrue(response.isFuzzyMatch());
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
service.deleteEntity(deleteOptions).execute();
}
}
use of com.ibm.watson.assistant.v1.model.Entity in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testUpdateEntity.
/**
* Test updateEntity.
*/
@Test
public void testUpdateEntity() {
// gotta be unique
String entity = "Hello" + UUID.randomUUID().toString();
// gotta be unique
String entity2 = "Goodbye" + UUID.randomUUID().toString();
String entityDescription = "Description of " + entity;
CreateEntityOptions.Builder createOptionsBuilder = new CreateEntityOptions.Builder();
createOptionsBuilder.workspaceId(workspaceId);
createOptionsBuilder.entity(entity);
createOptionsBuilder.description(entityDescription);
service.createEntity(createOptionsBuilder.build()).execute();
try {
String entityDescription2 = "Description of " + entity2;
String entityValue2 = "Value of " + entity2;
Map<String, Object> entityMetadata2 = new HashMap<String, Object>();
String metadataValue2 = "value for " + entity2;
entityMetadata2.put("key", metadataValue2);
UpdateEntityOptions.Builder updateOptionsBuilder = new UpdateEntityOptions.Builder(workspaceId, entity);
updateOptionsBuilder.newEntity(entity2);
updateOptionsBuilder.newDescription(entityDescription2);
updateOptionsBuilder.addValue(new CreateValue.Builder().value(entityValue2).build());
updateOptionsBuilder.newMetadata(entityMetadata2);
updateOptionsBuilder.newFuzzyMatch(true);
Entity response = service.updateEntity(updateOptionsBuilder.build()).execute();
assertNotNull(response);
assertNotNull(response.getEntityName());
assertEquals(response.getEntityName(), entity2);
assertNotNull(response.getDescription());
assertEquals(response.getDescription(), entityDescription2);
assertNotNull(response.getMetadata());
assertNotNull(response.getMetadata().get("key"));
assertEquals(response.getMetadata().get("key"), metadataValue2);
assertNotNull(response.isFuzzyMatch());
assertTrue(response.isFuzzyMatch());
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity2).build();
service.deleteEntity(deleteOptions).execute();
}
}
use of com.ibm.watson.assistant.v1.model.Entity in project java-sdk by watson-developer-cloud.
the class Conversation method updateEntity.
/**
* Update entity.
*
* Update an existing entity with new or modified data.
*
* @param updateEntityOptions the {@link UpdateEntityOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Entity}
*/
public ServiceCall<Entity> updateEntity(UpdateEntityOptions updateEntityOptions) {
Validator.notNull(updateEntityOptions, "updateEntityOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "entities" };
String[] pathParameters = { updateEntityOptions.workspaceId(), updateEntityOptions.entity() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (updateEntityOptions.newFuzzyMatch() != null) {
contentJson.addProperty("fuzzy_match", updateEntityOptions.newFuzzyMatch());
}
if (updateEntityOptions.newEntity() != null) {
contentJson.addProperty("entity", updateEntityOptions.newEntity());
}
if (updateEntityOptions.newMetadata() != null) {
contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(updateEntityOptions.newMetadata()));
}
if (updateEntityOptions.newValues() != null) {
contentJson.add("values", GsonSingleton.getGson().toJsonTree(updateEntityOptions.newValues()));
}
if (updateEntityOptions.newDescription() != null) {
contentJson.addProperty("description", updateEntityOptions.newDescription());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Entity.class));
}
Aggregations