use of com.ibm.cloud.cloudant.v1.model.GetDesignDocumentOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetDesignDocumentWOptions.
@Test
public void testGetDesignDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"_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\"}], \"autoupdate\": true, \"filters\": {\"mapKey\": \"inner\"}, \"indexes\": {\"mapKey\": {\"analyzer\": {\"name\": \"classic\", \"stopwords\": [\"stopwords\"], \"fields\": {\"mapKey\": {\"name\": \"classic\", \"stopwords\": [\"stopwords\"]}}}, \"index\": \"index\"}}, \"language\": \"javascript\", \"options\": {\"partitioned\": false}, \"validate_doc_update\": \"validateDocUpdate\", \"views\": {\"mapKey\": {\"map\": \"map\", \"reduce\": \"reduce\"}}, \"st_indexes\": {\"mapKey\": {\"index\": \"index\"}}}";
String getDesignDocumentPath = "/testString/_design/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetDesignDocumentOptions model
GetDesignDocumentOptions getDesignDocumentOptionsModel = new GetDesignDocumentOptions.Builder().db("testString").ddoc("testString").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).conflicts(false).deletedConflicts(false).latest(false).localSeq(false).meta(false).rev("testString").revs(false).revsInfo(false).build();
// Invoke operation with valid options model (positive test)
Response<DesignDocument> response = cloudantService.getDesignDocument(getDesignDocumentOptionsModel).execute();
assertNotNull(response);
DesignDocument 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(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("deleted_conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("local_seq")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("meta")), Boolean.valueOf(false));
assertEquals(query.get("rev"), "testString");
assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("revs_info")), Boolean.valueOf(false));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getDesignDocumentPath);
}
use of com.ibm.cloud.cloudant.v1.model.GetDesignDocumentOptions in project cloudant-java-sdk by IBM.
the class Cloudant method getDesignDocument.
/**
* Retrieve a design document.
*
* Returns design document with the specified `doc_id` from the specified database. Unless you request a specific
* revision, the current revision of the design document is always returned.
*
* @param getDesignDocumentOptions the {@link GetDesignDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DesignDocument}
*/
public ServiceCall<DesignDocument> getDesignDocument(GetDesignDocumentOptions getDesignDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getDesignDocumentOptions, "getDesignDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", getDesignDocumentOptions.db());
pathParamsMap.put("ddoc", getDesignDocumentOptions.ddoc());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDesignDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (getDesignDocumentOptions.ifNoneMatch() != null) {
builder.header("If-None-Match", getDesignDocumentOptions.ifNoneMatch());
}
if (getDesignDocumentOptions.attachments() != null) {
builder.query("attachments", String.valueOf(getDesignDocumentOptions.attachments()));
}
if (getDesignDocumentOptions.attEncodingInfo() != null) {
builder.query("att_encoding_info", String.valueOf(getDesignDocumentOptions.attEncodingInfo()));
}
if (getDesignDocumentOptions.conflicts() != null) {
builder.query("conflicts", String.valueOf(getDesignDocumentOptions.conflicts()));
}
if (getDesignDocumentOptions.deletedConflicts() != null) {
builder.query("deleted_conflicts", String.valueOf(getDesignDocumentOptions.deletedConflicts()));
}
if (getDesignDocumentOptions.latest() != null) {
builder.query("latest", String.valueOf(getDesignDocumentOptions.latest()));
}
if (getDesignDocumentOptions.localSeq() != null) {
builder.query("local_seq", String.valueOf(getDesignDocumentOptions.localSeq()));
}
if (getDesignDocumentOptions.meta() != null) {
builder.query("meta", String.valueOf(getDesignDocumentOptions.meta()));
}
if (getDesignDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(getDesignDocumentOptions.rev()));
}
if (getDesignDocumentOptions.revs() != null) {
builder.query("revs", String.valueOf(getDesignDocumentOptions.revs()));
}
if (getDesignDocumentOptions.revsInfo() != null) {
builder.query("revs_info", String.valueOf(getDesignDocumentOptions.revsInfo()));
}
ResponseConverter<DesignDocument> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DesignDocument>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.GetDesignDocumentOptions in project cloudant-java-sdk by IBM.
the class GetDesignDocumentOptionsTest method testGetDesignDocumentOptions.
@Test
public void testGetDesignDocumentOptions() throws Throwable {
GetDesignDocumentOptions getDesignDocumentOptionsModel = new GetDesignDocumentOptions.Builder().db("testString").ddoc("testString").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).conflicts(false).deletedConflicts(false).latest(false).localSeq(false).meta(false).rev("testString").revs(false).revsInfo(false).build();
assertEquals(getDesignDocumentOptionsModel.db(), "testString");
assertEquals(getDesignDocumentOptionsModel.ddoc(), "testString");
assertEquals(getDesignDocumentOptionsModel.ifNoneMatch(), "testString");
assertEquals(getDesignDocumentOptionsModel.attachments(), Boolean.valueOf(false));
assertEquals(getDesignDocumentOptionsModel.attEncodingInfo(), Boolean.valueOf(false));
assertEquals(getDesignDocumentOptionsModel.conflicts(), Boolean.valueOf(false));
assertEquals(getDesignDocumentOptionsModel.deletedConflicts(), Boolean.valueOf(false));
assertEquals(getDesignDocumentOptionsModel.latest(), Boolean.valueOf(false));
assertEquals(getDesignDocumentOptionsModel.localSeq(), Boolean.valueOf(false));
assertEquals(getDesignDocumentOptionsModel.meta(), Boolean.valueOf(false));
assertEquals(getDesignDocumentOptionsModel.rev(), "testString");
assertEquals(getDesignDocumentOptionsModel.revs(), Boolean.valueOf(false));
assertEquals(getDesignDocumentOptionsModel.revsInfo(), Boolean.valueOf(false));
}
Aggregations