use of com.ibm.cloud.cloudant.v1.model.GetLocalDocumentOptions in project cloudant-java-sdk by IBM.
the class GetLocalDocumentOptionsTest method testGetLocalDocumentOptions.
@Test
public void testGetLocalDocumentOptions() throws Throwable {
GetLocalDocumentOptions getLocalDocumentOptionsModel = new GetLocalDocumentOptions.Builder().db("testString").docId("testString").accept("application/json").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).localSeq(false).build();
assertEquals(getLocalDocumentOptionsModel.db(), "testString");
assertEquals(getLocalDocumentOptionsModel.docId(), "testString");
assertEquals(getLocalDocumentOptionsModel.accept(), "application/json");
assertEquals(getLocalDocumentOptionsModel.ifNoneMatch(), "testString");
assertEquals(getLocalDocumentOptionsModel.attachments(), Boolean.valueOf(false));
assertEquals(getLocalDocumentOptionsModel.attEncodingInfo(), Boolean.valueOf(false));
assertEquals(getLocalDocumentOptionsModel.localSeq(), Boolean.valueOf(false));
}
use of com.ibm.cloud.cloudant.v1.model.GetLocalDocumentOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetLocalDocumentWOptions.
@Test
public void testGetLocalDocumentWOptions() 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\"}]}";
String getLocalDocumentPath = "/testString/_local/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetLocalDocumentOptions model
GetLocalDocumentOptions getLocalDocumentOptionsModel = new GetLocalDocumentOptions.Builder().db("testString").docId("testString").accept("application/json").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).localSeq(false).build();
// Invoke operation with valid options model (positive test)
Response<Document> response = cloudantService.getLocalDocument(getLocalDocumentOptionsModel).execute();
assertNotNull(response);
Document 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("local_seq")), Boolean.valueOf(false));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getLocalDocumentPath);
}
use of com.ibm.cloud.cloudant.v1.model.GetLocalDocumentOptions in project cloudant-java-sdk by IBM.
the class Cloudant method getLocalDocument.
/**
* Retrieve a local document.
*
* Retrieves the specified local document. The semantics are identical to accessing a standard document in the
* specified database, except that the document is not replicated.
*
* @param getLocalDocumentOptions the {@link GetLocalDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Document}
*/
public ServiceCall<Document> getLocalDocument(GetLocalDocumentOptions getLocalDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getLocalDocumentOptions, "getLocalDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", getLocalDocumentOptions.db());
pathParamsMap.put("doc_id", getLocalDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_local/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getLocalDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
if (getLocalDocumentOptions.accept() != null) {
builder.header("Accept", getLocalDocumentOptions.accept());
}
if (getLocalDocumentOptions.ifNoneMatch() != null) {
builder.header("If-None-Match", getLocalDocumentOptions.ifNoneMatch());
}
if (getLocalDocumentOptions.attachments() != null) {
builder.query("attachments", String.valueOf(getLocalDocumentOptions.attachments()));
}
if (getLocalDocumentOptions.attEncodingInfo() != null) {
builder.query("att_encoding_info", String.valueOf(getLocalDocumentOptions.attEncodingInfo()));
}
if (getLocalDocumentOptions.localSeq() != null) {
builder.query("local_seq", String.valueOf(getLocalDocumentOptions.localSeq()));
}
ResponseConverter<Document> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Document>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations