Search in sources :

Example 1 with GetDbUpdatesOptions

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");
}
Also used : GetDbUpdatesOptions(com.ibm.cloud.cloudant.v1.model.GetDbUpdatesOptions) Test(org.testng.annotations.Test)

Example 2 with GetDbUpdatesOptions

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DbUpdates(com.ibm.cloud.cloudant.v1.model.DbUpdates) GetDbUpdatesOptions(com.ibm.cloud.cloudant.v1.model.GetDbUpdatesOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with GetDbUpdatesOptions

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) DbUpdates(com.ibm.cloud.cloudant.v1.model.DbUpdates)

Aggregations

DbUpdates (com.ibm.cloud.cloudant.v1.model.DbUpdates)2 GetDbUpdatesOptions (com.ibm.cloud.cloudant.v1.model.GetDbUpdatesOptions)2 Test (org.testng.annotations.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1