Search in sources :

Example 1 with CollectionsList

use of com.ibm.watson.visual_recognition.v4.model.CollectionsList 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)

Example 2 with CollectionsList

use of com.ibm.watson.visual_recognition.v4.model.CollectionsList in project java-sdk by watson-developer-cloud.

the class VisualRecognition method listCollections.

/**
 * List collections.
 *
 * <p>Retrieves a list of collections for the service instance.
 *
 * @param listCollectionsOptions the {@link ListCollectionsOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link CollectionsList}
 */
public ServiceCall<CollectionsList> listCollections(ListCollectionsOptions listCollectionsOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "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<CollectionsList> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CollectionsList>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : CollectionsList(com.ibm.watson.visual_recognition.v4.model.CollectionsList) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Example 3 with CollectionsList

use of com.ibm.watson.visual_recognition.v4.model.CollectionsList in project java-sdk by watson-developer-cloud.

the class VisualRecognitionIT method testCollectionOperations.

/**
 * Test collection operations.
 */
@Test
public void testCollectionOperations() {
    String testCollectionId = null;
    try {
        // test create
        String newCollectionName = "java-sdk-test-collection";
        String newCollectionDescription = "Collection for integration testing of the Visual Recognition v4 service in" + " the Java SDK";
        CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions.Builder().name(newCollectionName).description(newCollectionDescription).build();
        Collection newCollection = service.createCollection(createCollectionOptions).execute().getResult();
        assertNotNull(newCollection);
        assertEquals(newCollectionName, newCollection.getName());
        assertEquals(newCollectionDescription, newCollection.getDescription());
        // test get
        testCollectionId = newCollection.getCollectionId();
        GetCollectionOptions getCollectionOptions = new GetCollectionOptions.Builder().collectionId(testCollectionId).build();
        Collection retrievedCollection = service.getCollection(getCollectionOptions).execute().getResult();
        assertNotNull(retrievedCollection);
        assertEquals(newCollection.getCollectionId(), retrievedCollection.getCollectionId());
        // test update
        String updatedDescription = "Collection with an updated description, still for testing in the Java SDK.";
        UpdateCollectionOptions updateCollectionOptions = new UpdateCollectionOptions.Builder().collectionId(testCollectionId).description(updatedDescription).build();
        Collection updatedCollection = service.updateCollection(updateCollectionOptions).execute().getResult();
        assertNotNull(updatedCollection);
        assertEquals(updatedDescription, updatedCollection.getDescription());
    } finally {
        if (testCollectionId != null) {
            // test delete
            DeleteCollectionOptions deleteCollectionOptions = new DeleteCollectionOptions.Builder().collectionId(testCollectionId).build();
            service.deleteCollection(deleteCollectionOptions).execute();
            // test list
            CollectionsList collectionsList = service.listCollections().execute().getResult();
            assertNotNull(collectionsList);
            for (Collection collection : collectionsList.getCollections()) {
                assertFalse(collection.getCollectionId().equals(testCollectionId));
            }
        }
    }
}
Also used : UpdateCollectionOptions(com.ibm.watson.visual_recognition.v4.model.UpdateCollectionOptions) CollectionsList(com.ibm.watson.visual_recognition.v4.model.CollectionsList) GetCollectionOptions(com.ibm.watson.visual_recognition.v4.model.GetCollectionOptions) CreateCollectionOptions(com.ibm.watson.visual_recognition.v4.model.CreateCollectionOptions) Collection(com.ibm.watson.visual_recognition.v4.model.Collection) DeleteCollectionOptions(com.ibm.watson.visual_recognition.v4.model.DeleteCollectionOptions) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Aggregations

CollectionsList (com.ibm.watson.visual_recognition.v4.model.CollectionsList)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)1 CreateCollectionOptions (com.ibm.watson.visual_recognition.v4.model.CreateCollectionOptions)1 DeleteCollectionOptions (com.ibm.watson.visual_recognition.v4.model.DeleteCollectionOptions)1 GetCollectionOptions (com.ibm.watson.visual_recognition.v4.model.GetCollectionOptions)1 ListCollectionsOptions (com.ibm.watson.visual_recognition.v4.model.ListCollectionsOptions)1 UpdateCollectionOptions (com.ibm.watson.visual_recognition.v4.model.UpdateCollectionOptions)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.junit.Test)1 Test (org.testng.annotations.Test)1