use of com.ibm.watson.discovery.v2.model.ListCollectionsResponse in project java-sdk by watson-developer-cloud.
the class Discovery method listCollections.
/**
* List collections.
*
* Lists existing collections for the service instance.
*
* @param listCollectionsOptions the {@link ListCollectionsOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link ListCollectionsResponse}
*/
public ServiceCall<ListCollectionsResponse> listCollections(ListCollectionsOptions listCollectionsOptions) {
Validator.notNull(listCollectionsOptions, "listCollectionsOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections" };
String[] pathParameters = { listCollectionsOptions.environmentId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (listCollectionsOptions.name() != null) {
builder.query("name", listCollectionsOptions.name());
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ListCollectionsResponse.class));
}
use of com.ibm.watson.discovery.v2.model.ListCollectionsResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testListCollectionsWOptions.
@Test
public void testListCollectionsWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"collections\": [{\"collection_id\": \"collectionId\", \"name\": \"name\"}]}";
String listCollectionsPath = "/v2/projects/testString/collections";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the ListCollectionsOptions model
ListCollectionsOptions listCollectionsOptionsModel = new ListCollectionsOptions.Builder().projectId("testString").build();
// Invoke operation with valid options model (positive test)
Response<ListCollectionsResponse> response = discoveryService.listCollections(listCollectionsOptionsModel).execute();
assertNotNull(response);
ListCollectionsResponse 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, listCollectionsPath);
}
use of com.ibm.watson.discovery.v2.model.ListCollectionsResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method getCollectionsIsSuccessful.
/**
* Gets the collections is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void getCollectionsIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(getCollsResp));
ListCollectionsOptions getRequest = new ListCollectionsOptions.Builder(environmentId).build();
ListCollectionsResponse response = discoveryService.listCollections(getRequest).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(COLL1_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(getCollsResp, response);
}
use of com.ibm.watson.discovery.v2.model.ListCollectionsResponse in project java-sdk by watson-developer-cloud.
the class Discovery method listCollections.
/**
* List collections.
*
* <p>Lists existing collections for the service instance.
*
* @param listCollectionsOptions the {@link ListCollectionsOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link ListCollectionsResponse}
*/
public ServiceCall<ListCollectionsResponse> listCollections(ListCollectionsOptions listCollectionsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(listCollectionsOptions, "listCollectionsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", listCollectionsOptions.environmentId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listCollections");
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));
if (listCollectionsOptions.name() != null) {
builder.query("name", String.valueOf(listCollectionsOptions.name()));
}
ResponseConverter<ListCollectionsResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ListCollectionsResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations