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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations