Search in sources :

Example 1 with ListCollectionsResponse

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

the class DiscoveryServiceTest method getCollectionsIsSuccessful.

@Test
public void getCollectionsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(getCollsResp));
    ListCollectionsOptions getRequest = new ListCollectionsOptions.Builder(environmentId).build();
    ListCollectionsResponse response = discoveryService.listCollections(getRequest).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL1_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(getCollsResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ListCollectionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsOptions) ListCollectionsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsResponse) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with ListCollectionsResponse

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

the class DiscoveryTest method testListCollectionsWOptions.

// Test the listCollections operation with a valid options model parameter
@Test
public void testListCollectionsWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"collections\": [{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"status\": \"active\", \"configuration_id\": \"configurationId\", \"language\": \"language\", \"document_counts\": {\"available\": 9, \"processing\": 10, \"failed\": 6, \"pending\": 7}, \"disk_usage\": {\"used_bytes\": 9}, \"training_status\": {\"total_examples\": 13, \"available\": false, \"processing\": true, \"minimum_queries_added\": false, \"minimum_examples_added\": true, \"sufficient_label_diversity\": true, \"notices\": 7, \"successfully_trained\": \"2019-01-01T12:00:00.000Z\", \"data_updated\": \"2019-01-01T12:00:00.000Z\"}, \"crawl_status\": {\"source_crawl\": {\"status\": \"running\", \"next_crawl\": \"2019-01-01T12:00:00.000Z\"}}, \"smart_document_understanding\": {\"enabled\": true, \"total_annotated_pages\": 19, \"total_pages\": 10, \"total_documents\": 14, \"custom_fields\": {\"defined\": 7, \"maximum_allowed\": 14}}}]}";
    String listCollectionsPath = "/v1/environments/testString/collections";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListCollectionsOptions model
    ListCollectionsOptions listCollectionsOptionsModel = new ListCollectionsOptions.Builder().environmentId("testString").name("testString").build();
    // Invoke listCollections() with a valid options model and verify the result
    Response<ListCollectionsResponse> response = discoveryService.listCollections(listCollectionsOptionsModel).execute();
    assertNotNull(response);
    ListCollectionsResponse 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, listCollectionsPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(query.get("name"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListCollectionsOptions(com.ibm.watson.discovery.v1.model.ListCollectionsOptions) ListCollectionsResponse(com.ibm.watson.discovery.v1.model.ListCollectionsResponse) Test(org.testng.annotations.Test)

Example 3 with ListCollectionsResponse

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

the class Discovery method listCollections.

/**
 * List collections.
 *
 * <p>Lists existing collections for the specified project.
 *
 * @param listCollectionsOptions the {@link ListCollectionsOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link ListCollectionsResponse}
 */
public ServiceCall<ListCollectionsResponse> listCollections(ListCollectionsOptions listCollectionsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listCollectionsOptions, "listCollectionsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", listCollectionsOptions.projectId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "listCollections");
    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<ListCollectionsResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ListCollectionsResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ListCollectionsResponse(com.ibm.watson.discovery.v2.model.ListCollectionsResponse)

Example 4 with ListCollectionsResponse

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

the class DiscoveryServiceIT method listCollectionsIsSuccessful.

// Collections
@Test
public void listCollectionsIsSuccessful() {
    createTestCollection();
    ListCollectionsOptions listOptions = new ListCollectionsOptions.Builder(environmentId).build();
    ListCollectionsResponse listResponse = discovery.listCollections(listOptions).execute();
    assertFalse(listResponse.getCollections().isEmpty());
}
Also used : ListCollectionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsOptions) ListCollectionsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsResponse) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 5 with ListCollectionsResponse

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

the class DiscoveryServiceIT method getCollectionsByNameIsSuccessful.

@Test
public void getCollectionsByNameIsSuccessful() {
    Configuration createConfigResponse = createTestConfig();
    String uniqueCollectionName = uniqueName + "-collection";
    CreateCollectionOptions.Builder createCollectionBuilder = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(createConfigResponse.getConfigurationId());
    createCollection(createCollectionBuilder.build());
    ListCollectionsOptions.Builder getBuilder = new ListCollectionsOptions.Builder(environmentId);
    getBuilder.name(uniqueCollectionName);
    ListCollectionsResponse getResponse = discovery.listCollections(getBuilder.build()).execute();
    assertEquals(1, getResponse.getCollections().size());
    assertEquals(uniqueCollectionName, getResponse.getCollections().get(0).getName());
}
Also used : ListCollectionsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsOptions) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) CreateCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions) ListCollectionsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsResponse) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

ListCollectionsResponse (com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsResponse)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 ListCollectionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsOptions)3 ListCollectionsResponse (com.ibm.watson.discovery.v1.model.ListCollectionsResponse)3 Test (org.junit.Test)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 ListCollectionsOptions (com.ibm.watson.discovery.v1.model.ListCollectionsOptions)2 ListCollectionsResponse (com.ibm.watson.discovery.v2.model.ListCollectionsResponse)2 HashMap (java.util.HashMap)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 Test (org.testng.annotations.Test)2 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)1 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 ListCollectionsOptions (com.ibm.watson.discovery.v2.model.ListCollectionsOptions)1