Search in sources :

Example 56 with Entity

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

the class AssistantTest method testListEntitiesWOptions.

// Test the listEntities operation with a valid options model parameter
@Test
public void testListEntitiesWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"entities\": [{\"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\"}]}], \"pagination\": {\"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5, \"matched\": 7, \"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\"}}";
    String listEntitiesPath = "/v1/workspaces/testString/entities";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListEntitiesOptions model
    ListEntitiesOptions listEntitiesOptionsModel = new ListEntitiesOptions.Builder().workspaceId("testString").export(false).pageLimit(Long.valueOf("26")).includeCount(false).sort("entity").cursor("testString").includeAudit(false).build();
    // Invoke listEntities() with a valid options model and verify the result
    Response<EntityCollection> response = assistantService.listEntities(listEntitiesOptionsModel).execute();
    assertNotNull(response);
    EntityCollection 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, listEntitiesPath);
    // 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(Long.valueOf(query.get("page_limit")), Long.valueOf("26"));
    assertEquals(Boolean.valueOf(query.get("include_count")), Boolean.valueOf(false));
    assertEquals(query.get("sort"), "entity");
    assertEquals(query.get("cursor"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) EntityCollection(com.ibm.watson.assistant.v1.model.EntityCollection) ListEntitiesOptions(com.ibm.watson.assistant.v1.model.ListEntitiesOptions) Test(org.testng.annotations.Test)

Example 57 with Entity

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

the class AssistantTest method testDeleteValueWOptions.

// Test the deleteValue operation with a valid options model parameter
@Test
public void testDeleteValueWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "";
    String deleteValuePath = "/v1/workspaces/testString/entities/testString/values/testString";
    server.enqueue(new MockResponse().setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the DeleteValueOptions model
    DeleteValueOptions deleteValueOptionsModel = new DeleteValueOptions.Builder().workspaceId("testString").entity("testString").value("testString").build();
    // Invoke deleteValue() with a valid options model and verify the result
    Response<Void> response = assistantService.deleteValue(deleteValueOptionsModel).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, deleteValuePath);
    // 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) DeleteValueOptions(com.ibm.watson.assistant.v1.model.DeleteValueOptions) Test(org.testng.annotations.Test)

Example 58 with Entity

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

the class AssistantTest method testListValuesWOptions.

// Test the listValues operation with a valid options model parameter
@Test
public void testListValuesWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"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\"}], \"pagination\": {\"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5, \"matched\": 7, \"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\"}}";
    String listValuesPath = "/v1/workspaces/testString/entities/testString/values";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListValuesOptions model
    ListValuesOptions listValuesOptionsModel = new ListValuesOptions.Builder().workspaceId("testString").entity("testString").export(false).pageLimit(Long.valueOf("26")).includeCount(false).sort("value").cursor("testString").includeAudit(false).build();
    // Invoke listValues() with a valid options model and verify the result
    Response<ValueCollection> response = assistantService.listValues(listValuesOptionsModel).execute();
    assertNotNull(response);
    ValueCollection 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, listValuesPath);
    // 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(Long.valueOf(query.get("page_limit")), Long.valueOf("26"));
    assertEquals(Boolean.valueOf(query.get("include_count")), Boolean.valueOf(false));
    assertEquals(query.get("sort"), "value");
    assertEquals(query.get("cursor"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListValuesOptions(com.ibm.watson.assistant.v1.model.ListValuesOptions) ValueCollection(com.ibm.watson.assistant.v1.model.ValueCollection) Test(org.testng.annotations.Test)

Example 59 with Entity

use of com.ibm.watson.assistant.v1.model.Entity 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));
}
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) GetEntityOptions(com.ibm.watson.assistant.v1.model.GetEntityOptions) Test(org.testng.annotations.Test)

Example 60 with Entity

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

the class AssistantTest method testUpdateValueWOptions.

// Test the updateValue operation with a valid options model parameter
@Test
public void testUpdateValueWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"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 updateValuePath = "/v1/workspaces/testString/entities/testString/values/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the UpdateValueOptions model
    UpdateValueOptions updateValueOptionsModel = new UpdateValueOptions.Builder().workspaceId("testString").entity("testString").value("testString").newValue("testString").newMetadata(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).newType("synonyms").newSynonyms(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).newPatterns(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).append(false).includeAudit(false).build();
    // Invoke updateValue() with a valid options model and verify the result
    Response<Value> response = assistantService.updateValue(updateValueOptionsModel).execute();
    assertNotNull(response);
    Value 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, updateValuePath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("append")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateValueOptions(com.ibm.watson.assistant.v1.model.UpdateValueOptions) DialogNodeOutputOptionsElementValue(com.ibm.watson.assistant.v1.model.DialogNodeOutputOptionsElementValue) CreateValue(com.ibm.watson.assistant.v1.model.CreateValue) Value(com.ibm.watson.assistant.v1.model.Value) Test(org.testng.annotations.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)32 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)32 Test (org.testng.annotations.Test)32 HashMap (java.util.HashMap)27 Test (org.junit.Test)24 CreateEntityOptions (com.ibm.watson.assistant.v1.model.CreateEntityOptions)19 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)18 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)13 CreateValueOptions (com.ibm.watson.assistant.v1.model.CreateValueOptions)13 Entity (com.ibm.watson.assistant.v1.model.Entity)12 Value (com.ibm.watson.assistant.v1.model.Value)12 Synonym (com.ibm.watson.assistant.v1.model.Synonym)11 JsonObject (com.google.gson.JsonObject)10 CreateValue (com.ibm.watson.assistant.v1.model.CreateValue)10 Entity (model.Entity)10 CreateSynonymOptions (com.ibm.watson.assistant.v1.model.CreateSynonymOptions)7 DeleteEntityOptions (com.ibm.watson.assistant.v1.model.DeleteEntityOptions)7 DeleteSynonymOptions (com.ibm.watson.assistant.v1.model.DeleteSynonymOptions)7 DeleteValueOptions (com.ibm.watson.assistant.v1.model.DeleteValueOptions)7 Example (com.ibm.watson.assistant.v1.model.Example)7