Search in sources :

Example 1 with GetCollectionOptions

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

the class VisualRecognitionTest method testGetCollectionWOptions.

@Test
public void testGetCollectionWOptions() 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 getCollectionPath = "/v4/collections/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetCollectionOptions model
    GetCollectionOptions getCollectionOptionsModel = new GetCollectionOptions.Builder().collectionId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Collection> response = visualRecognitionService.getCollection(getCollectionOptionsModel).execute();
    assertNotNull(response);
    Collection 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, getCollectionPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetCollectionOptions(com.ibm.watson.visual_recognition.v4.model.GetCollectionOptions) Collection(com.ibm.watson.visual_recognition.v4.model.Collection) Test(org.testng.annotations.Test)

Example 2 with GetCollectionOptions

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

the class DiscoveryServiceTest method getCollectionIsSuccessful.

/**
 * Gets the collection is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(getCollResp));
    GetCollectionOptions getRequest = new GetCollectionOptions.Builder(environmentId, collectionId).build();
    Collection response = discoveryService.getCollection(getRequest).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL2_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(getCollResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetCollectionOptions(com.ibm.watson.discovery.v1.model.GetCollectionOptions) Collection(com.ibm.watson.discovery.v1.model.Collection) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 3 with GetCollectionOptions

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

the class Discovery method getCollection.

/**
 * Get collection.
 *
 * <p>Get details about the specified collection.
 *
 * @param getCollectionOptions the {@link GetCollectionOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link CollectionDetails}
 */
public ServiceCall<CollectionDetails> getCollection(GetCollectionOptions getCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getCollectionOptions, "getCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", getCollectionOptions.projectId());
    pathParamsMap.put("collection_id", getCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "getCollection");
    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<CollectionDetails> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CollectionDetails>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) CollectionDetails(com.ibm.watson.discovery.v2.model.CollectionDetails)

Example 4 with GetCollectionOptions

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

the class DiscoveryServiceTest method getCollectionIsSuccessful.

@Test
public void getCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(getCollResp));
    GetCollectionOptions getRequest = new GetCollectionOptions.Builder(environmentId, collectionId).build();
    Collection response = discoveryService.getCollection(getRequest).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL2_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(getCollResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetCollectionOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 5 with GetCollectionOptions

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

the class DiscoveryServiceIT method getCollectionIsSuccessful.

@Test
public void getCollectionIsSuccessful() {
    Configuration createConfigResponse = createTestConfig();
    String uniqueCollectionName = uniqueName + "-collection";
    CreateCollectionOptions.Builder createCollectionBuilder = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(createConfigResponse.getConfigurationId());
    Collection createResponse = createCollection(createCollectionBuilder.build());
    GetCollectionOptions getOptions = new GetCollectionOptions.Builder(environmentId, createResponse.getCollectionId()).build();
    // need to wait for collection to be ready
    Collection getResponse = discovery.getCollection(getOptions).execute();
    assertEquals(createResponse.getName(), getResponse.getName());
}
Also used : Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) GetCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetCollectionOptions) CreateCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 Test (org.junit.Test)4 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)3 GetCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetCollectionOptions)3 Collection (com.ibm.watson.discovery.v1.model.Collection)3 GetCollectionOptions (com.ibm.watson.discovery.v1.model.GetCollectionOptions)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 Test (org.testng.annotations.Test)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)2 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 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