Search in sources :

Example 1 with ListFieldsOptions

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);
}
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 ListFieldsOptions

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")), ","));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListCollectionFieldsResponse(com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse) ListFieldsOptions(com.ibm.watson.discovery.v1.model.ListFieldsOptions) Test(org.testng.annotations.Test)

Example 3 with ListFieldsOptions

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);
}
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 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Test (org.testng.annotations.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 ListCollectionFieldsResponse (com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse)1 ListFieldsOptions (com.ibm.watson.discovery.v1.model.ListFieldsOptions)1 ListFieldsOptions (com.ibm.watson.discovery.v2.model.ListFieldsOptions)1 HashMap (java.util.HashMap)1