use of com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostAllDocsQueriesWOptions.
@Test
public void testPostAllDocsQueriesWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"results\": [{\"total_rows\": 0, \"rows\": [{\"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\", \"doc\": {\"_attachments\": {\"mapKey\": {\"content_type\": \"contentType\", \"data\": \"VGhpcyBpcyBhbiBlbmNvZGVkIGJ5dGUgYXJyYXku\", \"digest\": \"digest\", \"encoded_length\": 0, \"encoding\": \"encoding\", \"follows\": false, \"length\": 0, \"revpos\": 1, \"stub\": true}}, \"_conflicts\": [\"conflicts\"], \"_deleted\": false, \"_deleted_conflicts\": [\"deletedConflicts\"], \"_id\": \"id\", \"_local_seq\": \"localSeq\", \"_rev\": \"rev\", \"_revisions\": {\"ids\": [\"ids\"], \"start\": 1}, \"_revs_info\": [{\"rev\": \"rev\", \"status\": \"available\"}]}, \"id\": \"id\", \"key\": \"key\", \"value\": {\"rev\": \"rev\"}}], \"update_seq\": \"updateSeq\"}]}";
String postAllDocsQueriesPath = "/testString/_all_docs/queries";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the AllDocsQuery model
AllDocsQuery allDocsQueryModel = new AllDocsQuery.Builder().attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("0")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("small-appliances:1000042", "small-appliances:1000043"))).startkey("testString").build();
// Construct an instance of the PostAllDocsQueriesOptions model
PostAllDocsQueriesOptions postAllDocsQueriesOptionsModel = new PostAllDocsQueriesOptions.Builder().db("testString").queries(new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel))).build();
// Invoke operation with valid options model (positive test)
Response<AllDocsQueriesResult> response = cloudantService.postAllDocsQueries(postAllDocsQueriesOptionsModel).execute();
assertNotNull(response);
AllDocsQueriesResult 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);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, postAllDocsQueriesPath);
}
use of com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions in project cloudant-java-sdk by IBM.
the class Cloudant method postAllDocsQueries.
/**
* Multi-query the list of all documents in a database.
*
* Runs multiple queries using the primary index (all document IDs). Returns a JSON object that contains a list of
* result objects, one for each query, with a structure equivalent to that of a single `_all_docs` request. This
* enables you to request multiple queries in a single request, in place of multiple `POST /{db}/_all_docs` requests.
*
* @param postAllDocsQueriesOptions the {@link PostAllDocsQueriesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link AllDocsQueriesResult}
*/
public ServiceCall<AllDocsQueriesResult> postAllDocsQueries(PostAllDocsQueriesOptions postAllDocsQueriesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postAllDocsQueriesOptions, "postAllDocsQueriesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postAllDocsQueriesOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_all_docs/queries", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postAllDocsQueries");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.add("queries", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postAllDocsQueriesOptions.queries()));
builder.bodyJson(contentJson);
ResponseConverter<AllDocsQueriesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsQueriesResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions in project cloudant-java-sdk by IBM.
the class PostAllDocsQueriesOptionsTest method testPostAllDocsQueriesOptions.
@Test
public void testPostAllDocsQueriesOptions() throws Throwable {
AllDocsQuery allDocsQueryModel = new AllDocsQuery.Builder().attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("0")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).startkey("testString").build();
assertEquals(allDocsQueryModel.attEncodingInfo(), Boolean.valueOf(false));
assertEquals(allDocsQueryModel.attachments(), Boolean.valueOf(false));
assertEquals(allDocsQueryModel.conflicts(), Boolean.valueOf(false));
assertEquals(allDocsQueryModel.descending(), Boolean.valueOf(false));
assertEquals(allDocsQueryModel.includeDocs(), Boolean.valueOf(false));
assertEquals(allDocsQueryModel.inclusiveEnd(), Boolean.valueOf(true));
assertEquals(allDocsQueryModel.limit(), Long.valueOf("0"));
assertEquals(allDocsQueryModel.skip(), Long.valueOf("0"));
assertEquals(allDocsQueryModel.updateSeq(), Boolean.valueOf(false));
assertEquals(allDocsQueryModel.endkey(), "testString");
assertEquals(allDocsQueryModel.key(), "testString");
assertEquals(allDocsQueryModel.keys(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(allDocsQueryModel.startkey(), "testString");
PostAllDocsQueriesOptions postAllDocsQueriesOptionsModel = new PostAllDocsQueriesOptions.Builder().db("testString").queries(new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel))).build();
assertEquals(postAllDocsQueriesOptionsModel.db(), "testString");
assertEquals(postAllDocsQueriesOptionsModel.queries(), new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel)));
}
use of com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostAllDocsQueriesAsStreamWOptions.
@Test
public void testPostAllDocsQueriesAsStreamWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"foo\": \"this is a mock response for JSON streaming\"}";
String postAllDocsQueriesAsStreamPath = "/testString/_all_docs/queries";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the AllDocsQuery model
AllDocsQuery allDocsQueryModel = new AllDocsQuery.Builder().attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("0")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("small-appliances:1000042", "small-appliances:1000043"))).startkey("testString").build();
// Construct an instance of the PostAllDocsQueriesOptions model
PostAllDocsQueriesOptions postAllDocsQueriesOptionsModel = new PostAllDocsQueriesOptions.Builder().db("testString").queries(new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel))).build();
// Invoke operation with valid options model (positive test)
Response<InputStream> response = cloudantService.postAllDocsQueriesAsStream(postAllDocsQueriesOptionsModel).execute();
assertNotNull(response);
InputStream 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);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, postAllDocsQueriesAsStreamPath);
// Verify streamed JSON response
java.util.Scanner s = new java.util.Scanner(responseObj).useDelimiter("\\A");
String streamedResponseBody = s.hasNext() ? s.next() : "";
assertEquals(streamedResponseBody, mockResponseBody);
}
Aggregations