Search in sources :

Example 1 with GetLocalDocumentOptions

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));
}
Also used : GetLocalDocumentOptions(com.ibm.cloud.cloudant.v1.model.GetLocalDocumentOptions) Test(org.testng.annotations.Test)

Example 2 with GetLocalDocumentOptions

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetLocalDocumentOptions(com.ibm.cloud.cloudant.v1.model.GetLocalDocumentOptions) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) DesignDocument(com.ibm.cloud.cloudant.v1.model.DesignDocument) Document(com.ibm.cloud.cloudant.v1.model.Document) SchedulerDocument(com.ibm.cloud.cloudant.v1.model.SchedulerDocument) BulkGetResultDocument(com.ibm.cloud.cloudant.v1.model.BulkGetResultDocument) BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with GetLocalDocumentOptions

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) DesignDocument(com.ibm.cloud.cloudant.v1.model.DesignDocument) Document(com.ibm.cloud.cloudant.v1.model.Document) SchedulerDocument(com.ibm.cloud.cloudant.v1.model.SchedulerDocument)

Aggregations

DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)2 Document (com.ibm.cloud.cloudant.v1.model.Document)2 GetLocalDocumentOptions (com.ibm.cloud.cloudant.v1.model.GetLocalDocumentOptions)2 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)2 SchedulerDocument (com.ibm.cloud.cloudant.v1.model.SchedulerDocument)2 Test (org.testng.annotations.Test)2 BulkGetQueryDocument (com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument)1 BulkGetResultDocument (com.ibm.cloud.cloudant.v1.model.BulkGetResultDocument)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1