Search in sources :

Example 1 with PostApiKeysOptions

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

the class CloudantTest method testPostApiKeysWOptions.

@Test
public void testPostApiKeysWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"ok\": true, \"key\": \"key\", \"password\": \"password\"}";
    String postApiKeysPath = "/_api/v2/api_keys";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PostApiKeysOptions model
    PostApiKeysOptions postApiKeysOptionsModel = new PostApiKeysOptions();
    // Invoke operation with valid options model (positive test)
    Response<ApiKeysResult> response = cloudantService.postApiKeys(postApiKeysOptionsModel).execute();
    assertNotNull(response);
    ApiKeysResult 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, postApiKeysPath);
}
Also used : ApiKeysResult(com.ibm.cloud.cloudant.v1.model.ApiKeysResult) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) PostApiKeysOptions(com.ibm.cloud.cloudant.v1.model.PostApiKeysOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with PostApiKeysOptions

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

the class PostApiKeysOptionsTest method testPostApiKeysOptions.

@Test
public void testPostApiKeysOptions() throws Throwable {
    PostApiKeysOptions postApiKeysOptionsModel = new PostApiKeysOptions();
    assertNotNull(postApiKeysOptionsModel);
}
Also used : PostApiKeysOptions(com.ibm.cloud.cloudant.v1.model.PostApiKeysOptions) Test(org.testng.annotations.Test)

Example 3 with PostApiKeysOptions

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

the class Cloudant method postApiKeys.

/**
 * Generates API keys for apps or persons to enable database access.
 *
 * Generates API keys to enable database access for a person or application, but without creating a new IBM Cloudant
 * account for that person or application. An API key is a randomly generated username and password. The key is given
 * the wanted access permissions for a database.
 *
 * @param postApiKeysOptions the {@link PostApiKeysOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ApiKeysResult}
 */
public ServiceCall<ApiKeysResult> postApiKeys(PostApiKeysOptions postApiKeysOptions) {
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/api_keys"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postApiKeys");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<ApiKeysResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ApiKeysResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : ApiKeysResult(com.ibm.cloud.cloudant.v1.model.ApiKeysResult) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Aggregations

ApiKeysResult (com.ibm.cloud.cloudant.v1.model.ApiKeysResult)2 PostApiKeysOptions (com.ibm.cloud.cloudant.v1.model.PostApiKeysOptions)2 Test (org.testng.annotations.Test)2 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