Search in sources :

Example 1 with PostDbsInfoOptions

use of com.ibm.cloud.cloudant.v1.model.PostDbsInfoOptions in project cloudant-java-sdk by IBM.

the class PostDbsInfoOptionsTest method testPostDbsInfoOptions.

@Test
public void testPostDbsInfoOptions() throws Throwable {
    PostDbsInfoOptions postDbsInfoOptionsModel = new PostDbsInfoOptions.Builder().keys(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    assertEquals(postDbsInfoOptionsModel.keys(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
}
Also used : PostDbsInfoOptions(com.ibm.cloud.cloudant.v1.model.PostDbsInfoOptions) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 2 with PostDbsInfoOptions

use of com.ibm.cloud.cloudant.v1.model.PostDbsInfoOptions in project cloudant-java-sdk by IBM.

the class CloudantTest method testPostDbsInfoWOptions.

@Test
public void testPostDbsInfoWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "[{\"error\": \"error\", \"info\": {\"cluster\": {\"n\": 1, \"q\": 1, \"r\": 1, \"w\": 1}, \"committed_update_seq\": \"committedUpdateSeq\", \"compact_running\": true, \"compacted_seq\": \"compactedSeq\", \"db_name\": \"dbName\", \"disk_format_version\": 17, \"doc_count\": 0, \"doc_del_count\": 0, \"engine\": \"engine\", \"props\": {\"partitioned\": false}, \"sizes\": {\"active\": 6, \"external\": 8, \"file\": 4}, \"update_seq\": \"updateSeq\", \"uuid\": \"uuid\"}, \"key\": \"key\"}]";
    String postDbsInfoPath = "/_dbs_info";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PostDbsInfoOptions model
    PostDbsInfoOptions postDbsInfoOptionsModel = new PostDbsInfoOptions.Builder().keys(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Invoke operation with valid options model (positive test)
    Response<List<DbsInfoResult>> response = cloudantService.postDbsInfo(postDbsInfoOptionsModel).execute();
    assertNotNull(response);
    List<DbsInfoResult> 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, postDbsInfoPath);
}
Also used : PostDbsInfoOptions(com.ibm.cloud.cloudant.v1.model.PostDbsInfoOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DbsInfoResult(com.ibm.cloud.cloudant.v1.model.DbsInfoResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with PostDbsInfoOptions

use of com.ibm.cloud.cloudant.v1.model.PostDbsInfoOptions in project cloudant-java-sdk by IBM.

the class Cloudant method postDbsInfo.

/**
 * Query information about multiple databases.
 *
 * This operation enables you to request information about multiple databases in a single request, instead of issuing
 * multiple `GET /{db}` requests. It returns a list that contains an information object for each database specified in
 * the request.
 *
 * @param postDbsInfoOptions the {@link PostDbsInfoOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link List}
 */
public ServiceCall<List<DbsInfoResult>> postDbsInfo(PostDbsInfoOptions postDbsInfoOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postDbsInfoOptions, "postDbsInfoOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_dbs_info"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postDbsInfo");
    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("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postDbsInfoOptions.keys()));
    builder.bodyJson(contentJson);
    ResponseConverter<List<DbsInfoResult>> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<List<DbsInfoResult>>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : DbsInfoResult(com.ibm.cloud.cloudant.v1.model.DbsInfoResult) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) List(java.util.List)

Aggregations

DbsInfoResult (com.ibm.cloud.cloudant.v1.model.DbsInfoResult)2 PostDbsInfoOptions (com.ibm.cloud.cloudant.v1.model.PostDbsInfoOptions)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.testng.annotations.Test)2 JsonObject (com.google.gson.JsonObject)1 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