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 AssistantTest method testGetEntityWOptions.
// Test the getEntity operation with a valid options model parameter
@Test
public void testGetEntityWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"entity\": \"entity\", \"description\": \"description\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"fuzzy_match\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"values\": [{\"value\": \"value\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"type\": \"synonyms\", \"synonyms\": [\"synonym\"], \"patterns\": [\"pattern\"], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}";
String getEntityPath = "/v1/workspaces/testString/entities/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the GetEntityOptions model
GetEntityOptions getEntityOptionsModel = new GetEntityOptions.Builder().workspaceId("testString").entity("testString").export(false).includeAudit(false).build();
// Invoke getEntity() with a valid options model and verify the result
Response<Entity> response = assistantService.getEntity(getEntityOptionsModel).execute();
assertNotNull(response);
Entity responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getEntityPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(Boolean.valueOf(query.get("export")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
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().getResult();
try {
assertNotNull(response);
assertNotNull(response.getEntity());
assertEquals(response.getEntity(), 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().getResult();
fail(ex.getMessage());
}
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
service.deleteEntity(deleteOptions).execute().getResult();
try {
GetEntityOptions getOptions = new GetEntityOptions.Builder(workspaceId, entity).build();
service.getEntity(getOptions).execute().getResult();
fail("deleteEntity failed");
} catch (Exception ex) {
// Expected result
assertTrue(ex instanceof NotFoundException);
}
}
Aggregations