use of com.ibm.cloud.cloudant.v1.model.ChangesResult in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostChangesWOptions.
@Test
public void testPostChangesWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"last_seq\": \"lastSeq\", \"pending\": 7, \"results\": [{\"changes\": [{\"rev\": \"rev\"}], \"deleted\": false, \"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\", \"seq\": \"seq\"}]}";
String postChangesPath = "/testString/_changes";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the PostChangesOptions model
PostChangesOptions postChangesOptionsModel = new PostChangesOptions.Builder().db("testString").docIds(new java.util.ArrayList<String>(java.util.Arrays.asList("0007741142412418284"))).fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).selector(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).lastEventId("testString").attEncodingInfo(false).attachments(false).conflicts(false).descending(false).feed("normal").filter("testString").heartbeat(Long.valueOf("0")).includeDocs(false).limit(Long.valueOf("0")).seqInterval(Long.valueOf("1")).since("0").style("main_only").timeout(Long.valueOf("0")).view("testString").build();
// Invoke operation with valid options model (positive test)
Response<ChangesResult> response = cloudantService.postChanges(postChangesOptionsModel).execute();
assertNotNull(response);
ChangesResult 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(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("descending")), Boolean.valueOf(false));
assertEquals(query.get("feed"), "normal");
assertEquals(query.get("filter"), "testString");
assertEquals(Long.valueOf(query.get("heartbeat")), Long.valueOf("0"));
assertEquals(Boolean.valueOf(query.get("include_docs")), Boolean.valueOf(false));
assertEquals(Long.valueOf(query.get("limit")), Long.valueOf("0"));
assertEquals(Long.valueOf(query.get("seq_interval")), Long.valueOf("1"));
assertEquals(query.get("since"), "0");
assertEquals(query.get("style"), "main_only");
assertEquals(Long.valueOf(query.get("timeout")), Long.valueOf("0"));
assertEquals(query.get("view"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, postChangesPath);
}
use of com.ibm.cloud.cloudant.v1.model.ChangesResult in project cloudant-java-sdk by IBM.
the class Cloudant method postChanges.
/**
* Query the database document changes feed.
*
* Requests the database changes feed in the same way as `GET /{db}/_changes` does. It is widely used with the
* `filter` query parameter because it allows one to pass more information to the filter.
*
* @param postChangesOptions the {@link PostChangesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ChangesResult}
*/
public ServiceCall<ChangesResult> postChanges(PostChangesOptions postChangesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postChangesOptions, "postChangesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postChangesOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_changes", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postChanges");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (postChangesOptions.lastEventId() != null) {
builder.header("Last-Event-ID", postChangesOptions.lastEventId());
}
if (postChangesOptions.attEncodingInfo() != null) {
builder.query("att_encoding_info", String.valueOf(postChangesOptions.attEncodingInfo()));
}
if (postChangesOptions.attachments() != null) {
builder.query("attachments", String.valueOf(postChangesOptions.attachments()));
}
if (postChangesOptions.conflicts() != null) {
builder.query("conflicts", String.valueOf(postChangesOptions.conflicts()));
}
if (postChangesOptions.descending() != null) {
builder.query("descending", String.valueOf(postChangesOptions.descending()));
}
if (postChangesOptions.feed() != null) {
builder.query("feed", String.valueOf(postChangesOptions.feed()));
}
if (postChangesOptions.filter() != null) {
builder.query("filter", String.valueOf(postChangesOptions.filter()));
}
if (postChangesOptions.heartbeat() != null) {
builder.query("heartbeat", String.valueOf(postChangesOptions.heartbeat()));
}
if (postChangesOptions.includeDocs() != null) {
builder.query("include_docs", String.valueOf(postChangesOptions.includeDocs()));
}
if (postChangesOptions.limit() != null) {
builder.query("limit", String.valueOf(postChangesOptions.limit()));
}
if (postChangesOptions.seqInterval() != null) {
builder.query("seq_interval", String.valueOf(postChangesOptions.seqInterval()));
}
if (postChangesOptions.since() != null) {
builder.query("since", String.valueOf(postChangesOptions.since()));
}
if (postChangesOptions.style() != null) {
builder.query("style", String.valueOf(postChangesOptions.style()));
}
if (postChangesOptions.timeout() != null) {
builder.query("timeout", String.valueOf(postChangesOptions.timeout()));
}
if (postChangesOptions.view() != null) {
builder.query("view", String.valueOf(postChangesOptions.view()));
}
final JsonObject contentJson = new JsonObject();
if (postChangesOptions.docIds() != null) {
contentJson.add("doc_ids", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postChangesOptions.docIds()));
}
if (postChangesOptions.fields() != null) {
contentJson.add("fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postChangesOptions.fields()));
}
if (postChangesOptions.selector() != null) {
contentJson.add("selector", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postChangesOptions.selector()));
}
builder.bodyJson(contentJson);
ResponseConverter<ChangesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ChangesResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.ChangesResult in project cloudant-java-sdk by IBM.
the class ChangesResultTest method testChangesResult.
@Test
public void testChangesResult() throws Throwable {
ChangesResult changesResultModel = new ChangesResult();
assertNull(changesResultModel.getLastSeq());
assertNull(changesResultModel.getPending());
assertNull(changesResultModel.getResults());
}
Aggregations