Search in sources :

Example 1 with PostActivityTrackerEventsOptions

use of com.ibm.cloud.cloudant.v1.model.PostActivityTrackerEventsOptions 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 PostActivityTrackerEventsOptions

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

the class CloudantTest method testPostActivityTrackerEventsWOptions.

@Test
public void testPostActivityTrackerEventsWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"ok\": true}";
    String postActivityTrackerEventsPath = "/_api/v2/user/activity_tracker/events";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PostActivityTrackerEventsOptions model
    PostActivityTrackerEventsOptions postActivityTrackerEventsOptionsModel = new PostActivityTrackerEventsOptions.Builder().types(new java.util.ArrayList<String>(java.util.Arrays.asList("management"))).build();
    // Invoke operation with valid options model (positive test)
    Response<Ok> response = cloudantService.postActivityTrackerEvents(postActivityTrackerEventsOptionsModel).execute();
    assertNotNull(response);
    Ok responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postActivityTrackerEventsPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ArrayList(java.util.ArrayList) Ok(com.ibm.cloud.cloudant.v1.model.Ok) PostActivityTrackerEventsOptions(com.ibm.cloud.cloudant.v1.model.PostActivityTrackerEventsOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with PostActivityTrackerEventsOptions

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

the class PostActivityTrackerEventsOptionsTest method testPostActivityTrackerEventsOptions.

@Test
public void testPostActivityTrackerEventsOptions() throws Throwable {
    PostActivityTrackerEventsOptions postActivityTrackerEventsOptionsModel = new PostActivityTrackerEventsOptions.Builder().types(new java.util.ArrayList<String>(java.util.Arrays.asList("management"))).build();
    assertEquals(postActivityTrackerEventsOptionsModel.types(), new java.util.ArrayList<String>(java.util.Arrays.asList("management")));
}
Also used : ArrayList(java.util.ArrayList) PostActivityTrackerEventsOptions(com.ibm.cloud.cloudant.v1.model.PostActivityTrackerEventsOptions) Test(org.testng.annotations.Test)

Aggregations

Ok (com.ibm.cloud.cloudant.v1.model.Ok)2 PostActivityTrackerEventsOptions (com.ibm.cloud.cloudant.v1.model.PostActivityTrackerEventsOptions)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1