Search in sources :

Example 66 with Collection

use of com.ibm.watson.discovery.v1.model.Collection 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)

Example 67 with Collection

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

the class VisualRecognitionIT method createTestCollection.

private String createTestCollection() {
    String testCollectionName = "java-sdk-test-collection";
    String testCollectionDescription = "Collection for integration testing of the Visual Recognition v4 service in " + "the Java SDK";
    CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions.Builder().name(testCollectionName).description(testCollectionDescription).build();
    Collection newCollection = service.createCollection(createCollectionOptions).execute().getResult();
    String testCollectionId = newCollection.getCollectionId();
    return testCollectionId;
}
Also used : CreateCollectionOptions(com.ibm.watson.visual_recognition.v4.model.CreateCollectionOptions) Collection(com.ibm.watson.visual_recognition.v4.model.Collection)

Aggregations

Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)26 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)23 HashMap (java.util.HashMap)22 Test (org.junit.Test)22 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)18 JsonObject (com.google.gson.JsonObject)15 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)14 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)11 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)10 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)9 Collection (com.ibm.watson.discovery.v1.model.Collection)9 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 MockResponse (okhttp3.mockwebserver.MockResponse)8 Test (org.testng.annotations.Test)7 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)5 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)5