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);
}
}
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);
}
}
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));
}
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);
}
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();
}
}
Aggregations