use of com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions 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.developer_cloud.assistant.v1.model.CreateEntityOptions in project java-sdk by watson-developer-cloud.
the class SynonymsIT method testGetSynonym.
/**
* Test getSynonym.
*/
@Test
public void testGetSynonym() {
String entity = "beverage";
String entityValue = "orange juice";
String synonym = "OJ";
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).build();
service.createValue(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
Date start = new Date();
CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
service.createSynonym(createOptions).execute();
try {
GetSynonymOptions getOptions = new GetSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).includeAudit(true).build();
Synonym response = service.getSynonym(getOptions).execute();
assertNotNull(response);
assertNotNull(response.getSynonymText());
assertEquals(response.getSynonymText(), synonym);
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));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
service.deleteSynonym(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions in project java-sdk by watson-developer-cloud.
the class SynonymsIT method testDeleteSynonym.
/**
* Test deleteSynonym.
*/
@Test
public void testDeleteSynonym() {
String entity = "beverage";
String entityValue = "orange juice";
String synonym = "OJ";
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).build();
service.createValue(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
Synonym response = service.createSynonym(createOptions).execute();
try {
assertNotNull(response);
assertNotNull(response.getSynonymText());
assertEquals(response.getSynonymText(), synonym);
} catch (Exception ex) {
DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
service.deleteSynonym(deleteOptions).execute();
fail(ex.getMessage());
}
DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).synonym(synonym).build();
service.deleteSynonym(deleteOptions).execute();
try {
GetSynonymOptions getOptions = new GetSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
service.getSynonym(getOptions).execute();
fail("deleteSynonym failed");
} catch (Exception ex) {
// Expected result
assertTrue(ex instanceof NotFoundException);
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions in project java-sdk by watson-developer-cloud.
the class ValuesIT method testGetValue.
/**
* Test getValue.
*/
@Test
public void testGetValue() {
String entity = "beverage";
String entityValue = "coffee" + UUID.randomUUID().toString();
String synonym1 = "java";
String synonym2 = "joe";
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute();
} 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).synonyms(new ArrayList<String>(Arrays.asList(synonym1, synonym2))).build();
service.createValue(createOptions).execute();
Date start = new Date();
try {
GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue).export(true).includeAudit(true).build();
ValueExport response = service.getValue(getOptions).execute();
assertNotNull(response);
assertNotNull(response.getValueText());
assertEquals(response.getValueText(), entityValue);
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));
assertNotNull(response.getSynonyms());
assertTrue(response.getSynonyms().size() == 2);
assertTrue(response.getSynonyms().contains(synonym1));
assertTrue(response.getSynonyms().contains(synonym2));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue).build();
service.deleteValue(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions 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();
} 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();
try {
assertNotNull(response);
assertNotNull(response.getValueText());
assertEquals(response.getValueText(), entityValue);
assertNull(response.getMetadata());
} catch (Exception ex) {
// Clean up
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue).build();
service.deleteValue(deleteOptions).execute();
fail(ex.getMessage());
}
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).build();
service.deleteValue(deleteOptions).execute();
try {
GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue).build();
service.getValue(getOptions).execute();
fail("deleteValue failed");
} catch (Exception ex) {
// Expected result
assertTrue(ex instanceof NotFoundException);
}
}
Aggregations