Search in sources :

Example 6 with ListCollectionsOptions

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

the class DiscoveryServiceTest method getCollectionsIsSuccessful.

/**
 * Gets the collections is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getCollectionsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(getCollsResp));
    ListCollectionsOptions getRequest = new ListCollectionsOptions.Builder(environmentId).build();
    ListCollectionsResponse response = discoveryService.listCollections(getRequest).execute().getResult();
    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.discovery.v1.model.ListCollectionsOptions) ListCollectionsResponse(com.ibm.watson.discovery.v1.model.ListCollectionsResponse) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 7 with ListCollectionsOptions

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

the class VisualRecognitionTest method testListCollectionsWOptions.

@Test
public void testListCollectionsWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"collections\": [{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"image_count\": 10, \"training_status\": {\"objects\": {\"ready\": false, \"in_progress\": true, \"data_changed\": false, \"latest_failed\": true, \"rscnn_ready\": true, \"description\": \"description\"}}}]}";
    String listCollectionsPath = "/v4/collections";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ListCollectionsOptions model
    ListCollectionsOptions listCollectionsOptionsModel = new ListCollectionsOptions();
    // Invoke operation with valid options model (positive test)
    Response<CollectionsList> response = visualRecognitionService.listCollections(listCollectionsOptionsModel).execute();
    assertNotNull(response);
    CollectionsList 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");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, listCollectionsPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListCollectionsOptions(com.ibm.watson.visual_recognition.v4.model.ListCollectionsOptions) CollectionsList(com.ibm.watson.visual_recognition.v4.model.CollectionsList) Test(org.testng.annotations.Test)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 MockResponse (okhttp3.mockwebserver.MockResponse)3 Test (org.testng.annotations.Test)3 ListCollectionsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsOptions)2 ListCollectionsResponse (com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionsResponse)2 ListCollectionsOptions (com.ibm.watson.discovery.v1.model.ListCollectionsOptions)2 ListCollectionsResponse (com.ibm.watson.discovery.v1.model.ListCollectionsResponse)2 ListCollectionsResponse (com.ibm.watson.discovery.v2.model.ListCollectionsResponse)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 ListCollectionsOptions (com.ibm.watson.discovery.v2.model.ListCollectionsOptions)1 CollectionsList (com.ibm.watson.visual_recognition.v4.model.CollectionsList)1 ListCollectionsOptions (com.ibm.watson.visual_recognition.v4.model.ListCollectionsOptions)1 HashMap (java.util.HashMap)1