Search in sources :

Example 16 with Ok

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

the class CloudantTest method testDeleteReplicationDocumentWOptions.

@Test
public void testDeleteReplicationDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
    String deleteReplicationDocumentPath = "/_replicator/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the DeleteReplicationDocumentOptions model
    DeleteReplicationDocumentOptions deleteReplicationDocumentOptionsModel = new DeleteReplicationDocumentOptions.Builder().docId("testString").ifMatch("testString").batch("ok").rev("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<DocumentResult> response = cloudantService.deleteReplicationDocument(deleteReplicationDocumentOptionsModel).execute();
    assertNotNull(response);
    DocumentResult responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "DELETE");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("batch"), "ok");
    assertEquals(query.get("rev"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteReplicationDocumentPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteReplicationDocumentOptions(com.ibm.cloud.cloudant.v1.model.DeleteReplicationDocumentOptions) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with Ok

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

the class CloudantTest method testPostGeoCleanupWOptions.

@Test
public void testPostGeoCleanupWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"ok\": true}";
    String postGeoCleanupPath = "/testString/_geo_cleanup";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(202).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PostGeoCleanupOptions model
    PostGeoCleanupOptions postGeoCleanupOptionsModel = new PostGeoCleanupOptions.Builder().db("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Ok> response = cloudantService.postGeoCleanup(postGeoCleanupOptionsModel).execute();
    assertNotNull(response);
    Ok 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, postGeoCleanupPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) PostGeoCleanupOptions(com.ibm.cloud.cloudant.v1.model.PostGeoCleanupOptions) Ok(com.ibm.cloud.cloudant.v1.model.Ok) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with Ok

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

the class CloudantTest method testGetGeoAsStreamWOptions.

@Test
public void testGetGeoAsStreamWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"foo\": \"this is a mock response for JSON streaming\"}";
    String getGeoAsStreamPath = "/testString/_design/testString/_geo/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetGeoOptions model
    GetGeoOptions getGeoOptionsModel = new GetGeoOptions.Builder().db("testString").ddoc("testString").index("testString").bbox("testString").bookmark("testString").format("view").g("testString").includeDocs(false).lat(Double.valueOf("-90")).limit(Long.valueOf("0")).lon(Double.valueOf("-180")).nearest(false).radius(Double.valueOf("0")).rangex(Double.valueOf("0")).rangey(Double.valueOf("0")).relation("intersects").skip(Long.valueOf("0")).stale("ok").build();
    // Invoke operation with valid options model (positive test)
    Response<InputStream> response = cloudantService.getGeoAsStream(getGeoOptionsModel).execute();
    assertNotNull(response);
    InputStream responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("bbox"), "testString");
    assertEquals(query.get("bookmark"), "testString");
    assertEquals(query.get("format"), "view");
    assertEquals(query.get("g"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_docs")), Boolean.valueOf(false));
    assertEquals(Double.valueOf(query.get("lat")), Double.valueOf("-90"));
    assertEquals(Long.valueOf(query.get("limit")), Long.valueOf("0"));
    assertEquals(Double.valueOf(query.get("lon")), Double.valueOf("-180"));
    assertEquals(Boolean.valueOf(query.get("nearest")), Boolean.valueOf(false));
    assertEquals(Double.valueOf(query.get("radius")), Double.valueOf("0"));
    assertEquals(Double.valueOf(query.get("rangex")), Double.valueOf("0"));
    assertEquals(Double.valueOf(query.get("rangey")), Double.valueOf("0"));
    assertEquals(query.get("relation"), "intersects");
    assertEquals(Long.valueOf(query.get("skip")), Long.valueOf("0"));
    assertEquals(query.get("stale"), "ok");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getGeoAsStreamPath);
    // 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) GetGeoOptions(com.ibm.cloud.cloudant.v1.model.GetGeoOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with Ok

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

the class DeleteDocumentOptionsTest method testDeleteDocumentOptions.

@Test
public void testDeleteDocumentOptions() throws Throwable {
    DeleteDocumentOptions deleteDocumentOptionsModel = new DeleteDocumentOptions.Builder().db("testString").docId("testString").ifMatch("testString").batch("ok").rev("testString").build();
    assertEquals(deleteDocumentOptionsModel.db(), "testString");
    assertEquals(deleteDocumentOptionsModel.docId(), "testString");
    assertEquals(deleteDocumentOptionsModel.ifMatch(), "testString");
    assertEquals(deleteDocumentOptionsModel.batch(), "ok");
    assertEquals(deleteDocumentOptionsModel.rev(), "testString");
}
Also used : DeleteDocumentOptions(com.ibm.cloud.cloudant.v1.model.DeleteDocumentOptions) Test(org.testng.annotations.Test)

Example 20 with Ok

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

the class DeleteReplicationDocumentOptionsTest method testDeleteReplicationDocumentOptions.

@Test
public void testDeleteReplicationDocumentOptions() throws Throwable {
    DeleteReplicationDocumentOptions deleteReplicationDocumentOptionsModel = new DeleteReplicationDocumentOptions.Builder().docId("testString").ifMatch("testString").batch("ok").rev("testString").build();
    assertEquals(deleteReplicationDocumentOptionsModel.docId(), "testString");
    assertEquals(deleteReplicationDocumentOptionsModel.ifMatch(), "testString");
    assertEquals(deleteReplicationDocumentOptionsModel.batch(), "ok");
    assertEquals(deleteReplicationDocumentOptionsModel.rev(), "testString");
}
Also used : DeleteReplicationDocumentOptions(com.ibm.cloud.cloudant.v1.model.DeleteReplicationDocumentOptions) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)43 MockResponse (okhttp3.mockwebserver.MockResponse)29 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 ArrayList (java.util.ArrayList)19 Ok (com.ibm.cloud.cloudant.v1.model.Ok)18 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)13 HashMap (java.util.HashMap)13 Attachment (com.ibm.cloud.cloudant.v1.model.Attachment)11 DocumentRevisionStatus (com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus)11 Revisions (com.ibm.cloud.cloudant.v1.model.Revisions)11 Document (com.ibm.cloud.cloudant.v1.model.Document)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)8 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)6 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)6 BulkGetQueryDocument (com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument)5 JsonObject (com.google.gson.JsonObject)4 BulkGetResultDocument (com.ibm.cloud.cloudant.v1.model.BulkGetResultDocument)4 SchedulerDocument (com.ibm.cloud.cloudant.v1.model.SchedulerDocument)4 List (java.util.List)4