Search in sources :

Example 1 with GetSecurityOptions

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Security(com.ibm.cloud.cloudant.v1.model.Security)

Example 2 with GetSecurityOptions

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");
}
Also used : GetSecurityOptions(com.ibm.cloud.cloudant.v1.model.GetSecurityOptions) Test(org.testng.annotations.Test)

Example 3 with GetSecurityOptions

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetSecurityOptions(com.ibm.cloud.cloudant.v1.model.GetSecurityOptions) Security(com.ibm.cloud.cloudant.v1.model.Security) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

GetSecurityOptions (com.ibm.cloud.cloudant.v1.model.GetSecurityOptions)2 Security (com.ibm.cloud.cloudant.v1.model.Security)2 Test (org.testng.annotations.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1