Search in sources :

Example 1 with ViewQueriesResult

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

the class Cloudant method postViewQueries.

/**
 * Multi-query a MapReduce view.
 *
 * This operation runs multiple specified view queries against the view function from the specified design document.
 *
 * @param postViewQueriesOptions the {@link PostViewQueriesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ViewQueriesResult}
 */
public ServiceCall<ViewQueriesResult> postViewQueries(PostViewQueriesOptions postViewQueriesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postViewQueriesOptions, "postViewQueriesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postViewQueriesOptions.db());
    pathParamsMap.put("ddoc", postViewQueriesOptions.ddoc());
    pathParamsMap.put("view", postViewQueriesOptions.view());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}/_view/{view}/queries", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postViewQueries");
    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(postViewQueriesOptions.queries()));
    builder.bodyJson(contentJson);
    ResponseConverter<ViewQueriesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ViewQueriesResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) ViewQueriesResult(com.ibm.cloud.cloudant.v1.model.ViewQueriesResult) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject)

Example 2 with ViewQueriesResult

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

the class CloudantTest method testPostViewQueriesWOptions.

@Test
public void testPostViewQueriesWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"results\": [{\"total_rows\": 0, \"update_seq\": \"updateSeq\", \"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\": \"anyValue\", \"value\": \"anyValue\"}]}]}";
    String postViewQueriesPath = "/testString/_design/testString/_view/testString/queries";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ViewQuery model
    ViewQuery viewQueryModel = new ViewQuery.Builder().attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(true).inclusiveEnd(true).limit(Long.valueOf("5")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").endkeyDocid("testString").group(false).groupLevel(Long.valueOf("1")).key("testString").keys(new java.util.ArrayList<Object>(java.util.Arrays.asList("testString"))).reduce(true).stable(false).startkey("testString").startkeyDocid("testString").update("true").build();
    // Construct an instance of the PostViewQueriesOptions model
    PostViewQueriesOptions postViewQueriesOptionsModel = new PostViewQueriesOptions.Builder().db("testString").ddoc("testString").view("testString").queries(new java.util.ArrayList<ViewQuery>(java.util.Arrays.asList(viewQueryModel))).build();
    // Invoke operation with valid options model (positive test)
    Response<ViewQueriesResult> response = cloudantService.postViewQueries(postViewQueriesOptionsModel).execute();
    assertNotNull(response);
    ViewQueriesResult 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, postViewQueriesPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) PostViewQueriesOptions(com.ibm.cloud.cloudant.v1.model.PostViewQueriesOptions) ArrayList(java.util.ArrayList) ViewQuery(com.ibm.cloud.cloudant.v1.model.ViewQuery) ViewQueriesResult(com.ibm.cloud.cloudant.v1.model.ViewQueriesResult) SecurityObject(com.ibm.cloud.cloudant.v1.model.SecurityObject) GeoJsonGeometryObject(com.ibm.cloud.cloudant.v1.model.GeoJsonGeometryObject) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ViewQueriesResult

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

the class ViewQueriesResultTest method testViewQueriesResult.

@Test
public void testViewQueriesResult() throws Throwable {
    ViewQueriesResult viewQueriesResultModel = new ViewQueriesResult();
    assertNull(viewQueriesResultModel.getResults());
}
Also used : ViewQueriesResult(com.ibm.cloud.cloudant.v1.model.ViewQueriesResult) Test(org.testng.annotations.Test)

Aggregations

ViewQueriesResult (com.ibm.cloud.cloudant.v1.model.ViewQueriesResult)3 Test (org.testng.annotations.Test)2 JsonObject (com.google.gson.JsonObject)1 GeoJsonGeometryObject (com.ibm.cloud.cloudant.v1.model.GeoJsonGeometryObject)1 PostViewQueriesOptions (com.ibm.cloud.cloudant.v1.model.PostViewQueriesOptions)1 SecurityObject (com.ibm.cloud.cloudant.v1.model.SecurityObject)1 ViewQuery (com.ibm.cloud.cloudant.v1.model.ViewQuery)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1