Search in sources :

Example 46 with Ok

use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.

the class CloudantTest method testGetGeoWOptions.

@Test
public void testGetGeoWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"bookmark\": \"bookmark\", \"features\": [{\"_id\": \"id\", \"_rev\": \"rev\", \"bbox\": [4], \"geometry\": {\"type\": \"Point\", \"coordinates\": [\"anyValue\"]}, \"properties\": {\"mapKey\": \"anyValue\"}, \"type\": \"Feature\"}], \"rows\": [{\"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\"}]}, \"geometry\": {\"type\": \"Point\", \"coordinates\": [\"anyValue\"]}, \"id\": \"id\", \"rev\": \"rev\"}], \"type\": \"FeatureCollection\"}";
    String getGeoPath = "/testString/_design/testString/_geo/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetGeoOptions model
    GetGeoOptions getGeoOptionsModel = new GetGeoOptions.Builder().db("testString").ddoc("testString").index("testString").bbox("testString").bookmark("testString").format("view").g("testString").includeDocs(false).lat(Double.valueOf("-90")).limit(Long.valueOf("0")).lon(Double.valueOf("-180")).nearest(false).radius(Double.valueOf("0")).rangex(Double.valueOf("0")).rangey(Double.valueOf("0")).relation("intersects").skip(Long.valueOf("0")).stale("ok").build();
    // Invoke operation with valid options model (positive test)
    Response<GeoResult> response = cloudantService.getGeo(getGeoOptionsModel).execute();
    assertNotNull(response);
    GeoResult 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(query.get("bbox"), "testString");
    assertEquals(query.get("bookmark"), "testString");
    assertEquals(query.get("format"), "view");
    assertEquals(query.get("g"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_docs")), Boolean.valueOf(false));
    assertEquals(Double.valueOf(query.get("lat")), Double.valueOf("-90"));
    assertEquals(Long.valueOf(query.get("limit")), Long.valueOf("0"));
    assertEquals(Double.valueOf(query.get("lon")), Double.valueOf("-180"));
    assertEquals(Boolean.valueOf(query.get("nearest")), Boolean.valueOf(false));
    assertEquals(Double.valueOf(query.get("radius")), Double.valueOf("0"));
    assertEquals(Double.valueOf(query.get("rangex")), Double.valueOf("0"));
    assertEquals(Double.valueOf(query.get("rangey")), Double.valueOf("0"));
    assertEquals(query.get("relation"), "intersects");
    assertEquals(Long.valueOf(query.get("skip")), Long.valueOf("0"));
    assertEquals(query.get("stale"), "ok");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getGeoPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GeoResult(com.ibm.cloud.cloudant.v1.model.GeoResult) GetGeoOptions(com.ibm.cloud.cloudant.v1.model.GetGeoOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 47 with Ok

use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.

the class Cloudant method putSecurity.

/**
 * Modify database permissions.
 *
 * Modify who has permission to read, write, or manage a database. This endpoint can be used to modify both Cloudant
 * and CouchDB related permissions. Be careful: by removing a Cloudant API key, a member or an admin from the list of
 * users that have access permissions, you remove it from the list of users that have access to the database.
 *
 * ### Note about nobody role
 *
 * The `nobody` username applies to all unauthenticated connection attempts. For example, if an application tries to
 * read data from a database, but did not identify itself, the task can continue only if the `nobody` user has the
 * role `_reader`.
 *
 * @param putSecurityOptions the {@link PutSecurityOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> putSecurity(PutSecurityOptions putSecurityOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putSecurityOptions, "putSecurityOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", putSecurityOptions.db());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_security", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putSecurity");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (putSecurityOptions.admins() != null) {
        contentJson.add("admins", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putSecurityOptions.admins()));
    }
    if (putSecurityOptions.members() != null) {
        contentJson.add("members", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putSecurityOptions.members()));
    }
    if (putSecurityOptions.cloudant() != null) {
        contentJson.add("cloudant", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putSecurityOptions.cloudant()));
    }
    if (putSecurityOptions.couchdbAuthOnly() != null) {
        contentJson.addProperty("couchdb_auth_only", putSecurityOptions.couchdbAuthOnly());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 48 with Ok

use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.

the class Cloudant method putCloudantSecurityConfiguration.

/**
 * Modify only Cloudant related database permissions.
 *
 * Modify only Cloudant related permissions to database. Be careful: by removing an API key from the list, you remove
 * the API key from the list of users that have access to the database.
 *
 * ### Note about nobody role
 *
 * The `nobody` username applies to all unauthenticated connection attempts. For example, if an application tries to
 * read data from a database, but did not identify itself, the task can continue only if the `nobody` user has the
 * role `_reader`.
 *
 * @param putCloudantSecurityConfigurationOptions the {@link PutCloudantSecurityConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> putCloudantSecurityConfiguration(PutCloudantSecurityConfigurationOptions putCloudantSecurityConfigurationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putCloudantSecurityConfigurationOptions, "putCloudantSecurityConfigurationOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", putCloudantSecurityConfigurationOptions.db());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/db/{db}/_security", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putCloudantSecurityConfiguration");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.add("cloudant", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCloudantSecurityConfigurationOptions.cloudant()));
    if (putCloudantSecurityConfigurationOptions.admins() != null) {
        contentJson.add("admins", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCloudantSecurityConfigurationOptions.admins()));
    }
    if (putCloudantSecurityConfigurationOptions.members() != null) {
        contentJson.add("members", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCloudantSecurityConfigurationOptions.members()));
    }
    if (putCloudantSecurityConfigurationOptions.couchdbAuthOnly() != null) {
        contentJson.addProperty("couchdb_auth_only", putCloudantSecurityConfigurationOptions.couchdbAuthOnly());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 49 with Ok

use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.

the class Cloudant method postGeoCleanup.

/**
 * Cleanup old geospatial indexes.
 *
 * Cleanup old geospatial indexes from disk that have been superseded by newer index builds.
 *
 * @param postGeoCleanupOptions the {@link PostGeoCleanupOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> postGeoCleanup(PostGeoCleanupOptions postGeoCleanupOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postGeoCleanupOptions, "postGeoCleanupOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postGeoCleanupOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_geo_cleanup", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postGeoCleanup");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 50 with Ok

use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.

the class Cloudant method deleteDatabase.

/**
 * Delete a database.
 *
 * Deletes the specified database and all documents and attachments contained within it. To avoid deleting a database,
 * the server responds with a 400 HTTP status code when the request URL includes a `?rev=` parameter. This response
 * suggests that a user wanted to delete a document but forgot to add the document ID to the URL.
 *
 * @param deleteDatabaseOptions the {@link DeleteDatabaseOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> deleteDatabase(DeleteDatabaseOptions deleteDatabaseOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDatabaseOptions, "deleteDatabaseOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", deleteDatabaseOptions.db());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDatabase");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Aggregations

Test (org.testng.annotations.Test)43 MockResponse (okhttp3.mockwebserver.MockResponse)29 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 ArrayList (java.util.ArrayList)19 Ok (com.ibm.cloud.cloudant.v1.model.Ok)18 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)13 HashMap (java.util.HashMap)13 Attachment (com.ibm.cloud.cloudant.v1.model.Attachment)11 DocumentRevisionStatus (com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus)11 Revisions (com.ibm.cloud.cloudant.v1.model.Revisions)11 Document (com.ibm.cloud.cloudant.v1.model.Document)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)8 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)6 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)6 BulkGetQueryDocument (com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument)5 JsonObject (com.google.gson.JsonObject)4 BulkGetResultDocument (com.ibm.cloud.cloudant.v1.model.BulkGetResultDocument)4 SchedulerDocument (com.ibm.cloud.cloudant.v1.model.SchedulerDocument)4 List (java.util.List)4