use of com.ibm.watson.discovery.v2.model.Completions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testGetAutocompletionWOptions.
// Test the getAutocompletion operation with a valid options model parameter
@Test
public void testGetAutocompletionWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"completions\": [\"completions\"]}";
String getAutocompletionPath = "/v1/environments/testString/collections/testString/autocompletion";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the GetAutocompletionOptions model
GetAutocompletionOptions getAutocompletionOptionsModel = new GetAutocompletionOptions.Builder().environmentId("testString").collectionId("testString").prefix("testString").field("testString").count(Long.valueOf("26")).build();
// Invoke getAutocompletion() with a valid options model and verify the result
Response<Completions> response = discoveryService.getAutocompletion(getAutocompletionOptionsModel).execute();
assertNotNull(response);
Completions 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, getAutocompletionPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(query.get("prefix"), "testString");
assertEquals(query.get("field"), "testString");
assertEquals(Long.valueOf(query.get("count")), Long.valueOf("26"));
}
use of com.ibm.watson.discovery.v2.model.Completions in project java-sdk by watson-developer-cloud.
the class Discovery method getAutocompletion.
/**
* Get Autocomplete Suggestions.
*
* <p>Returns completion query suggestions for the specified prefix. /n/n **Important:** this
* method is only valid when using the Cloud Pak version of Discovery.
*
* @param getAutocompletionOptions the {@link GetAutocompletionOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Completions}
*/
public ServiceCall<Completions> getAutocompletion(GetAutocompletionOptions getAutocompletionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getAutocompletionOptions, "getAutocompletionOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", getAutocompletionOptions.environmentId());
pathParamsMap.put("collection_id", getAutocompletionOptions.collectionId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/autocompletion", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getAutocompletion");
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));
builder.query("prefix", String.valueOf(getAutocompletionOptions.prefix()));
if (getAutocompletionOptions.field() != null) {
builder.query("field", String.valueOf(getAutocompletionOptions.field()));
}
if (getAutocompletionOptions.count() != null) {
builder.query("count", String.valueOf(getAutocompletionOptions.count()));
}
ResponseConverter<Completions> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Completions>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v2.model.Completions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testGetAutocompletionWOptions.
@Test
public void testGetAutocompletionWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"completions\": [\"completions\"]}";
String getAutocompletionPath = "/v2/projects/testString/autocompletion";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetAutocompletionOptions model
GetAutocompletionOptions getAutocompletionOptionsModel = new GetAutocompletionOptions.Builder().projectId("testString").prefix("testString").collectionIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).field("testString").count(Long.valueOf("26")).build();
// Invoke operation with valid options model (positive test)
Response<Completions> response = discoveryService.getAutocompletion(getAutocompletionOptionsModel).execute();
assertNotNull(response);
Completions responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
assertEquals(query.get("prefix"), "testString");
assertEquals(query.get("collection_ids"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
assertEquals(query.get("field"), "testString");
assertEquals(Long.valueOf(query.get("count")), Long.valueOf("26"));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getAutocompletionPath);
}
use of com.ibm.watson.discovery.v2.model.Completions in project java-sdk by watson-developer-cloud.
the class Discovery method getAutocompletion.
/**
* Get Autocomplete Suggestions.
*
* <p>Returns completion query suggestions for the specified prefix.
*
* @param getAutocompletionOptions the {@link GetAutocompletionOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Completions}
*/
public ServiceCall<Completions> getAutocompletion(GetAutocompletionOptions getAutocompletionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getAutocompletionOptions, "getAutocompletionOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", getAutocompletionOptions.projectId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/autocompletion", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "getAutocompletion");
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));
builder.query("prefix", String.valueOf(getAutocompletionOptions.prefix()));
if (getAutocompletionOptions.collectionIds() != null) {
builder.query("collection_ids", RequestUtils.join(getAutocompletionOptions.collectionIds(), ","));
}
if (getAutocompletionOptions.field() != null) {
builder.query("field", String.valueOf(getAutocompletionOptions.field()));
}
if (getAutocompletionOptions.count() != null) {
builder.query("count", String.valueOf(getAutocompletionOptions.count()));
}
ResponseConverter<Completions> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Completions>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations