Search in sources :

Example 1 with BulkGetQueryDocument

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

the class CloudantTest method testPostBulkGetAsRelatedWOptions.

@Test
public void testPostBulkGetAsRelatedWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "This is a mock binary response.";
    String postBulkGetAsRelatedPath = "/testString/_bulk_get";
    server.enqueue(new MockResponse().setHeader("Content-type", "multipart/related").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the BulkGetQueryDocument model
    BulkGetQueryDocument bulkGetQueryDocumentModel = new BulkGetQueryDocument.Builder().attsSince(new java.util.ArrayList<String>(java.util.Arrays.asList("1-99b02e08da151943c2dcb40090160bb8"))).id("order00067").rev("3-917fa2381192822767f010b95b45325b").build();
    // Construct an instance of the PostBulkGetOptions model
    PostBulkGetOptions postBulkGetOptionsModel = new PostBulkGetOptions.Builder().db("testString").docs(new java.util.ArrayList<BulkGetQueryDocument>(java.util.Arrays.asList(bulkGetQueryDocumentModel))).attachments(false).attEncodingInfo(false).latest(false).revs(false).build();
    // Invoke operation with valid options model (positive test)
    Response<InputStream> response = cloudantService.postBulkGetAsRelated(postBulkGetOptionsModel).execute();
    assertNotNull(response);
    InputStream 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);
    assertNotNull(query);
    // Get query params
    assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postBulkGetAsRelatedPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) PostBulkGetOptions(com.ibm.cloud.cloudant.v1.model.PostBulkGetOptions) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with BulkGetQueryDocument

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

the class BulkGetQueryDocumentTest method testBulkGetQueryDocument.

@Test
public void testBulkGetQueryDocument() throws Throwable {
    BulkGetQueryDocument bulkGetQueryDocumentModel = new BulkGetQueryDocument.Builder().attsSince(new java.util.ArrayList<String>(java.util.Arrays.asList("1-99b02e08da151943c2dcb40090160bb8"))).id("testString").rev("testString").build();
    assertEquals(bulkGetQueryDocumentModel.attsSince(), new java.util.ArrayList<String>(java.util.Arrays.asList("1-99b02e08da151943c2dcb40090160bb8")));
    assertEquals(bulkGetQueryDocumentModel.id(), "testString");
    assertEquals(bulkGetQueryDocumentModel.rev(), "testString");
    String json = TestUtilities.serialize(bulkGetQueryDocumentModel);
    BulkGetQueryDocument bulkGetQueryDocumentModelNew = TestUtilities.deserialize(json, BulkGetQueryDocument.class);
    assertTrue(bulkGetQueryDocumentModelNew instanceof BulkGetQueryDocument);
    assertEquals(bulkGetQueryDocumentModelNew.id(), "testString");
    assertEquals(bulkGetQueryDocumentModelNew.rev(), "testString");
}
Also used : BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 3 with BulkGetQueryDocument

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

the class PostBulkGetOptionsTest method testPostBulkGetOptions.

@Test
public void testPostBulkGetOptions() throws Throwable {
    BulkGetQueryDocument bulkGetQueryDocumentModel = new BulkGetQueryDocument.Builder().attsSince(new java.util.ArrayList<String>(java.util.Arrays.asList("1-99b02e08da151943c2dcb40090160bb8"))).id("testString").rev("testString").build();
    assertEquals(bulkGetQueryDocumentModel.attsSince(), new java.util.ArrayList<String>(java.util.Arrays.asList("1-99b02e08da151943c2dcb40090160bb8")));
    assertEquals(bulkGetQueryDocumentModel.id(), "testString");
    assertEquals(bulkGetQueryDocumentModel.rev(), "testString");
    PostBulkGetOptions postBulkGetOptionsModel = new PostBulkGetOptions.Builder().db("testString").docs(new java.util.ArrayList<BulkGetQueryDocument>(java.util.Arrays.asList(bulkGetQueryDocumentModel))).attachments(false).attEncodingInfo(false).latest(false).revs(false).build();
    assertEquals(postBulkGetOptionsModel.db(), "testString");
    assertEquals(postBulkGetOptionsModel.docs(), new java.util.ArrayList<BulkGetQueryDocument>(java.util.Arrays.asList(bulkGetQueryDocumentModel)));
    assertEquals(postBulkGetOptionsModel.attachments(), Boolean.valueOf(false));
    assertEquals(postBulkGetOptionsModel.attEncodingInfo(), Boolean.valueOf(false));
    assertEquals(postBulkGetOptionsModel.latest(), Boolean.valueOf(false));
    assertEquals(postBulkGetOptionsModel.revs(), Boolean.valueOf(false));
}
Also used : BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) PostBulkGetOptions(com.ibm.cloud.cloudant.v1.model.PostBulkGetOptions) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 4 with BulkGetQueryDocument

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

the class CloudantTest method testPostBulkGetAsStreamWOptions.

@Test
public void testPostBulkGetAsStreamWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"foo\": \"this is a mock response for JSON streaming\"}";
    String postBulkGetAsStreamPath = "/testString/_bulk_get";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the BulkGetQueryDocument model
    BulkGetQueryDocument bulkGetQueryDocumentModel = new BulkGetQueryDocument.Builder().attsSince(new java.util.ArrayList<String>(java.util.Arrays.asList("1-99b02e08da151943c2dcb40090160bb8"))).id("order00067").rev("3-917fa2381192822767f010b95b45325b").build();
    // Construct an instance of the PostBulkGetOptions model
    PostBulkGetOptions postBulkGetOptionsModel = new PostBulkGetOptions.Builder().db("testString").docs(new java.util.ArrayList<BulkGetQueryDocument>(java.util.Arrays.asList(bulkGetQueryDocumentModel))).attachments(false).attEncodingInfo(false).latest(false).revs(false).build();
    // Invoke operation with valid options model (positive test)
    Response<InputStream> response = cloudantService.postBulkGetAsStream(postBulkGetOptionsModel).execute();
    assertNotNull(response);
    InputStream 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);
    assertNotNull(query);
    // Get query params
    assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postBulkGetAsStreamPath);
    // Verify streamed JSON response
    java.util.Scanner s = new java.util.Scanner(responseObj).useDelimiter("\\A");
    String streamedResponseBody = s.hasNext() ? s.next() : "";
    assertEquals(streamedResponseBody, mockResponseBody);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) PostBulkGetOptions(com.ibm.cloud.cloudant.v1.model.PostBulkGetOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with BulkGetQueryDocument

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

the class CloudantTest method testPostBulkGetAsMixedWOptions.

@Test
public void testPostBulkGetAsMixedWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "This is a mock binary response.";
    String postBulkGetAsMixedPath = "/testString/_bulk_get";
    server.enqueue(new MockResponse().setHeader("Content-type", "multipart/mixed").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the BulkGetQueryDocument model
    BulkGetQueryDocument bulkGetQueryDocumentModel = new BulkGetQueryDocument.Builder().attsSince(new java.util.ArrayList<String>(java.util.Arrays.asList("1-99b02e08da151943c2dcb40090160bb8"))).id("order00067").rev("3-917fa2381192822767f010b95b45325b").build();
    // Construct an instance of the PostBulkGetOptions model
    PostBulkGetOptions postBulkGetOptionsModel = new PostBulkGetOptions.Builder().db("testString").docs(new java.util.ArrayList<BulkGetQueryDocument>(java.util.Arrays.asList(bulkGetQueryDocumentModel))).attachments(false).attEncodingInfo(false).latest(false).revs(false).build();
    // Invoke operation with valid options model (positive test)
    Response<InputStream> response = cloudantService.postBulkGetAsMixed(postBulkGetOptionsModel).execute();
    assertNotNull(response);
    InputStream 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);
    assertNotNull(query);
    // Get query params
    assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postBulkGetAsMixedPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) PostBulkGetOptions(com.ibm.cloud.cloudant.v1.model.PostBulkGetOptions) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

BulkGetQueryDocument (com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument)6 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 PostBulkGetOptions (com.ibm.cloud.cloudant.v1.model.PostBulkGetOptions)5 MockResponse (okhttp3.mockwebserver.MockResponse)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 InputStream (java.io.InputStream)3 BulkGetResult (com.ibm.cloud.cloudant.v1.model.BulkGetResult)1