Search in sources :

Example 1 with EntityExport

use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport in project java-sdk by watson-developer-cloud.

the class EntitiesIT method testListEntitiesWithPaging.

/**
 * Test listEntities with pagination.
 */
@Test
@Ignore("To be run locally until we fix the Rate limitation issue")
public void testListEntitiesWithPaging() {
    // gotta be unique
    String entity1 = "Hello" + UUID.randomUUID().toString();
    // gotta be unique
    String entity2 = "Goodbye" + UUID.randomUUID().toString();
    CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity1).build();
    service.createEntity(createOptions).execute();
    service.createEntity(createOptions.newBuilder().entity(entity2).build()).execute();
    try {
        ListEntitiesOptions listOptions = new ListEntitiesOptions.Builder(workspaceId).sort("entity").pageLimit(1L).build();
        EntityCollection response = service.listEntities(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getEntities());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        assertNotNull(response.getPagination().getNextUrl());
        assertNotNull(response.getPagination().getCursor());
        assertTrue(!response.getEntities().get(0).getEntityName().equals(entity1));
        EntityExport ieResponse = null;
        while (response.getPagination().getCursor() != null) {
            assertNotNull(response.getEntities());
            assertTrue(response.getEntities().size() == 1);
            if (response.getEntities().get(0).getEntityName().equals(entity1)) {
                ieResponse = response.getEntities().get(0);
                break;
            }
            String cursor = response.getPagination().getCursor();
            response = service.listEntities(listOptions.newBuilder().cursor(cursor).build()).execute();
        }
        assertNotNull(ieResponse);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity1).build();
        service.deleteEntity(deleteOptions).execute();
        service.deleteEntity(deleteOptions.newBuilder().entity(entity2).build()).execute();
    }
}
Also used : EntityExport(com.ibm.watson.developer_cloud.conversation.v1.model.EntityExport) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) EntityCollection(com.ibm.watson.developer_cloud.conversation.v1.model.EntityCollection) DeleteEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteEntityOptions) ListEntitiesOptions(com.ibm.watson.developer_cloud.conversation.v1.model.ListEntitiesOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with EntityExport

use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport in project java-sdk by watson-developer-cloud.

the class EntitiesIT method testListEntities.

/**
 * Test listEntities.
 */
@Test
@Ignore("To be run locally until we fix the Rate limitation issue")
public void testListEntities() {
    // gotta be unique
    String entity = "Hello" + UUID.randomUUID().toString();
    try {
        ListEntitiesOptions listOptions = new ListEntitiesOptions.Builder(workspaceId).build();
        EntityCollection response = service.listEntities(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getEntities());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        // nextUrl may be null
        // Now add an entity and make sure we get it back
        String entityDescription = "Description of " + entity;
        String entityValue = "Value of " + entity;
        CreateEntityOptions options = new CreateEntityOptions.Builder(workspaceId, entity).description(entityDescription).addValue(new CreateValue.Builder(entityValue).build()).build();
        service.createEntity(options).execute();
        ListEntitiesOptions listOptions2 = listOptions.newBuilder().sort("-updated").pageLimit(5L).export(true).build();
        EntityCollection response2 = service.listEntities(listOptions2).execute();
        assertNotNull(response2);
        assertNotNull(response2.getEntities());
        List<EntityExport> entities = response2.getEntities();
        EntityExport ieResponse = null;
        for (EntityExport resp : entities) {
            if (resp.getEntityName().equals(entity)) {
                ieResponse = resp;
                break;
            }
        }
        assertNotNull(ieResponse);
        assertNotNull(ieResponse.getDescription());
        assertEquals(ieResponse.getDescription(), entityDescription);
        assertNotNull(ieResponse.getValues());
        assertTrue(ieResponse.getValues().size() == 1);
        assertTrue(ieResponse.getValues().get(0).getValueText().equals(entityValue));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
        service.deleteEntity(deleteOptions).execute();
    }
}
Also used : CreateValue(com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) EntityExport(com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport) EntityCollection(com.ibm.watson.developer_cloud.assistant.v1.model.EntityCollection) DeleteEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteEntityOptions) ListEntitiesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListEntitiesOptions) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with EntityExport

use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport 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();
    }
}
Also used : CreateValue(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) ArrayList(java.util.ArrayList) Date(java.util.Date) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) EntityExport(com.ibm.watson.developer_cloud.conversation.v1.model.EntityExport) ValueExport(com.ibm.watson.developer_cloud.conversation.v1.model.ValueExport) DeleteEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteEntityOptions) GetEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetEntityOptions) Test(org.junit.Test)

Example 4 with EntityExport

use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport in project java-sdk by watson-developer-cloud.

the class EntitiesIT method testListEntities.

/**
 * Test listEntities.
 */
@Test
@Ignore("To be run locally until we fix the Rate limitation issue")
public void testListEntities() {
    // gotta be unique
    String entity = "Hello" + UUID.randomUUID().toString();
    try {
        ListEntitiesOptions listOptions = new ListEntitiesOptions.Builder(workspaceId).build();
        EntityCollection response = service.listEntities(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getEntities());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        // nextUrl may be null
        // Now add an entity and make sure we get it back
        String entityDescription = "Description of " + entity;
        String entityValue = "Value of " + entity;
        CreateEntityOptions options = new CreateEntityOptions.Builder(workspaceId, entity).description(entityDescription).addValue(new CreateValue.Builder(entityValue).build()).build();
        service.createEntity(options).execute();
        ListEntitiesOptions listOptions2 = listOptions.newBuilder().sort("-updated").pageLimit(5L).export(true).build();
        EntityCollection response2 = service.listEntities(listOptions2).execute();
        assertNotNull(response2);
        assertNotNull(response2.getEntities());
        List<EntityExport> entities = response2.getEntities();
        EntityExport ieResponse = null;
        for (EntityExport resp : entities) {
            if (resp.getEntityName().equals(entity)) {
                ieResponse = resp;
                break;
            }
        }
        assertNotNull(ieResponse);
        assertNotNull(ieResponse.getDescription());
        assertEquals(ieResponse.getDescription(), entityDescription);
        assertNotNull(ieResponse.getValues());
        assertTrue(ieResponse.getValues().size() == 1);
        assertTrue(ieResponse.getValues().get(0).getValueText().equals(entityValue));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
        service.deleteEntity(deleteOptions).execute();
    }
}
Also used : CreateValue(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) EntityExport(com.ibm.watson.developer_cloud.conversation.v1.model.EntityExport) EntityCollection(com.ibm.watson.developer_cloud.conversation.v1.model.EntityCollection) DeleteEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteEntityOptions) ListEntitiesOptions(com.ibm.watson.developer_cloud.conversation.v1.model.ListEntitiesOptions) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with EntityExport

use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport in project java-sdk by watson-developer-cloud.

the class EntitiesIT method testListEntitiesWithPaging.

/**
 * Test listEntities with pagination.
 */
@Test
@Ignore("To be run locally until we fix the Rate limitation issue")
public void testListEntitiesWithPaging() {
    // gotta be unique
    String entity1 = "Hello" + UUID.randomUUID().toString();
    // gotta be unique
    String entity2 = "Goodbye" + UUID.randomUUID().toString();
    CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity1).build();
    service.createEntity(createOptions).execute();
    service.createEntity(createOptions.newBuilder().entity(entity2).build()).execute();
    try {
        ListEntitiesOptions listOptions = new ListEntitiesOptions.Builder(workspaceId).sort("entity").pageLimit(1L).build();
        EntityCollection response = service.listEntities(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getEntities());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        assertNotNull(response.getPagination().getNextUrl());
        assertNotNull(response.getPagination().getCursor());
        assertTrue(!response.getEntities().get(0).getEntityName().equals(entity1));
        EntityExport ieResponse = null;
        while (response.getPagination().getCursor() != null) {
            assertNotNull(response.getEntities());
            assertTrue(response.getEntities().size() == 1);
            if (response.getEntities().get(0).getEntityName().equals(entity1)) {
                ieResponse = response.getEntities().get(0);
                break;
            }
            String cursor = response.getPagination().getCursor();
            response = service.listEntities(listOptions.newBuilder().cursor(cursor).build()).execute();
        }
        assertNotNull(ieResponse);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity1).build();
        service.deleteEntity(deleteOptions).execute();
        service.deleteEntity(deleteOptions.newBuilder().entity(entity2).build()).execute();
    }
}
Also used : EntityExport(com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) EntityCollection(com.ibm.watson.developer_cloud.assistant.v1.model.EntityCollection) DeleteEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteEntityOptions) ListEntitiesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListEntitiesOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)6 Test (org.junit.Test)6 EntityExport (com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport)4 EntityExport (com.ibm.watson.developer_cloud.conversation.v1.model.EntityExport)4 Ignore (org.junit.Ignore)4 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)3 DeleteEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteEntityOptions)3 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)3 DeleteEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteEntityOptions)3 CreateValue (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue)2 EntityCollection (com.ibm.watson.developer_cloud.assistant.v1.model.EntityCollection)2 ListEntitiesOptions (com.ibm.watson.developer_cloud.assistant.v1.model.ListEntitiesOptions)2 CreateValue (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue)2 EntityCollection (com.ibm.watson.developer_cloud.conversation.v1.model.EntityCollection)2 ListEntitiesOptions (com.ibm.watson.developer_cloud.conversation.v1.model.ListEntitiesOptions)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 GetEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.GetEntityOptions)1 ValueExport (com.ibm.watson.developer_cloud.assistant.v1.model.ValueExport)1