use of com.ibm.cloud.cloudant.v1.model.GetDbUpdatesOptions in project cloudant-java-sdk by IBM.
the class GetDbUpdatesOptionsTest method testGetDbUpdatesOptions.
@Test
public void testGetDbUpdatesOptions() throws Throwable {
GetDbUpdatesOptions getDbUpdatesOptionsModel = new GetDbUpdatesOptions.Builder().feed("normal").heartbeat(Long.valueOf("0")).timeout(Long.valueOf("0")).since("0").build();
assertEquals(getDbUpdatesOptionsModel.feed(), "normal");
assertEquals(getDbUpdatesOptionsModel.heartbeat(), Long.valueOf("0"));
assertEquals(getDbUpdatesOptionsModel.timeout(), Long.valueOf("0"));
assertEquals(getDbUpdatesOptionsModel.since(), "0");
}
use of com.ibm.cloud.cloudant.v1.model.GetDbUpdatesOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetDbUpdatesWOptions.
@Test
public void testGetDbUpdatesWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"last_seq\": \"lastSeq\", \"results\": [{\"account\": \"account\", \"db_name\": \"dbName\", \"seq\": \"seq\", \"type\": \"created\"}]}";
String getDbUpdatesPath = "/_db_updates";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetDbUpdatesOptions model
GetDbUpdatesOptions getDbUpdatesOptionsModel = new GetDbUpdatesOptions.Builder().feed("normal").heartbeat(Long.valueOf("0")).timeout(Long.valueOf("0")).since("0").build();
// Invoke operation with valid options model (positive test)
Response<DbUpdates> response = cloudantService.getDbUpdates(getDbUpdatesOptionsModel).execute();
assertNotNull(response);
DbUpdates 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("feed"), "normal");
assertEquals(Long.valueOf(query.get("heartbeat")), Long.valueOf("0"));
assertEquals(Long.valueOf(query.get("timeout")), Long.valueOf("0"));
assertEquals(query.get("since"), "0");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getDbUpdatesPath);
}
use of com.ibm.cloud.cloudant.v1.model.GetDbUpdatesOptions in project cloudant-java-sdk by IBM.
the class Cloudant method getDbUpdates.
/**
* Retrieve change events for all databases.
*
* Lists changes to databases, like a global changes feed. Types of changes include updating the database and creating
* or deleting a database. Like the changes feed, the feed is not guaranteed to return changes in the correct order
* and might repeat changes. Polling modes for this method work like polling modes for the changes feed.
* **Note: This endpoint requires _admin or _db_updates role and is only available on dedicated clusters.**.
*
* @param getDbUpdatesOptions the {@link GetDbUpdatesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DbUpdates}
*/
public ServiceCall<DbUpdates> getDbUpdates(GetDbUpdatesOptions getDbUpdatesOptions) {
if (getDbUpdatesOptions == null) {
getDbUpdatesOptions = new GetDbUpdatesOptions.Builder().build();
}
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_db_updates"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDbUpdates");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (getDbUpdatesOptions.feed() != null) {
builder.query("feed", String.valueOf(getDbUpdatesOptions.feed()));
}
if (getDbUpdatesOptions.heartbeat() != null) {
builder.query("heartbeat", String.valueOf(getDbUpdatesOptions.heartbeat()));
}
if (getDbUpdatesOptions.timeout() != null) {
builder.query("timeout", String.valueOf(getDbUpdatesOptions.timeout()));
}
if (getDbUpdatesOptions.since() != null) {
builder.query("since", String.valueOf(getDbUpdatesOptions.since()));
}
ResponseConverter<DbUpdates> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DbUpdates>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations