Search in sources :

Example 1 with AllDocsQuery

use of com.ibm.cloud.cloudant.v1.model.AllDocsQuery 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 AllDocsQuery

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

the class AllDocsQueryTest method testAllDocsQuery.

@Test
public void testAllDocsQuery() throws Throwable {
    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("testString"))).startkey("testString").build();
    assertEquals(allDocsQueryModel.attEncodingInfo(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.attachments(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.conflicts(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.descending(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.includeDocs(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.inclusiveEnd(), Boolean.valueOf(true));
    assertEquals(allDocsQueryModel.limit(), Long.valueOf("0"));
    assertEquals(allDocsQueryModel.skip(), Long.valueOf("0"));
    assertEquals(allDocsQueryModel.updateSeq(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.endkey(), "testString");
    assertEquals(allDocsQueryModel.key(), "testString");
    assertEquals(allDocsQueryModel.keys(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(allDocsQueryModel.startkey(), "testString");
    String json = TestUtilities.serialize(allDocsQueryModel);
    AllDocsQuery allDocsQueryModelNew = TestUtilities.deserialize(json, AllDocsQuery.class);
    assertTrue(allDocsQueryModelNew instanceof AllDocsQuery);
    assertEquals(allDocsQueryModelNew.attEncodingInfo(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModelNew.attachments(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModelNew.conflicts(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModelNew.descending(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModelNew.includeDocs(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModelNew.inclusiveEnd(), Boolean.valueOf(true));
    assertEquals(allDocsQueryModelNew.limit(), Long.valueOf("0"));
    assertEquals(allDocsQueryModelNew.skip(), Long.valueOf("0"));
    assertEquals(allDocsQueryModelNew.updateSeq(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModelNew.endkey(), "testString");
    assertEquals(allDocsQueryModelNew.key(), "testString");
    assertEquals(allDocsQueryModelNew.startkey(), "testString");
}
Also used : AllDocsQuery(com.ibm.cloud.cloudant.v1.model.AllDocsQuery) Test(org.testng.annotations.Test)

Example 3 with AllDocsQuery

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

the class PostDesignDocsQueriesOptionsTest method testPostDesignDocsQueriesOptions.

@Test
public void testPostDesignDocsQueriesOptions() throws Throwable {
    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("testString"))).startkey("testString").build();
    assertEquals(allDocsQueryModel.attEncodingInfo(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.attachments(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.conflicts(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.descending(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.includeDocs(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.inclusiveEnd(), Boolean.valueOf(true));
    assertEquals(allDocsQueryModel.limit(), Long.valueOf("0"));
    assertEquals(allDocsQueryModel.skip(), Long.valueOf("0"));
    assertEquals(allDocsQueryModel.updateSeq(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.endkey(), "testString");
    assertEquals(allDocsQueryModel.key(), "testString");
    assertEquals(allDocsQueryModel.keys(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(allDocsQueryModel.startkey(), "testString");
    PostDesignDocsQueriesOptions postDesignDocsQueriesOptionsModel = new PostDesignDocsQueriesOptions.Builder().db("testString").queries(new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel))).accept("application/json").build();
    assertEquals(postDesignDocsQueriesOptionsModel.db(), "testString");
    assertEquals(postDesignDocsQueriesOptionsModel.queries(), new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel)));
    assertEquals(postDesignDocsQueriesOptionsModel.accept(), "application/json");
}
Also used : AllDocsQuery(com.ibm.cloud.cloudant.v1.model.AllDocsQuery) PostDesignDocsQueriesOptions(com.ibm.cloud.cloudant.v1.model.PostDesignDocsQueriesOptions) Test(org.testng.annotations.Test)

Example 4 with AllDocsQuery

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

the class PostAllDocsQueriesOptionsTest method testPostAllDocsQueriesOptions.

@Test
public void testPostAllDocsQueriesOptions() throws Throwable {
    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("testString"))).startkey("testString").build();
    assertEquals(allDocsQueryModel.attEncodingInfo(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.attachments(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.conflicts(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.descending(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.includeDocs(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.inclusiveEnd(), Boolean.valueOf(true));
    assertEquals(allDocsQueryModel.limit(), Long.valueOf("0"));
    assertEquals(allDocsQueryModel.skip(), Long.valueOf("0"));
    assertEquals(allDocsQueryModel.updateSeq(), Boolean.valueOf(false));
    assertEquals(allDocsQueryModel.endkey(), "testString");
    assertEquals(allDocsQueryModel.key(), "testString");
    assertEquals(allDocsQueryModel.keys(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(allDocsQueryModel.startkey(), "testString");
    PostAllDocsQueriesOptions postAllDocsQueriesOptionsModel = new PostAllDocsQueriesOptions.Builder().db("testString").queries(new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel))).build();
    assertEquals(postAllDocsQueriesOptionsModel.db(), "testString");
    assertEquals(postAllDocsQueriesOptionsModel.queries(), new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel)));
}
Also used : PostAllDocsQueriesOptions(com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions) AllDocsQuery(com.ibm.cloud.cloudant.v1.model.AllDocsQuery) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 5 with AllDocsQuery

use of com.ibm.cloud.cloudant.v1.model.AllDocsQuery 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)

Aggregations

AllDocsQuery (com.ibm.cloud.cloudant.v1.model.AllDocsQuery)6 Test (org.testng.annotations.Test)6 PostAllDocsQueriesOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions)3 ArrayList (java.util.ArrayList)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AllDocsQueriesResult (com.ibm.cloud.cloudant.v1.model.AllDocsQueriesResult)2 PostDesignDocsQueriesOptions (com.ibm.cloud.cloudant.v1.model.PostDesignDocsQueriesOptions)2 InputStream (java.io.InputStream)1