Search in sources :

Example 16 with CreateValue

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

the class AssistantTest method testCreateEntityWOptions.

// Test the createEntity operation with a valid options model parameter
@Test
public void testCreateEntityWOptions() 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 createEntityPath = "/v1/workspaces/testString/entities";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the CreateValue model
    CreateValue createValueModel = new CreateValue.Builder().value("testString").metadata(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).type("synonyms").synonyms(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).patterns(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the CreateEntityOptions model
    CreateEntityOptions createEntityOptionsModel = new CreateEntityOptions.Builder().workspaceId("testString").entity("testString").description("testString").metadata(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).fuzzyMatch(true).values(new java.util.ArrayList<CreateValue>(java.util.Arrays.asList(createValueModel))).includeAudit(false).build();
    // Invoke createEntity() with a valid options model and verify the result
    Response<Entity> response = assistantService.createEntity(createEntityOptionsModel).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(), "POST");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, createEntityPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Entity(com.ibm.watson.assistant.v1.model.Entity) CreateEntity(com.ibm.watson.assistant.v1.model.CreateEntity) RuntimeEntity(com.ibm.watson.assistant.v1.model.RuntimeEntity) CreateValue(com.ibm.watson.assistant.v1.model.CreateValue) CreateEntityOptions(com.ibm.watson.assistant.v1.model.CreateEntityOptions) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.Test)10 HashMap (java.util.HashMap)8 CreateValue (com.ibm.watson.assistant.v1.model.CreateValue)6 MockResponse (okhttp3.mockwebserver.MockResponse)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 Test (org.testng.annotations.Test)5 CreateEntity (com.ibm.watson.assistant.v1.model.CreateEntity)4 Value (com.ibm.watson.assistant.v1.model.Value)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 CreateValue (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue)4 CreateValue (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue)4 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)4 ArrayList (java.util.ArrayList)4 CreateEntityOptions (com.ibm.watson.assistant.v1.model.CreateEntityOptions)3 Entity (com.ibm.watson.assistant.v1.model.Entity)3 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)2 Counterexample (com.ibm.watson.assistant.v1.model.Counterexample)2 CreateIntent (com.ibm.watson.assistant.v1.model.CreateIntent)2 CreateValueOptions (com.ibm.watson.assistant.v1.model.CreateValueOptions)2 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)2