Search in sources :

Example 1 with GetExampleOptions

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

the class ConversationServiceIT method testDeleteExample.

/**
 * Test deleteExample.
 */
@Test
public void testDeleteExample() {
    createExampleIntent();
    // gotta be unique
    String exampleText = "Howdy " + UUID.randomUUID().toString();
    CreateExampleOptions createOptions = new CreateExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
    service.createExample(createOptions).execute();
    DeleteExampleOptions deleteOptions = new DeleteExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
    service.deleteExample(deleteOptions).execute();
    try {
        GetExampleOptions getOptions = new GetExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
        service.getExample(getOptions).execute();
        fail("deleteCounterexample failed");
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
    }
}
Also used : CreateExampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateExampleOptions) GetExampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetExampleOptions) DeleteExampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteExampleOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) 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 GetExampleOptions

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

the class AssistantServiceIT method testDeleteExample.

/**
 * Test deleteExample.
 */
@Test
public void testDeleteExample() {
    createExampleIntent();
    // gotta be unique
    String exampleText = "Howdy " + UUID.randomUUID().toString();
    CreateExampleOptions createOptions = new CreateExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
    service.createExample(createOptions).execute();
    DeleteExampleOptions deleteOptions = new DeleteExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
    service.deleteExample(deleteOptions).execute();
    try {
        GetExampleOptions getOptions = new GetExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
        service.getExample(getOptions).execute();
        fail("deleteCounterexample failed");
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
    }
}
Also used : CreateExampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateExampleOptions) GetExampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetExampleOptions) DeleteExampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteExampleOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 3 with GetExampleOptions

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

the class AssistantTest method testGetExampleWOptions.

// Test the getExample operation with a valid options model parameter
@Test
public void testGetExampleWOptions() 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 getExamplePath = "/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 GetExampleOptions model
    GetExampleOptions getExampleOptionsModel = new GetExampleOptions.Builder().workspaceId("testString").intent("testString").text("testString").includeAudit(false).build();
    // Invoke getExample() with a valid options model and verify the result
    Response<Example> response = assistantService.getExample(getExampleOptionsModel).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(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getExamplePath);
    // 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) GetExampleOptions(com.ibm.watson.assistant.v1.model.GetExampleOptions) Example(com.ibm.watson.assistant.v1.model.Example) Test(org.testng.annotations.Test)

Example 4 with GetExampleOptions

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

the class Assistant method getExample.

/**
 * Get user input example.
 *
 * <p>Get information about a user input example.
 *
 * @param getExampleOptions the {@link GetExampleOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Example}
 */
public ServiceCall<Example> getExample(GetExampleOptions getExampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getExampleOptions, "getExampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", getExampleOptions.workspaceId());
    pathParamsMap.put("intent", getExampleOptions.intent());
    pathParamsMap.put("text", getExampleOptions.text());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/intents/{intent}/examples/{text}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "getExample");
    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 (getExampleOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getExampleOptions.includeAudit()));
    }
    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)

Example 5 with GetExampleOptions

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

the class AssistantServiceIT method testGetExample.

/**
 * Test getExample.
 */
@Test
public void testGetExample() {
    createExampleIntent();
    Date start = new Date();
    // gotta be unique
    String exampleText = "Howdy " + UUID.randomUUID().toString();
    CreateExampleOptions createOptions = new CreateExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
    service.createExample(createOptions).execute();
    try {
        GetExampleOptions getOptions = new GetExampleOptions.Builder(workspaceId, exampleIntent, exampleText).includeAudit(true).build();
        Example response = service.getExample(getOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getExampleText());
        assertEquals(response.getExampleText(), exampleText);
        assertNotNull(response.getCreated());
        assertNotNull(response.getUpdated());
        Date now = new Date();
        assertTrue(fuzzyBefore(response.getCreated(), now));
        assertTrue(fuzzyAfter(response.getCreated(), start));
        assertTrue(fuzzyBefore(response.getUpdated(), now));
        assertTrue(fuzzyAfter(response.getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteExampleOptions deleteOptions = new DeleteExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
        service.deleteExample(deleteOptions).execute();
    }
}
Also used : CreateExampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateExampleOptions) GetExampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetExampleOptions) 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) Date(java.util.Date) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)4 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)4 Test (org.junit.Test)4 Example (com.ibm.watson.assistant.v1.model.Example)2 CreateExampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateExampleOptions)2 DeleteExampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteExampleOptions)2 GetExampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.GetExampleOptions)2 CreateExampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateExampleOptions)2 DeleteExampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteExampleOptions)2 GetExampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.GetExampleOptions)2 Date (java.util.Date)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 GetExampleOptions (com.ibm.watson.assistant.v1.model.GetExampleOptions)1 CreateExample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateExample)1 Example (com.ibm.watson.developer_cloud.assistant.v1.model.Example)1 CreateExample (com.ibm.watson.developer_cloud.conversation.v1.model.CreateExample)1 Example (com.ibm.watson.developer_cloud.conversation.v1.model.Example)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1