use of com.ibm.watson.assistant.v1.model.CreateCounterexampleOptions 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();
}
}
use of com.ibm.watson.assistant.v1.model.CreateCounterexampleOptions in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT method testCreateCounterexample.
/**
* Test createCounterexample.
*/
@Test
public void testCreateCounterexample() {
// gotta be unique
String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
Counterexample response = service.createCounterexample(createOptions).execute();
try {
assertNotNull(response);
assertNotNull(response.getText());
assertEquals(response.getText(), counterExampleText);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
service.deleteCounterexample(deleteOptions).execute();
}
}
use of com.ibm.watson.assistant.v1.model.CreateCounterexampleOptions in project java-sdk by watson-developer-cloud.
the class AssistantTest method testCreateCounterexampleWOptions.
// Test the createCounterexample operation with a valid options model parameter
@Test
public void testCreateCounterexampleWOptions() 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 createCounterexamplePath = "/v1/workspaces/testString/counterexamples";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the CreateCounterexampleOptions model
CreateCounterexampleOptions createCounterexampleOptionsModel = new CreateCounterexampleOptions.Builder().workspaceId("testString").text("testString").includeAudit(false).build();
// Invoke createCounterexample() with a valid options model and verify the result
Response<Counterexample> response = assistantService.createCounterexample(createCounterexampleOptionsModel).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, createCounterexamplePath);
// 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.CreateCounterexampleOptions in project java-sdk by watson-developer-cloud.
the class Assistant method createCounterexample.
/**
* Create counterexample.
*
* <p>Add a new counterexample to a workspace. Counterexamples are examples that have been marked
* as irrelevant input.
*
* <p>If you want to add multiple counterexamples with a single API call, consider using the
* **[Update workspace](#update-workspace)** method instead.
*
* @param createCounterexampleOptions the {@link CreateCounterexampleOptions} containing the
* options for the call
* @return a {@link ServiceCall} with a result of type {@link Counterexample}
*/
public ServiceCall<Counterexample> createCounterexample(CreateCounterexampleOptions createCounterexampleOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createCounterexampleOptions, "createCounterexampleOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("workspace_id", createCounterexampleOptions.workspaceId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/counterexamples", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "createCounterexample");
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 (createCounterexampleOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(createCounterexampleOptions.includeAudit()));
}
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("text", createCounterexampleOptions.text());
builder.bodyJson(contentJson);
ResponseConverter<Counterexample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Counterexample>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.assistant.v1.model.CreateCounterexampleOptions 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();
}
}
Aggregations