use of com.ibm.cloud.cloudant.v1.model.AllDocsResult in project knative-eventing-java-app by IBM.
the class EventControllerEndpointTest method mockGetEvents.
public void mockGetEvents(@SuppressWarnings("rawtypes") final List<CloudEventImpl> docs) throws Exception {
Gson customGson = SBApplicationConfig.getCustomGsonBuilder().create();
List<DocsResultRow> docsResultRows = new ArrayList<>();
for (CloudEvent<?, ?> cloudEvent : docs) {
Document document = new Document();
document.setProperties(customGson.fromJson(customGson.toJson(cloudEvent), Map.class));
DocsResultRow docsResultRowMock = Mockito.mock(DocsResultRow.class);
Mockito.when(docsResultRowMock.getDoc()).thenReturn(document);
docsResultRows.add(docsResultRowMock);
}
long expectedNumEvents = docs.size();
@SuppressWarnings("unchecked") Response<AllDocsResult> responseMock = Mockito.mock(Response.class);
AllDocsResult allDocsResultMock = Mockito.mock(AllDocsResult.class);
Mockito.when(this.eventService.getNumEvents()).thenReturn(expectedNumEvents);
Mockito.when(responseMock.getResult()).thenReturn(allDocsResultMock);
Mockito.when(allDocsResultMock.getRows()).thenReturn(docsResultRows);
}
use of com.ibm.cloud.cloudant.v1.model.AllDocsResult in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostPartitionAllDocsWOptions.
@Test
public void testPostPartitionAllDocsWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"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 postPartitionAllDocsPath = "/testString/_partition/testString/_all_docs";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the PostPartitionAllDocsOptions model
PostPartitionAllDocsOptions postPartitionAllDocsOptionsModel = new PostPartitionAllDocsOptions.Builder().db("testString").partitionKey("testString").attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("10")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).startkey("0007741142412418284").build();
// Invoke operation with valid options model (positive test)
Response<AllDocsResult> response = cloudantService.postPartitionAllDocs(postPartitionAllDocsOptionsModel).execute();
assertNotNull(response);
AllDocsResult 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, postPartitionAllDocsPath);
}
use of com.ibm.cloud.cloudant.v1.model.AllDocsResult in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostDesignDocsWOptions.
@Test
public void testPostDesignDocsWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"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 postDesignDocsPath = "/testString/_design_docs";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the PostDesignDocsOptions model
PostDesignDocsOptions postDesignDocsOptionsModel = new PostDesignDocsOptions.Builder().db("testString").attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("10")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).startkey("0007741142412418284").accept("application/json").build();
// Invoke operation with valid options model (positive test)
Response<AllDocsResult> response = cloudantService.postDesignDocs(postDesignDocsOptionsModel).execute();
assertNotNull(response);
AllDocsResult 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, postDesignDocsPath);
}
use of com.ibm.cloud.cloudant.v1.model.AllDocsResult in project cloudant-java-sdk by IBM.
the class Cloudant method postDesignDocs.
/**
* Query a list of all design documents in a database.
*
* Queries the index of all design document IDs. The results matching the request body parameters are returned in a
* JSON object, including a list of matching design documents with basic contents, such as the ID and revision. When
* no request body parameters are specified, results for all design documents in the database are returned.
* Optionally, the design document content or additional metadata can be included in the response.
*
* @param postDesignDocsOptions the {@link PostDesignDocsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link AllDocsResult}
*/
public ServiceCall<AllDocsResult> postDesignDocs(PostDesignDocsOptions postDesignDocsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postDesignDocsOptions, "postDesignDocsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postDesignDocsOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design_docs", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postDesignDocs");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
if (postDesignDocsOptions.accept() != null) {
builder.header("Accept", postDesignDocsOptions.accept());
}
final JsonObject contentJson = new JsonObject();
if (postDesignDocsOptions.attEncodingInfo() != null) {
contentJson.addProperty("att_encoding_info", postDesignDocsOptions.attEncodingInfo());
}
if (postDesignDocsOptions.attachments() != null) {
contentJson.addProperty("attachments", postDesignDocsOptions.attachments());
}
if (postDesignDocsOptions.conflicts() != null) {
contentJson.addProperty("conflicts", postDesignDocsOptions.conflicts());
}
if (postDesignDocsOptions.descending() != null) {
contentJson.addProperty("descending", postDesignDocsOptions.descending());
}
if (postDesignDocsOptions.includeDocs() != null) {
contentJson.addProperty("include_docs", postDesignDocsOptions.includeDocs());
}
if (postDesignDocsOptions.inclusiveEnd() != null) {
contentJson.addProperty("inclusive_end", postDesignDocsOptions.inclusiveEnd());
}
if (postDesignDocsOptions.limit() != null) {
contentJson.addProperty("limit", postDesignDocsOptions.limit());
}
if (postDesignDocsOptions.skip() != null) {
contentJson.addProperty("skip", postDesignDocsOptions.skip());
}
if (postDesignDocsOptions.updateSeq() != null) {
contentJson.addProperty("update_seq", postDesignDocsOptions.updateSeq());
}
if (postDesignDocsOptions.endkey() != null) {
contentJson.addProperty("endkey", postDesignDocsOptions.endkey());
}
if (postDesignDocsOptions.key() != null) {
contentJson.addProperty("key", postDesignDocsOptions.key());
}
if (postDesignDocsOptions.keys() != null) {
contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postDesignDocsOptions.keys()));
}
if (postDesignDocsOptions.startkey() != null) {
contentJson.addProperty("startkey", postDesignDocsOptions.startkey());
}
builder.bodyJson(contentJson);
ResponseConverter<AllDocsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.AllDocsResult in project cloudant-java-sdk by IBM.
the class Cloudant method postAllDocs.
/**
* Query a list of all documents in a database.
*
* Queries the primary index (all document IDs). The results that match the request body parameters are returned in a
* JSON object, including a list of matching documents with basic contents, such as the ID and revision. When no
* request body parameters are specified, results for all documents in the database are returned. Optionally, document
* content or additional metadata can be included in the response.
*
* @param postAllDocsOptions the {@link PostAllDocsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link AllDocsResult}
*/
public ServiceCall<AllDocsResult> postAllDocs(PostAllDocsOptions postAllDocsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postAllDocsOptions, "postAllDocsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postAllDocsOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_all_docs", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postAllDocs");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
if (postAllDocsOptions.attEncodingInfo() != null) {
contentJson.addProperty("att_encoding_info", postAllDocsOptions.attEncodingInfo());
}
if (postAllDocsOptions.attachments() != null) {
contentJson.addProperty("attachments", postAllDocsOptions.attachments());
}
if (postAllDocsOptions.conflicts() != null) {
contentJson.addProperty("conflicts", postAllDocsOptions.conflicts());
}
if (postAllDocsOptions.descending() != null) {
contentJson.addProperty("descending", postAllDocsOptions.descending());
}
if (postAllDocsOptions.includeDocs() != null) {
contentJson.addProperty("include_docs", postAllDocsOptions.includeDocs());
}
if (postAllDocsOptions.inclusiveEnd() != null) {
contentJson.addProperty("inclusive_end", postAllDocsOptions.inclusiveEnd());
}
if (postAllDocsOptions.limit() != null) {
contentJson.addProperty("limit", postAllDocsOptions.limit());
}
if (postAllDocsOptions.skip() != null) {
contentJson.addProperty("skip", postAllDocsOptions.skip());
}
if (postAllDocsOptions.updateSeq() != null) {
contentJson.addProperty("update_seq", postAllDocsOptions.updateSeq());
}
if (postAllDocsOptions.endkey() != null) {
contentJson.addProperty("endkey", postAllDocsOptions.endkey());
}
if (postAllDocsOptions.key() != null) {
contentJson.addProperty("key", postAllDocsOptions.key());
}
if (postAllDocsOptions.keys() != null) {
contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postAllDocsOptions.keys()));
}
if (postAllDocsOptions.startkey() != null) {
contentJson.addProperty("startkey", postAllDocsOptions.startkey());
}
builder.bodyJson(contentJson);
ResponseConverter<AllDocsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations