Search in sources :

Example 1 with Ok

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

the class Cloudant method postActivityTrackerEvents.

/**
 * Modify Activity Tracker events configuration.
 *
 * Configure event types that are being sent to IBM Cloud Activity Tracker for the IBM Cloudant instance.
 *
 * @param postActivityTrackerEventsOptions the {@link PostActivityTrackerEventsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> postActivityTrackerEvents(PostActivityTrackerEventsOptions postActivityTrackerEventsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postActivityTrackerEventsOptions, "postActivityTrackerEventsOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/activity_tracker/events"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postActivityTrackerEvents");
    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("types", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postActivityTrackerEventsOptions.types()));
    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) JsonObject(com.google.gson.JsonObject) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 2 with Ok

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

the class Cloudant method deleteIndex.

/**
 * Delete an index.
 *
 * @param deleteIndexOptions the {@link DeleteIndexOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> deleteIndex(DeleteIndexOptions deleteIndexOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteIndexOptions, "deleteIndexOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", deleteIndexOptions.db());
    pathParamsMap.put("ddoc", deleteIndexOptions.ddoc());
    pathParamsMap.put("type", deleteIndexOptions.type());
    pathParamsMap.put("index", deleteIndexOptions.index());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_index/_design/{ddoc}/{type}/{index}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteIndex");
    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 3 with Ok

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

the class Cloudant method putDatabase.

/**
 * Create a database.
 *
 * @param putDatabaseOptions the {@link PutDatabaseOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> putDatabase(PutDatabaseOptions putDatabaseOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putDatabaseOptions, "putDatabaseOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", putDatabaseOptions.db());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putDatabase");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (putDatabaseOptions.partitioned() != null) {
        builder.query("partitioned", String.valueOf(putDatabaseOptions.partitioned()));
    }
    if (putDatabaseOptions.q() != null) {
        builder.query("q", String.valueOf(putDatabaseOptions.q()));
    }
    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 4 with Ok

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

the class Cloudant method putCorsConfiguration.

/**
 * Modify CORS configuration.
 *
 * Sets the CORS configuration. The configuration applies to all databases and all account level endpoints in your
 * account.
 *
 * @param putCorsConfigurationOptions the {@link PutCorsConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> putCorsConfiguration(PutCorsConfigurationOptions putCorsConfigurationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putCorsConfigurationOptions, "putCorsConfigurationOptions cannot be null");
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/config/cors"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putCorsConfiguration");
    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("origins", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCorsConfigurationOptions.origins()));
    if (putCorsConfigurationOptions.allowCredentials() != null) {
        contentJson.addProperty("allow_credentials", putCorsConfigurationOptions.allowCredentials());
    }
    if (putCorsConfigurationOptions.enableCors() != null) {
        contentJson.addProperty("enable_cors", putCorsConfigurationOptions.enableCors());
    }
    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) JsonObject(com.google.gson.JsonObject) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 5 with Ok

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

the class CloudantTest method testDeleteDesignDocumentWOptions.

@Test
public void testDeleteDesignDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
    String deleteDesignDocumentPath = "/testString/_design/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the DeleteDesignDocumentOptions model
    DeleteDesignDocumentOptions deleteDesignDocumentOptionsModel = new DeleteDesignDocumentOptions.Builder().db("testString").ddoc("testString").ifMatch("testString").batch("ok").rev("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<DocumentResult> response = cloudantService.deleteDesignDocument(deleteDesignDocumentOptionsModel).execute();
    assertNotNull(response);
    DocumentResult responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "DELETE");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("batch"), "ok");
    assertEquals(query.get("rev"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteDesignDocumentPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) DeleteDesignDocumentOptions(com.ibm.cloud.cloudant.v1.model.DeleteDesignDocumentOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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