Search in sources :

Example 1 with AllDocsQueriesResult

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

the class CloudantTest method testPostAllDocsQueriesWOptions.

@Test
public void testPostAllDocsQueriesWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"results\": [{\"total_rows\": 0, \"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\": \"key\", \"value\": {\"rev\": \"rev\"}}], \"update_seq\": \"updateSeq\"}]}";
    String postAllDocsQueriesPath = "/testString/_all_docs/queries";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the AllDocsQuery model
    AllDocsQuery allDocsQueryModel = new AllDocsQuery.Builder().attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("0")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("small-appliances:1000042", "small-appliances:1000043"))).startkey("testString").build();
    // Construct an instance of the PostAllDocsQueriesOptions model
    PostAllDocsQueriesOptions postAllDocsQueriesOptionsModel = new PostAllDocsQueriesOptions.Builder().db("testString").queries(new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel))).build();
    // Invoke operation with valid options model (positive test)
    Response<AllDocsQueriesResult> response = cloudantService.postAllDocsQueries(postAllDocsQueriesOptionsModel).execute();
    assertNotNull(response);
    AllDocsQueriesResult 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, postAllDocsQueriesPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ArrayList(java.util.ArrayList) PostAllDocsQueriesOptions(com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions) AllDocsQuery(com.ibm.cloud.cloudant.v1.model.AllDocsQuery) AllDocsQueriesResult(com.ibm.cloud.cloudant.v1.model.AllDocsQueriesResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with AllDocsQueriesResult

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

the class Cloudant method postAllDocsQueries.

/**
 * Multi-query the list of all documents in a database.
 *
 * Runs multiple queries using the primary index (all document IDs). Returns a JSON object that contains a list of
 * result objects, one for each query, with a structure equivalent to that of a single `_all_docs` request. This
 * enables you to request multiple queries in a single request, in place of multiple `POST /{db}/_all_docs` requests.
 *
 * @param postAllDocsQueriesOptions the {@link PostAllDocsQueriesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link AllDocsQueriesResult}
 */
public ServiceCall<AllDocsQueriesResult> postAllDocsQueries(PostAllDocsQueriesOptions postAllDocsQueriesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postAllDocsQueriesOptions, "postAllDocsQueriesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postAllDocsQueriesOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_all_docs/queries", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postAllDocsQueries");
    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(postAllDocsQueriesOptions.queries()));
    builder.bodyJson(contentJson);
    ResponseConverter<AllDocsQueriesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsQueriesResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) AllDocsQueriesResult(com.ibm.cloud.cloudant.v1.model.AllDocsQueriesResult)

Example 3 with AllDocsQueriesResult

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

the class AllDocsQueriesResultTest method testAllDocsQueriesResult.

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

Example 4 with AllDocsQueriesResult

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

the class CloudantTest method testPostDesignDocsQueriesWOptions.

@Test
public void testPostDesignDocsQueriesWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"results\": [{\"total_rows\": 0, \"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\": \"key\", \"value\": {\"rev\": \"rev\"}}], \"update_seq\": \"updateSeq\"}]}";
    String postDesignDocsQueriesPath = "/testString/_design_docs/queries";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the AllDocsQuery model
    AllDocsQuery allDocsQueryModel = new AllDocsQuery.Builder().attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("0")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("small-appliances:1000042", "small-appliances:1000043"))).startkey("testString").build();
    // Construct an instance of the PostDesignDocsQueriesOptions model
    PostDesignDocsQueriesOptions postDesignDocsQueriesOptionsModel = new PostDesignDocsQueriesOptions.Builder().db("testString").queries(new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel))).accept("application/json").build();
    // Invoke operation with valid options model (positive test)
    Response<AllDocsQueriesResult> response = cloudantService.postDesignDocsQueries(postDesignDocsQueriesOptionsModel).execute();
    assertNotNull(response);
    AllDocsQueriesResult 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, postDesignDocsQueriesPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) AllDocsQuery(com.ibm.cloud.cloudant.v1.model.AllDocsQuery) PostDesignDocsQueriesOptions(com.ibm.cloud.cloudant.v1.model.PostDesignDocsQueriesOptions) AllDocsQueriesResult(com.ibm.cloud.cloudant.v1.model.AllDocsQueriesResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with AllDocsQueriesResult

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

the class Cloudant method postDesignDocsQueries.

/**
 * Multi-query the list of all design documents.
 *
 * This operation runs multiple view queries of all design documents in the database. This operation enables you to
 * request numerous queries in a single request, in place of multiple POST `/{db}/_design_docs` requests.
 *
 * @param postDesignDocsQueriesOptions the {@link PostDesignDocsQueriesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link AllDocsQueriesResult}
 */
public ServiceCall<AllDocsQueriesResult> postDesignDocsQueries(PostDesignDocsQueriesOptions postDesignDocsQueriesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postDesignDocsQueriesOptions, "postDesignDocsQueriesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postDesignDocsQueriesOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design_docs/queries", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postDesignDocsQueries");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    if (postDesignDocsQueriesOptions.accept() != null) {
        builder.header("Accept", postDesignDocsQueriesOptions.accept());
    }
    final JsonObject contentJson = new JsonObject();
    contentJson.add("queries", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postDesignDocsQueriesOptions.queries()));
    builder.bodyJson(contentJson);
    ResponseConverter<AllDocsQueriesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsQueriesResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) AllDocsQueriesResult(com.ibm.cloud.cloudant.v1.model.AllDocsQueriesResult)

Aggregations

AllDocsQueriesResult (com.ibm.cloud.cloudant.v1.model.AllDocsQueriesResult)5 Test (org.testng.annotations.Test)3 JsonObject (com.google.gson.JsonObject)2 AllDocsQuery (com.ibm.cloud.cloudant.v1.model.AllDocsQuery)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)2 HashMap (java.util.HashMap)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 PostAllDocsQueriesOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions)1 PostDesignDocsQueriesOptions (com.ibm.cloud.cloudant.v1.model.PostDesignDocsQueriesOptions)1 ArrayList (java.util.ArrayList)1