Search in sources :

Example 1 with ListFieldsResponse

use of com.ibm.watson.discovery.v2.model.ListFieldsResponse 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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListFieldsResponse(com.ibm.watson.discovery.v2.model.ListFieldsResponse) ListFieldsOptions(com.ibm.watson.discovery.v2.model.ListFieldsOptions) Test(org.testng.annotations.Test)

Example 2 with ListFieldsResponse

use of com.ibm.watson.discovery.v2.model.ListFieldsResponse 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ListFieldsResponse(com.ibm.watson.discovery.v2.model.ListFieldsResponse)

Aggregations

ListFieldsResponse (com.ibm.watson.discovery.v2.model.ListFieldsResponse)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 ListFieldsOptions (com.ibm.watson.discovery.v2.model.ListFieldsOptions)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1