use of com.ibm.cloud.cloudant.v1.model.ApiKeysResult 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);
}
use of com.ibm.cloud.cloudant.v1.model.ApiKeysResult in project cloudant-java-sdk by IBM.
the class ApiKeysResultTest method testApiKeysResult.
@Test
public void testApiKeysResult() throws Throwable {
ApiKeysResult apiKeysResultModel = new ApiKeysResult();
assertNull(apiKeysResultModel.isOk());
assertNull(apiKeysResultModel.getKey());
assertNull(apiKeysResultModel.getPassword());
}
use of com.ibm.cloud.cloudant.v1.model.ApiKeysResult 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);
}
Aggregations