use of com.ibm.watson.discovery.v2.model.ListFieldsOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testListFieldsWOptions.
@Test
public void testListFieldsWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"fields\": [{\"field\": \"field\", \"type\": \"nested\", \"collection_id\": \"collectionId\"}]}";
String listFieldsPath = "/v2/projects/testString/fields";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the ListFieldsOptions model
ListFieldsOptions listFieldsOptionsModel = new ListFieldsOptions.Builder().projectId("testString").collectionIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
// Invoke operation with valid options model (positive test)
Response<ListFieldsResponse> response = discoveryService.listFields(listFieldsOptionsModel).execute();
assertNotNull(response);
ListFieldsResponse 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("collection_ids"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, listFieldsPath);
}
use of com.ibm.watson.discovery.v2.model.ListFieldsOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testListFieldsWOptions.
// Test the listFields operation with a valid options model parameter
@Test
public void testListFieldsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"fields\": [{\"field\": \"field\", \"type\": \"nested\"}]}";
String listFieldsPath = "/v1/environments/testString/fields";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ListFieldsOptions model
ListFieldsOptions listFieldsOptionsModel = new ListFieldsOptions.Builder().environmentId("testString").collectionIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
// Invoke listFields() with a valid options model and verify the result
Response<ListCollectionFieldsResponse> response = discoveryService.listFields(listFieldsOptionsModel).execute();
assertNotNull(response);
ListCollectionFieldsResponse 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, listFieldsPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(query.get("collection_ids"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
}
use of com.ibm.watson.discovery.v2.model.ListFieldsOptions in project java-sdk by watson-developer-cloud.
the class Discovery method listFields.
/**
* List fields.
*
* <p>Gets a list of the unique fields (and their types) stored in the the specified collections.
*
* @param listFieldsOptions the {@link ListFieldsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ListFieldsResponse}
*/
public ServiceCall<ListFieldsResponse> listFields(ListFieldsOptions listFieldsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(listFieldsOptions, "listFieldsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", listFieldsOptions.projectId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/fields", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "listFields");
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 (listFieldsOptions.collectionIds() != null) {
builder.query("collection_ids", RequestUtils.join(listFieldsOptions.collectionIds(), ","));
}
ResponseConverter<ListFieldsResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ListFieldsResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations