Search in sources :

Example 1 with ListCollectionFieldsOptions

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

the class DiscoveryServiceTest method listfieldsCollectionIsSuccessful.

// no updateCollection yet?
@Test
public void listfieldsCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listfieldsCollResp));
    ListCollectionFieldsOptions getRequest = new ListCollectionFieldsOptions.Builder(environmentId, collectionId).build();
    ListCollectionFieldsResponse response = discoveryService.listCollectionFields(getRequest).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL3_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listfieldsCollResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ListCollectionFieldsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsOptions) ListCollectionFieldsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsResponse) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with ListCollectionFieldsOptions

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

the class DiscoveryServiceTest method listfieldsCollectionIsSuccessful.

// no updateCollection yet?
/**
 * Listfields collection is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void listfieldsCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listfieldsCollResp));
    ListCollectionFieldsOptions getRequest = new ListCollectionFieldsOptions.Builder(environmentId, collectionId).build();
    ListCollectionFieldsResponse response = discoveryService.listCollectionFields(getRequest).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL3_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listfieldsCollResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ListCollectionFieldsOptions(com.ibm.watson.discovery.v1.model.ListCollectionFieldsOptions) ListCollectionFieldsResponse(com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 3 with ListCollectionFieldsOptions

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

the class DiscoveryTest method testListCollectionFieldsWOptions.

// Test the listCollectionFields operation with a valid options model parameter
@Test
public void testListCollectionFieldsWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"fields\": [{\"field\": \"field\", \"type\": \"nested\"}]}";
    String listCollectionFieldsPath = "/v1/environments/testString/collections/testString/fields";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListCollectionFieldsOptions model
    ListCollectionFieldsOptions listCollectionFieldsOptionsModel = new ListCollectionFieldsOptions.Builder().environmentId("testString").collectionId("testString").build();
    // Invoke listCollectionFields() with a valid options model and verify the result
    Response<ListCollectionFieldsResponse> response = discoveryService.listCollectionFields(listCollectionFieldsOptionsModel).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, listCollectionFieldsPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListCollectionFieldsOptions(com.ibm.watson.discovery.v1.model.ListCollectionFieldsOptions) ListCollectionFieldsResponse(com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse) Test(org.testng.annotations.Test)

Example 4 with ListCollectionFieldsOptions

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

the class DiscoveryServiceIT method getCollectionFieldsIsSuccessful.

@Ignore
@Test
public void getCollectionFieldsIsSuccessful() {
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    createTestDocument("test_document", collectionId);
    ListCollectionFieldsOptions getOptions = new ListCollectionFieldsOptions.Builder(environmentId, collectionId).build();
    ListCollectionFieldsResponse getResponse = discovery.listCollectionFields(getOptions).execute();
    assertFalse(getResponse.getFields().isEmpty());
}
Also used : ListCollectionFieldsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) ListCollectionFieldsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsResponse) Ignore(org.junit.Ignore) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 5 with ListCollectionFieldsOptions

use of com.ibm.watson.discovery.v1.model.ListCollectionFieldsOptions 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)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 ListCollectionFieldsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsOptions)2 ListCollectionFieldsResponse (com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsResponse)2 ListCollectionFieldsOptions (com.ibm.watson.discovery.v1.model.ListCollectionFieldsOptions)2 Test (org.junit.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Ignore (org.junit.Ignore)1 Test (org.testng.annotations.Test)1