use of com.ibm.watson.visual_recognition.v4.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);
}
use of com.ibm.watson.visual_recognition.v4.model.GetCollectionOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognition method getCollection.
/**
* Get collection details.
*
* <p>Get details of one collection.
*
* @param getCollectionOptions the {@link GetCollectionOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link Collection}
*/
public ServiceCall<Collection> 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("collection_id", getCollectionOptions.collectionId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "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<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.visual_recognition.v4.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);
}
use of com.ibm.watson.visual_recognition.v4.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);
}
use of com.ibm.watson.visual_recognition.v4.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());
}
Aggregations