Search in sources :

Example 1 with UpdateCollectionOptions

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

the class VisualRecognitionTest method testUpdateCollectionWOptions.

@Test
public void testUpdateCollectionWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"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 updateCollectionPath = "/v4/collections/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the UpdateCollectionOptions model
    UpdateCollectionOptions updateCollectionOptionsModel = new UpdateCollectionOptions.Builder().collectionId("testString").name("testString").description("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Collection> response = visualRecognitionService.updateCollection(updateCollectionOptionsModel).execute();
    assertNotNull(response);
    Collection responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // 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, updateCollectionPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateCollectionOptions(com.ibm.watson.visual_recognition.v4.model.UpdateCollectionOptions) Collection(com.ibm.watson.visual_recognition.v4.model.Collection) Test(org.testng.annotations.Test)

Example 2 with UpdateCollectionOptions

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

the class DiscoveryTest method testUpdateCollectionWOptions.

@Test
public void testUpdateCollectionWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"language\": \"en\", \"enrichments\": [{\"enrichment_id\": \"enrichmentId\", \"fields\": [\"fields\"]}]}";
    String updateCollectionPath = "/v2/projects/testString/collections/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the CollectionEnrichment model
    CollectionEnrichment collectionEnrichmentModel = new CollectionEnrichment.Builder().enrichmentId("testString").fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the UpdateCollectionOptions model
    UpdateCollectionOptions updateCollectionOptionsModel = new UpdateCollectionOptions.Builder().projectId("testString").collectionId("testString").name("testString").description("testString").enrichments(new java.util.ArrayList<CollectionEnrichment>(java.util.Arrays.asList(collectionEnrichmentModel))).build();
    // Invoke operation with valid options model (positive test)
    Response<CollectionDetails> response = discoveryService.updateCollection(updateCollectionOptionsModel).execute();
    assertNotNull(response);
    CollectionDetails responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // 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, updateCollectionPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CollectionEnrichment(com.ibm.watson.discovery.v2.model.CollectionEnrichment) UpdateCollectionOptions(com.ibm.watson.discovery.v2.model.UpdateCollectionOptions) CollectionDetails(com.ibm.watson.discovery.v2.model.CollectionDetails) Test(org.testng.annotations.Test)

Example 3 with UpdateCollectionOptions

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

the class DiscoveryTest method testUpdateCollectionWOptions.

// Test the updateCollection operation with a valid options model parameter
@Test
public void testUpdateCollectionWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"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 updateCollectionPath = "/v1/environments/testString/collections/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the UpdateCollectionOptions model
    UpdateCollectionOptions updateCollectionOptionsModel = new UpdateCollectionOptions.Builder().environmentId("testString").collectionId("testString").name("testString").description("testString").configurationId("testString").build();
    // Invoke updateCollection() with a valid options model and verify the result
    Response<Collection> response = discoveryService.updateCollection(updateCollectionOptionsModel).execute();
    assertNotNull(response);
    Collection 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(), "PUT");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateCollectionPath);
    // 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) UpdateCollectionOptions(com.ibm.watson.discovery.v1.model.UpdateCollectionOptions) Collection(com.ibm.watson.discovery.v1.model.Collection) Test(org.testng.annotations.Test)

Example 4 with UpdateCollectionOptions

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

the class Discovery method updateCollection.

/**
 * Update a collection.
 *
 * @param updateCollectionOptions the {@link UpdateCollectionOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Collection}
 */
public ServiceCall<Collection> updateCollection(UpdateCollectionOptions updateCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateCollectionOptions, "updateCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", updateCollectionOptions.environmentId());
    pathParamsMap.put("collection_id", updateCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "updateCollection");
    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));
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", updateCollectionOptions.name());
    if (updateCollectionOptions.description() != null) {
        contentJson.addProperty("description", updateCollectionOptions.description());
    }
    if (updateCollectionOptions.configurationId() != null) {
        contentJson.addProperty("configuration_id", updateCollectionOptions.configurationId());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Collection(com.ibm.watson.discovery.v1.model.Collection)

Example 5 with UpdateCollectionOptions

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

MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Test (org.testng.annotations.Test)3 Collection (com.ibm.watson.discovery.v1.model.Collection)2 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)2 UpdateCollectionOptions (com.ibm.watson.visual_recognition.v4.model.UpdateCollectionOptions)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 UpdateCollectionOptions (com.ibm.watson.discovery.v1.model.UpdateCollectionOptions)1 CollectionDetails (com.ibm.watson.discovery.v2.model.CollectionDetails)1 CollectionEnrichment (com.ibm.watson.discovery.v2.model.CollectionEnrichment)1 UpdateCollectionOptions (com.ibm.watson.discovery.v2.model.UpdateCollectionOptions)1 CollectionsList (com.ibm.watson.visual_recognition.v4.model.CollectionsList)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 HashMap (java.util.HashMap)1 Test (org.junit.Test)1