use of com.ibm.cloud.cloudant.v1.model.PostDesignDocsOptions in project cloudant-java-sdk by IBM.
the class PostDesignDocsOptionsTest method testPostDesignDocsOptions.
@Test
public void testPostDesignDocsOptions() throws Throwable {
PostDesignDocsOptions postDesignDocsOptionsModel = new PostDesignDocsOptions.Builder().db("testString").accept("application/json").attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("0")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).startkey("testString").build();
assertEquals(postDesignDocsOptionsModel.db(), "testString");
assertEquals(postDesignDocsOptionsModel.accept(), "application/json");
assertEquals(postDesignDocsOptionsModel.attEncodingInfo(), Boolean.valueOf(false));
assertEquals(postDesignDocsOptionsModel.attachments(), Boolean.valueOf(false));
assertEquals(postDesignDocsOptionsModel.conflicts(), Boolean.valueOf(false));
assertEquals(postDesignDocsOptionsModel.descending(), Boolean.valueOf(false));
assertEquals(postDesignDocsOptionsModel.includeDocs(), Boolean.valueOf(false));
assertEquals(postDesignDocsOptionsModel.inclusiveEnd(), Boolean.valueOf(true));
assertEquals(postDesignDocsOptionsModel.limit(), Long.valueOf("0"));
assertEquals(postDesignDocsOptionsModel.skip(), Long.valueOf("0"));
assertEquals(postDesignDocsOptionsModel.updateSeq(), Boolean.valueOf(false));
assertEquals(postDesignDocsOptionsModel.endkey(), "testString");
assertEquals(postDesignDocsOptionsModel.key(), "testString");
assertEquals(postDesignDocsOptionsModel.keys(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(postDesignDocsOptionsModel.startkey(), "testString");
}
use of com.ibm.cloud.cloudant.v1.model.PostDesignDocsOptions 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.PostDesignDocsOptions 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);
}
Aggregations