Search in sources :

Example 1 with DeleteEntityOptions

use of com.ibm.watson.assistant.v1.model.DeleteEntityOptions 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 DeleteEntityOptions

use of com.ibm.watson.assistant.v1.model.DeleteEntityOptions 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();
    }
}
Also used : Entity(com.ibm.watson.developer_cloud.assistant.v1.model.Entity) HashMap(java.util.HashMap) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) DeleteEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteEntityOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 3 with DeleteEntityOptions

use of com.ibm.watson.assistant.v1.model.DeleteEntityOptions 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 4 with DeleteEntityOptions

use of com.ibm.watson.assistant.v1.model.DeleteEntityOptions 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);
    }
}
Also used : Entity(com.ibm.watson.developer_cloud.assistant.v1.model.Entity) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) DeleteEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteEntityOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) GetEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetEntityOptions) Test(org.junit.Test)

Example 5 with DeleteEntityOptions

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

the class AssistantTest method testDeleteEntityWOptions.

// Test the deleteEntity operation with a valid options model parameter
@Test
public void testDeleteEntityWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "";
    String deleteEntityPath = "/v1/workspaces/testString/entities/testString";
    server.enqueue(new MockResponse().setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the DeleteEntityOptions model
    DeleteEntityOptions deleteEntityOptionsModel = new DeleteEntityOptions.Builder().workspaceId("testString").entity("testString").build();
    // Invoke deleteEntity() with a valid options model and verify the result
    Response<Void> response = assistantService.deleteEntity(deleteEntityOptionsModel).execute();
    assertNotNull(response);
    Void responseObj = response.getResult();
    assertNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "DELETE");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteEntityPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteEntityOptions(com.ibm.watson.assistant.v1.model.DeleteEntityOptions) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.Test)18 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)12 DeleteEntityOptions (com.ibm.watson.assistant.v1.model.DeleteEntityOptions)7 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)6 CreateEntityOptions (com.ibm.watson.assistant.v1.model.CreateEntityOptions)6 Entity (com.ibm.watson.assistant.v1.model.Entity)6 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)6 DeleteEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteEntityOptions)6 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)6 DeleteEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteEntityOptions)6 HashMap (java.util.HashMap)6 Ignore (org.junit.Ignore)6 CreateValue (com.ibm.watson.assistant.v1.model.CreateValue)3 CreateValue (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue)3 Entity (com.ibm.watson.developer_cloud.assistant.v1.model.Entity)3 EntityExport (com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport)3 CreateValue (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue)3 Entity (com.ibm.watson.developer_cloud.conversation.v1.model.Entity)3 EntityExport (com.ibm.watson.developer_cloud.conversation.v1.model.EntityExport)3 ArrayList (java.util.ArrayList)3