Search in sources :

Example 1 with UpdateCounterexampleOptions

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

the class ConversationServiceIT method testUpdateCounterexample.

/**
 * Test updateCounterexample.
 */
@Test
public void testUpdateCounterexample() {
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    // gotta be unique
    String counterExampleText2 = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.createCounterexample(createOptions).execute();
    try {
        UpdateCounterexampleOptions updateOptions = new UpdateCounterexampleOptions.Builder(workspaceId, counterExampleText).newText(counterExampleText2).build();
        Counterexample response = service.updateCounterexample(updateOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getText());
        assertEquals(response.getText(), counterExampleText2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText2).build();
        service.deleteCounterexample(deleteOptions).execute();
    }
}
Also used : CreateCounterexampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexampleOptions) UpdateCounterexampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.UpdateCounterexampleOptions) DeleteCounterexampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteCounterexampleOptions) CreateCounterexample(com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexample) Counterexample(com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 2 with UpdateCounterexampleOptions

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

the class Assistant method updateCounterexample.

/**
 * Update counterexample.
 *
 * <p>Update the text of a counterexample. Counterexamples are examples that have been marked as
 * irrelevant input.
 *
 * @param updateCounterexampleOptions the {@link UpdateCounterexampleOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link Counterexample}
 */
public ServiceCall<Counterexample> updateCounterexample(UpdateCounterexampleOptions updateCounterexampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateCounterexampleOptions, "updateCounterexampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateCounterexampleOptions.workspaceId());
    pathParamsMap.put("text", updateCounterexampleOptions.text());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/counterexamples/{text}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateCounterexample");
    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 (updateCounterexampleOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateCounterexampleOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateCounterexampleOptions.newText() != null) {
        contentJson.addProperty("text", updateCounterexampleOptions.newText());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Counterexample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Counterexample>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Counterexample(com.ibm.watson.assistant.v1.model.Counterexample)

Example 3 with UpdateCounterexampleOptions

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

the class AssistantServiceIT method testUpdateCounterexample.

/**
 * Test updateCounterexample.
 */
@Test
public void testUpdateCounterexample() {
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    // gotta be unique
    String counterExampleText2 = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.createCounterexample(createOptions).execute();
    try {
        UpdateCounterexampleOptions updateOptions = new UpdateCounterexampleOptions.Builder(workspaceId, counterExampleText).newText(counterExampleText2).build();
        Counterexample response = service.updateCounterexample(updateOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getText());
        assertEquals(response.getText(), counterExampleText2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText2).build();
        service.deleteCounterexample(deleteOptions).execute();
    }
}
Also used : CreateCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions) UpdateCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.UpdateCounterexampleOptions) DeleteCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions) Counterexample(com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample) CreateCounterexample(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 4 with UpdateCounterexampleOptions

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

the class AssistantTest method testUpdateCounterexampleWOptions.

// Test the updateCounterexample operation with a valid options model parameter
@Test
public void testUpdateCounterexampleWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"text\": \"text\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String updateCounterexamplePath = "/v1/workspaces/testString/counterexamples/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the UpdateCounterexampleOptions model
    UpdateCounterexampleOptions updateCounterexampleOptionsModel = new UpdateCounterexampleOptions.Builder().workspaceId("testString").text("testString").newText("testString").includeAudit(false).build();
    // Invoke updateCounterexample() with a valid options model and verify the result
    Response<Counterexample> response = assistantService.updateCounterexample(updateCounterexampleOptionsModel).execute();
    assertNotNull(response);
    Counterexample 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, updateCounterexamplePath);
    // 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) UpdateCounterexampleOptions(com.ibm.watson.assistant.v1.model.UpdateCounterexampleOptions) Counterexample(com.ibm.watson.assistant.v1.model.Counterexample) Test(org.testng.annotations.Test)

Aggregations

Counterexample (com.ibm.watson.assistant.v1.model.Counterexample)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 UpdateCounterexampleOptions (com.ibm.watson.assistant.v1.model.UpdateCounterexampleOptions)1 Counterexample (com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample)1 CreateCounterexample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample)1 CreateCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions)1 DeleteCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions)1 UpdateCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateCounterexampleOptions)1 Counterexample (com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample)1 CreateCounterexample (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexample)1 CreateCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexampleOptions)1 DeleteCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteCounterexampleOptions)1 UpdateCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.UpdateCounterexampleOptions)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1