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