Search in sources :

Example 6 with DeleteCollectionOptions

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

the class DiscoveryServiceTest method deleteCollectionIsSuccessful.

/**
 * Delete collection is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void deleteCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(deleteCollResp));
    DeleteCollectionOptions deleteRequest = new DeleteCollectionOptions.Builder(environmentId, collectionId).build();
    DeleteCollectionResponse response = discoveryService.deleteCollection(deleteRequest).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL2_PATH, request.getPath());
    assertEquals(DELETE, request.getMethod());
    assertEquals(DeleteCollectionResponse.Status.DELETED, response.getStatus());
    assertEquals(deleteCollResp.getCollectionId(), response.getCollectionId());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeleteCollectionResponse(com.ibm.watson.discovery.v1.model.DeleteCollectionResponse) DeleteCollectionOptions(com.ibm.watson.discovery.v1.model.DeleteCollectionOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 7 with DeleteCollectionOptions

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

the class DiscoveryTest method testDeleteCollectionWOptions.

// Test the deleteCollection operation with a valid options model parameter
@Test
public void testDeleteCollectionWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"collection_id\": \"collectionId\", \"status\": \"deleted\"}";
    String deleteCollectionPath = "/v1/environments/testString/collections/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the DeleteCollectionOptions model
    DeleteCollectionOptions deleteCollectionOptionsModel = new DeleteCollectionOptions.Builder().environmentId("testString").collectionId("testString").build();
    // Invoke deleteCollection() with a valid options model and verify the result
    Response<DeleteCollectionResponse> response = discoveryService.deleteCollection(deleteCollectionOptionsModel).execute();
    assertNotNull(response);
    DeleteCollectionResponse 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(), "DELETE");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteCollectionPath);
    // 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) DeleteCollectionResponse(com.ibm.watson.discovery.v1.model.DeleteCollectionResponse) DeleteCollectionOptions(com.ibm.watson.discovery.v1.model.DeleteCollectionOptions) Test(org.testng.annotations.Test)

Example 8 with DeleteCollectionOptions

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

the class VisualRecognitionTest method testDeleteCollectionWOptions.

@Test
public void testDeleteCollectionWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "";
    String deleteCollectionPath = "/v4/collections/testString";
    server.enqueue(new MockResponse().setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the DeleteCollectionOptions model
    DeleteCollectionOptions deleteCollectionOptionsModel = new DeleteCollectionOptions.Builder().collectionId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Void> response = visualRecognitionService.deleteCollection(deleteCollectionOptionsModel).execute();
    assertNotNull(response);
    Void responseObj = response.getResult();
    // Response does not have a return type. Check that the result is null.
    assertNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "DELETE");
    // 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, deleteCollectionPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteCollectionOptions(com.ibm.watson.visual_recognition.v4.model.DeleteCollectionOptions) Test(org.testng.annotations.Test)

Example 9 with DeleteCollectionOptions

use of com.ibm.watson.discovery.v2.model.DeleteCollectionOptions 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 10 with DeleteCollectionOptions

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

the class VisualRecognitionIT method deleteTestCollection.

private void deleteTestCollection(String collectionId) {
    DeleteCollectionOptions deleteCollectionOptions = new DeleteCollectionOptions.Builder().collectionId(collectionId).build();
    service.deleteCollection(deleteCollectionOptions).execute();
}
Also used : DeleteCollectionOptions(com.ibm.watson.visual_recognition.v4.model.DeleteCollectionOptions)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 Test (org.junit.Test)4 DeleteCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteCollectionOptions)3 DeleteCollectionOptions (com.ibm.watson.discovery.v1.model.DeleteCollectionOptions)3 DeleteCollectionOptions (com.ibm.watson.visual_recognition.v4.model.DeleteCollectionOptions)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 Test (org.testng.annotations.Test)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)2 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)2 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)2 DeleteCollectionResponse (com.ibm.watson.discovery.v1.model.DeleteCollectionResponse)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)1 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)1 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)1