Search in sources :

Example 6 with SecurityObject

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

the class CloudantTest method testPutCloudantSecurityConfigurationWOptions.

@Test
public void testPutCloudantSecurityConfigurationWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"ok\": true}";
    String putCloudantSecurityConfigurationPath = "/_api/v2/db/testString/_security";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the SecurityObject model
    SecurityObject securityObjectModel = new SecurityObject.Builder().names(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).roles(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the PutCloudantSecurityConfigurationOptions model
    PutCloudantSecurityConfigurationOptions putCloudantSecurityConfigurationOptionsModel = new PutCloudantSecurityConfigurationOptions.Builder().db("testString").cloudant(new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
        }
    }).admins(securityObjectModel).members(securityObjectModel).couchdbAuthOnly(true).build();
    // Invoke operation with valid options model (positive test)
    Response<Ok> response = cloudantService.putCloudantSecurityConfiguration(putCloudantSecurityConfigurationOptionsModel).execute();
    assertNotNull(response);
    Ok responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PUT");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, putCloudantSecurityConfigurationPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) SecurityObject(com.ibm.cloud.cloudant.v1.model.SecurityObject) ArrayList(java.util.ArrayList) PutCloudantSecurityConfigurationOptions(com.ibm.cloud.cloudant.v1.model.PutCloudantSecurityConfigurationOptions) ArrayList(java.util.ArrayList) List(java.util.List) Ok(com.ibm.cloud.cloudant.v1.model.Ok) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SecurityObject (com.ibm.cloud.cloudant.v1.model.SecurityObject)6 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 List (java.util.List)5 Ok (com.ibm.cloud.cloudant.v1.model.Ok)2 PutCloudantSecurityConfigurationOptions (com.ibm.cloud.cloudant.v1.model.PutCloudantSecurityConfigurationOptions)2 PutSecurityOptions (com.ibm.cloud.cloudant.v1.model.PutSecurityOptions)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Security (com.ibm.cloud.cloudant.v1.model.Security)1