Search in sources :

Example 6 with ListCollectionFieldsResponse

use of com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method listFieldsIsSuccessful.

@Test
public void listFieldsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listFieldsResp));
    ListFieldsOptions.Builder builder = new ListFieldsOptions.Builder(environmentId, new ArrayList<>(Arrays.asList(collectionId)));
    ListCollectionFieldsResponse response = discoveryService.listFields(builder.build()).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(FIELD_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listFieldsResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ListCollectionFieldsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsResponse) ListFieldsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListFieldsOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 7 with ListCollectionFieldsResponse

use of com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse in project java-sdk by watson-developer-cloud.

the class Discovery method listFields.

/**
 * List fields in specified collections.
 *
 * Gets a list of the unique fields (and their types) stored in the indexes of the specified collections.
 *
 * @param listFieldsOptions the {@link ListFieldsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link ListCollectionFieldsResponse}
 */
public ServiceCall<ListCollectionFieldsResponse> listFields(ListFieldsOptions listFieldsOptions) {
    Validator.notNull(listFieldsOptions, "listFieldsOptions cannot be null");
    String[] pathSegments = { "v1/environments", "fields" };
    String[] pathParameters = { listFieldsOptions.environmentId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    builder.query("collection_ids", RequestUtils.join(listFieldsOptions.collectionIds(), ","));
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ListCollectionFieldsResponse.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) ListCollectionFieldsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsResponse)

Example 8 with ListCollectionFieldsResponse

use of com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method listFieldsIsSuccessful.

/**
 * List fields is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void listFieldsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listFieldsResp));
    ListFieldsOptions.Builder builder = new ListFieldsOptions.Builder(environmentId, new ArrayList<>(Arrays.asList(collectionId)));
    ListCollectionFieldsResponse response = discoveryService.listFields(builder.build()).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(FIELD_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listFieldsResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ListCollectionFieldsResponse(com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse) ListFieldsOptions(com.ibm.watson.discovery.v1.model.ListFieldsOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 9 with ListCollectionFieldsResponse

use of com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse 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 10 with ListCollectionFieldsResponse

use of com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse in project java-sdk by watson-developer-cloud.

the class Discovery method listCollectionFields.

/**
 * List collection fields.
 *
 * <p>Gets a list of the unique fields (and their types) stored in the index.
 *
 * @param listCollectionFieldsOptions the {@link ListCollectionFieldsOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link ListCollectionFieldsResponse}
 */
public ServiceCall<ListCollectionFieldsResponse> listCollectionFields(ListCollectionFieldsOptions listCollectionFieldsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listCollectionFieldsOptions, "listCollectionFieldsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", listCollectionFieldsOptions.environmentId());
    pathParamsMap.put("collection_id", listCollectionFieldsOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/fields", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listCollectionFields");
    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));
    ResponseConverter<ListCollectionFieldsResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ListCollectionFieldsResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ListCollectionFieldsResponse(com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse)

Aggregations

ListCollectionFieldsResponse (com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 ListCollectionFieldsResponse (com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsResponse)5 Test (org.junit.Test)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)2 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 ListCollectionFieldsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsOptions)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 ListCollectionFieldsOptions (com.ibm.watson.discovery.v1.model.ListCollectionFieldsOptions)2 ListFieldsOptions (com.ibm.watson.discovery.v1.model.ListFieldsOptions)2 HashMap (java.util.HashMap)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 Test (org.testng.annotations.Test)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)1 ListFieldsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListFieldsOptions)1 Ignore (org.junit.Ignore)1