Search in sources :

Example 1 with UpdateExampleOptions

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

the class AssistantTest method testUpdateExampleWOptions.

// Test the updateExample operation with a valid options model parameter
@Test
public void testUpdateExampleWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"text\": \"text\", \"mentions\": [{\"entity\": \"entity\", \"location\": [8]}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String updateExamplePath = "/v1/workspaces/testString/intents/testString/examples/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the Mention model
    Mention mentionModel = new Mention.Builder().entity("testString").location(new java.util.ArrayList<Long>(java.util.Arrays.asList(Long.valueOf("26")))).build();
    // Construct an instance of the UpdateExampleOptions model
    UpdateExampleOptions updateExampleOptionsModel = new UpdateExampleOptions.Builder().workspaceId("testString").intent("testString").text("testString").newText("testString").newMentions(new java.util.ArrayList<Mention>(java.util.Arrays.asList(mentionModel))).includeAudit(false).build();
    // Invoke updateExample() with a valid options model and verify the result
    Response<Example> response = assistantService.updateExample(updateExampleOptionsModel).execute();
    assertNotNull(response);
    Example 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, updateExamplePath);
    // 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) Mention(com.ibm.watson.assistant.v1.model.Mention) Example(com.ibm.watson.assistant.v1.model.Example) UpdateExampleOptions(com.ibm.watson.assistant.v1.model.UpdateExampleOptions) Test(org.testng.annotations.Test)

Example 2 with UpdateExampleOptions

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

the class AssistantServiceIT method testUpdateExample.

/**
 * Test updateExample.
 */
@Test
public void testUpdateExample() {
    createExampleIntent();
    // gotta be unique
    String exampleText = "Howdy " + UUID.randomUUID().toString();
    // gotta be unique
    String exampleText2 = "Howdy " + UUID.randomUUID().toString();
    CreateExampleOptions createOptions = new CreateExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
    service.createExample(createOptions).execute();
    try {
        UpdateExampleOptions updateOptions = new UpdateExampleOptions.Builder(workspaceId, exampleIntent, exampleText).newText(exampleText2).build();
        Example response = service.updateExample(updateOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getExampleText());
        assertEquals(response.getExampleText(), exampleText2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteExampleOptions deleteOptions = new DeleteExampleOptions.Builder(workspaceId, exampleIntent, exampleText2).build();
        service.deleteExample(deleteOptions).execute();
    }
}
Also used : CreateExampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateExampleOptions) CreateExample(com.ibm.watson.developer_cloud.assistant.v1.model.CreateExample) Example(com.ibm.watson.developer_cloud.assistant.v1.model.Example) DeleteExampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteExampleOptions) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) UpdateExampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.UpdateExampleOptions) Test(org.junit.Test)

Example 3 with UpdateExampleOptions

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

the class ConversationServiceIT method testUpdateExample.

/**
 * Test updateExample.
 */
@Test
public void testUpdateExample() {
    createExampleIntent();
    // gotta be unique
    String exampleText = "Howdy " + UUID.randomUUID().toString();
    // gotta be unique
    String exampleText2 = "Howdy " + UUID.randomUUID().toString();
    CreateExampleOptions createOptions = new CreateExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
    service.createExample(createOptions).execute();
    try {
        UpdateExampleOptions updateOptions = new UpdateExampleOptions.Builder(workspaceId, exampleIntent, exampleText).newText(exampleText2).build();
        Example response = service.updateExample(updateOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getExampleText());
        assertEquals(response.getExampleText(), exampleText2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteExampleOptions deleteOptions = new DeleteExampleOptions.Builder(workspaceId, exampleIntent, exampleText2).build();
        service.deleteExample(deleteOptions).execute();
    }
}
Also used : CreateExampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateExampleOptions) CreateExample(com.ibm.watson.developer_cloud.conversation.v1.model.CreateExample) Example(com.ibm.watson.developer_cloud.conversation.v1.model.Example) DeleteExampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteExampleOptions) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) UpdateExampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.UpdateExampleOptions) Test(org.junit.Test)

Example 4 with UpdateExampleOptions

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

the class Assistant method updateExample.

/**
 * Update user input example.
 *
 * <p>Update the text of a user input example.
 *
 * <p>If you want to update multiple examples with a single API call, consider using the **[Update
 * intent](#update-intent)** method instead.
 *
 * @param updateExampleOptions the {@link UpdateExampleOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Example}
 */
public ServiceCall<Example> updateExample(UpdateExampleOptions updateExampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateExampleOptions, "updateExampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateExampleOptions.workspaceId());
    pathParamsMap.put("intent", updateExampleOptions.intent());
    pathParamsMap.put("text", updateExampleOptions.text());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/intents/{intent}/examples/{text}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateExample");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    if (updateExampleOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateExampleOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateExampleOptions.newText() != null) {
        contentJson.addProperty("text", updateExampleOptions.newText());
    }
    if (updateExampleOptions.newMentions() != null) {
        contentJson.add("mentions", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateExampleOptions.newMentions()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Example> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Example>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Example(com.ibm.watson.assistant.v1.model.Example) JsonObject(com.google.gson.JsonObject)

Aggregations

Example (com.ibm.watson.assistant.v1.model.Example)2 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)2 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 Mention (com.ibm.watson.assistant.v1.model.Mention)1 UpdateExampleOptions (com.ibm.watson.assistant.v1.model.UpdateExampleOptions)1 CreateExample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateExample)1 CreateExampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateExampleOptions)1 DeleteExampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteExampleOptions)1 Example (com.ibm.watson.developer_cloud.assistant.v1.model.Example)1 UpdateExampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateExampleOptions)1 CreateExample (com.ibm.watson.developer_cloud.conversation.v1.model.CreateExample)1 CreateExampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateExampleOptions)1 DeleteExampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteExampleOptions)1 Example (com.ibm.watson.developer_cloud.conversation.v1.model.Example)1 UpdateExampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.UpdateExampleOptions)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1