use of com.ibm.cloud.cloudant.v1.model.GetSecurityOptions in project cloudant-java-sdk by IBM.
the class Cloudant method getSecurity.
/**
* Retrieve database permissions information.
*
* See who has permission to read, write, and manage the database. The credentials you use to log in to the dashboard
* automatically include `_admin` permissions to all databases you create. Everyone and everything else, including
* users you share databases with and API keys you create, must be given a permission level explicitly.
*
* @param getSecurityOptions the {@link GetSecurityOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Security}
*/
public ServiceCall<Security> getSecurity(GetSecurityOptions getSecurityOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getSecurityOptions, "getSecurityOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", getSecurityOptions.db());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_security", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSecurity");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<Security> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Security>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.GetSecurityOptions in project cloudant-java-sdk by IBM.
the class GetSecurityOptionsTest method testGetSecurityOptions.
@Test
public void testGetSecurityOptions() throws Throwable {
GetSecurityOptions getSecurityOptionsModel = new GetSecurityOptions.Builder().db("testString").build();
assertEquals(getSecurityOptionsModel.db(), "testString");
}
use of com.ibm.cloud.cloudant.v1.model.GetSecurityOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetSecurityWOptions.
@Test
public void testGetSecurityWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"admins\": {\"names\": [\"names\"], \"roles\": [\"roles\"]}, \"members\": {\"names\": [\"names\"], \"roles\": [\"roles\"]}, \"cloudant\": {\"mapKey\": [\"_reader\"]}, \"couchdb_auth_only\": false}";
String getSecurityPath = "/testString/_security";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetSecurityOptions model
GetSecurityOptions getSecurityOptionsModel = new GetSecurityOptions.Builder().db("testString").build();
// Invoke operation with valid options model (positive test)
Response<Security> response = cloudantService.getSecurity(getSecurityOptionsModel).execute();
assertNotNull(response);
Security 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);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getSecurityPath);
}
Aggregations