Search in sources :

Example 36 with Ok

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

the class CloudantTest method testGetSessionInformationWOptions.

@Test
public void testGetSessionInformationWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"ok\": true, \"info\": {\"authenticated\": \"authenticated\", \"authentication_db\": \"authenticationDb\", \"authentication_handlers\": [\"authenticationHandlers\"]}, \"userCtx\": {\"db\": \"db\", \"name\": \"name\", \"roles\": [\"_reader\"]}}";
    String getSessionInformationPath = "/_session";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetSessionInformationOptions model
    GetSessionInformationOptions getSessionInformationOptionsModel = new GetSessionInformationOptions();
    // Invoke operation with valid options model (positive test)
    Response<SessionInformation> response = cloudantService.getSessionInformation(getSessionInformationOptionsModel).execute();
    assertNotNull(response);
    SessionInformation 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);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getSessionInformationPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetSessionInformationOptions(com.ibm.cloud.cloudant.v1.model.GetSessionInformationOptions) SessionInformation(com.ibm.cloud.cloudant.v1.model.SessionInformation) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 37 with Ok

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

the class CloudantTest method testPostDocumentWOptions.

@Test
public void testPostDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
    String postDocumentPath = "/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the Attachment model
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    // Construct an instance of the Revisions model
    Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
    // Construct an instance of the DocumentRevisionStatus model
    DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
    // Construct an instance of the Document model
    Document documentModel = new Document.Builder().attachments(new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    }).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).add("foo", "testString").build();
    // Construct an instance of the PostDocumentOptions model
    PostDocumentOptions postDocumentOptionsModel = new PostDocumentOptions.Builder().db("testString").document(documentModel).contentType("application/json").batch("ok").build();
    // Invoke operation with valid options model (positive test)
    Response<DocumentResult> response = cloudantService.postDocument(postDocumentOptionsModel).execute();
    assertNotNull(response);
    DocumentResult 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(query.get("batch"), "ok");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postDocumentPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) ArrayList(java.util.ArrayList) Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Revisions(com.ibm.cloud.cloudant.v1.model.Revisions) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) DesignDocument(com.ibm.cloud.cloudant.v1.model.DesignDocument) Document(com.ibm.cloud.cloudant.v1.model.Document) SchedulerDocument(com.ibm.cloud.cloudant.v1.model.SchedulerDocument) BulkGetResultDocument(com.ibm.cloud.cloudant.v1.model.BulkGetResultDocument) BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) DocumentRevisionStatus(com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus) PostDocumentOptions(com.ibm.cloud.cloudant.v1.model.PostDocumentOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 38 with Ok

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

the class CloudantTest method testPutDatabaseWOptions.

@Test
public void testPutDatabaseWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"ok\": true}";
    String putDatabasePath = "/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PutDatabaseOptions model
    PutDatabaseOptions putDatabaseOptionsModel = new PutDatabaseOptions.Builder().db("testString").partitioned(false).q(Long.valueOf("26")).build();
    // Invoke operation with valid options model (positive test)
    Response<Ok> response = cloudantService.putDatabase(putDatabaseOptionsModel).execute();
    assertNotNull(response);
    Ok responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PUT");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(Boolean.valueOf(query.get("partitioned")), Boolean.valueOf(false));
    assertEquals(Long.valueOf(query.get("q")), Long.valueOf("26"));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, putDatabasePath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) PutDatabaseOptions(com.ibm.cloud.cloudant.v1.model.PutDatabaseOptions) Ok(com.ibm.cloud.cloudant.v1.model.Ok) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 39 with Ok

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

the class CloudantTest method testPutLocalDocumentWOptions.

@Test
public void testPutLocalDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
    String putLocalDocumentPath = "/testString/_local/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the Attachment model
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    // Construct an instance of the Revisions model
    Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
    // Construct an instance of the DocumentRevisionStatus model
    DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
    // Construct an instance of the Document model
    Document documentModel = new Document.Builder().attachments(new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    }).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("exampleid").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).add("brand", "Foo").add("colours", "[\"red\",\"green\",\"black\",\"blue\"]").add("description", "Slim Colourful Design Electronic Cooking Appliance for ...").add("image", "assets/img/0gmsnghhew.jpg").add("keywords", "[\"Foo\",\"Scales\",\"Weight\",\"Digital\",\"Kitchen\"]").add("name", "Digital Kitchen Scales").add("price", "14.99").add("productid", "1000042").add("taxonomy", "[\"Home\",\"Kitchen\",\"Small Appliances\"]").add("type", "product").build();
    // Construct an instance of the PutLocalDocumentOptions model
    PutLocalDocumentOptions putLocalDocumentOptionsModel = new PutLocalDocumentOptions.Builder().db("testString").docId("testString").document(documentModel).contentType("application/json").batch("ok").build();
    // Invoke operation with valid options model (positive test)
    Response<DocumentResult> response = cloudantService.putLocalDocument(putLocalDocumentOptionsModel).execute();
    assertNotNull(response);
    DocumentResult responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PUT");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("batch"), "ok");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, putLocalDocumentPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HashMap(java.util.HashMap) PutLocalDocumentOptions(com.ibm.cloud.cloudant.v1.model.PutLocalDocumentOptions) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) ArrayList(java.util.ArrayList) Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Revisions(com.ibm.cloud.cloudant.v1.model.Revisions) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) DesignDocument(com.ibm.cloud.cloudant.v1.model.DesignDocument) Document(com.ibm.cloud.cloudant.v1.model.Document) SchedulerDocument(com.ibm.cloud.cloudant.v1.model.SchedulerDocument) BulkGetResultDocument(com.ibm.cloud.cloudant.v1.model.BulkGetResultDocument) BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) DocumentRevisionStatus(com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 40 with Ok

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

the class CloudantTest method testPostSearchAsStreamWOptions.

@Test
public void testPostSearchAsStreamWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"foo\": \"this is a mock response for JSON streaming\"}";
    String postSearchAsStreamPath = "/testString/_design/testString/_search/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PostSearchOptions model
    PostSearchOptions postSearchOptionsModel = new PostSearchOptions.Builder().db("testString").ddoc("testString").index("testString").query("testString").bookmark("testString").highlightFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).highlightNumber(Long.valueOf("1")).highlightPostTag("</em>").highlightPreTag("<em>").highlightSize(Long.valueOf("1")).includeDocs(false).includeFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).limit(Long.valueOf("3")).sort(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).stale("ok").counts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).drilldown(new java.util.ArrayList<List<String>>(java.util.Arrays.asList(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))))).groupField("testString").groupLimit(Long.valueOf("1")).groupSort(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).ranges(new java.util.HashMap<String, Map<String, Map<String, String>>>() {

        {
            put("foo", new java.util.HashMap<String, Map<String, String>>() {

                {
                    put("foo", new java.util.HashMap<String, String>() {

                        {
                            put("foo", "testString");
                        }
                    });
                }
            });
        }
    }).build();
    // Invoke operation with valid options model (positive test)
    Response<InputStream> response = cloudantService.postSearchAsStream(postSearchOptionsModel).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);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postSearchAsStreamPath);
    // 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) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) PostSearchOptions(com.ibm.cloud.cloudant.v1.model.PostSearchOptions) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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