use of com.ibm.watson.assistant.v1.model.GetEntityOptions 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.GetEntityOptions in project java-sdk by watson-developer-cloud.
the class Assistant method getEntity.
/**
* Get entity.
*
* <p>Get information about an entity, optionally including all entity content.
*
* @param getEntityOptions the {@link GetEntityOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Entity}
*/
public ServiceCall<Entity> getEntity(GetEntityOptions getEntityOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getEntityOptions, "getEntityOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("workspace_id", getEntityOptions.workspaceId());
pathParamsMap.put("entity", getEntityOptions.entity());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "getEntity");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
if (getEntityOptions.export() != null) {
builder.query("export", String.valueOf(getEntityOptions.export()));
}
if (getEntityOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(getEntityOptions.includeAudit()));
}
ResponseConverter<Entity> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Entity>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.assistant.v1.model.GetEntityOptions in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testGetEntity.
/**
* Test getEntity.
*/
@Test
public void testGetEntity() {
// gotta be unique
String entity = "Hello" + UUID.randomUUID().toString();
String entityDescription = "Description of " + entity;
String entityValue = "Value of " + entity;
List<CreateValue> entityValues = new ArrayList<CreateValue>();
entityValues.add(new CreateValue.Builder().value(entityValue).build());
CreateEntityOptions.Builder optionsBuilder = new CreateEntityOptions.Builder();
optionsBuilder.workspaceId(workspaceId);
optionsBuilder.entity(entity);
optionsBuilder.description(entityDescription);
optionsBuilder.values(entityValues);
service.createEntity(optionsBuilder.build()).execute().getResult();
Date start = new Date();
try {
GetEntityOptions getOptions = new GetEntityOptions.Builder(workspaceId, entity).export(true).includeAudit(true).build();
Entity response = service.getEntity(getOptions).execute().getResult();
assertNotNull(response);
assertNotNull(response.getEntity());
assertEquals(response.getEntity(), entity);
assertNotNull(response.getDescription());
assertEquals(response.getDescription(), entityDescription);
assertNotNull(response.getValues());
assertNotNull(response.getCreated());
assertNotNull(response.getUpdated());
Date now = new Date();
assertTrue(fuzzyBefore(response.getCreated(), now));
assertTrue(fuzzyAfter(response.getCreated(), start));
assertTrue(fuzzyBefore(response.getUpdated(), now));
assertTrue(fuzzyAfter(response.getUpdated(), start));
List<Value> values = response.getValues();
assertTrue(values.size() == 1);
assertEquals(values.get(0).value(), entityValue);
assertTrue(fuzzyBefore(values.get(0).created(), now));
assertTrue(fuzzyAfter(values.get(0).created(), start));
assertTrue(fuzzyBefore(values.get(0).updated(), now));
assertTrue(fuzzyAfter(values.get(0).updated(), start));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
service.deleteEntity(deleteOptions).execute().getResult();
}
}
use of com.ibm.watson.assistant.v1.model.GetEntityOptions in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testGetEntity.
/**
* Test getEntity.
*/
@Test
public void testGetEntity() {
// gotta be unique
String entity = "Hello" + UUID.randomUUID().toString();
String entityDescription = "Description of " + entity;
String entityValue = "Value of " + entity;
List<CreateValue> entityValues = new ArrayList<CreateValue>();
entityValues.add(new CreateValue.Builder().value(entityValue).build());
CreateEntityOptions.Builder optionsBuilder = new CreateEntityOptions.Builder();
optionsBuilder.workspaceId(workspaceId);
optionsBuilder.entity(entity);
optionsBuilder.description(entityDescription);
optionsBuilder.values(entityValues);
service.createEntity(optionsBuilder.build()).execute();
Date start = new Date();
try {
GetEntityOptions getOptions = new GetEntityOptions.Builder(workspaceId, entity).export(true).includeAudit(true).build();
EntityExport response = service.getEntity(getOptions).execute();
assertNotNull(response);
assertNotNull(response.getEntityName());
assertEquals(response.getEntityName(), entity);
assertNotNull(response.getDescription());
assertEquals(response.getDescription(), entityDescription);
assertNotNull(response.getValues());
assertNotNull(response.getCreated());
assertNotNull(response.getUpdated());
Date now = new Date();
assertTrue(fuzzyBefore(response.getCreated(), now));
assertTrue(fuzzyAfter(response.getCreated(), start));
assertTrue(fuzzyBefore(response.getUpdated(), now));
assertTrue(fuzzyAfter(response.getUpdated(), start));
List<ValueExport> values = response.getValues();
assertTrue(values.size() == 1);
assertEquals(values.get(0).getValueText(), entityValue);
assertTrue(fuzzyBefore(values.get(0).getCreated(), now));
assertTrue(fuzzyAfter(values.get(0).getCreated(), start));
assertTrue(fuzzyBefore(values.get(0).getUpdated(), now));
assertTrue(fuzzyAfter(values.get(0).getUpdated(), start));
} 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.GetEntityOptions 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);
}
}
Aggregations