Search in sources :

Example 1 with SecurityObject

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

the class SecurityTest method testSecurity.

@Test
public void testSecurity() throws Throwable {
    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();
    assertEquals(securityObjectModel.names(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(securityObjectModel.roles(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    Security securityModel = new Security.Builder().admins(securityObjectModel).members(securityObjectModel).cloudant(new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
        }
    }).couchdbAuthOnly(true).build();
    assertEquals(securityModel.admins(), securityObjectModel);
    assertEquals(securityModel.members(), securityObjectModel);
    assertEquals(securityModel.cloudant(), new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
        }
    });
    assertEquals(securityModel.couchdbAuthOnly(), Boolean.valueOf(true));
    String json = TestUtilities.serialize(securityModel);
    Security securityModelNew = TestUtilities.deserialize(json, Security.class);
    assertTrue(securityModelNew instanceof Security);
    assertEquals(securityModelNew.admins().toString(), securityObjectModel.toString());
    assertEquals(securityModelNew.members().toString(), securityObjectModel.toString());
    assertEquals(securityModelNew.couchdbAuthOnly(), Boolean.valueOf(true));
}
Also used : SecurityObject(com.ibm.cloud.cloudant.v1.model.SecurityObject) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Security(com.ibm.cloud.cloudant.v1.model.Security) Test(org.testng.annotations.Test)

Example 2 with SecurityObject

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

the class PutCloudantSecurityConfigurationOptionsTest method testPutCloudantSecurityConfigurationOptions.

@Test
public void testPutCloudantSecurityConfigurationOptions() throws Throwable {
    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();
    assertEquals(securityObjectModel.names(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(securityObjectModel.roles(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    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();
    assertEquals(putCloudantSecurityConfigurationOptionsModel.db(), "testString");
    assertEquals(putCloudantSecurityConfigurationOptionsModel.cloudant(), new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
        }
    });
    assertEquals(putCloudantSecurityConfigurationOptionsModel.admins(), securityObjectModel);
    assertEquals(putCloudantSecurityConfigurationOptionsModel.members(), securityObjectModel);
    assertEquals(putCloudantSecurityConfigurationOptionsModel.couchdbAuthOnly(), Boolean.valueOf(true));
}
Also used : PutCloudantSecurityConfigurationOptions(com.ibm.cloud.cloudant.v1.model.PutCloudantSecurityConfigurationOptions) SecurityObject(com.ibm.cloud.cloudant.v1.model.SecurityObject) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 3 with SecurityObject

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

the class PutSecurityOptionsTest method testPutSecurityOptions.

@Test
public void testPutSecurityOptions() throws Throwable {
    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();
    assertEquals(securityObjectModel.names(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(securityObjectModel.roles(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    PutSecurityOptions putSecurityOptionsModel = new PutSecurityOptions.Builder().db("testString").admins(securityObjectModel).members(securityObjectModel).cloudant(new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
        }
    }).couchdbAuthOnly(true).build();
    assertEquals(putSecurityOptionsModel.db(), "testString");
    assertEquals(putSecurityOptionsModel.admins(), securityObjectModel);
    assertEquals(putSecurityOptionsModel.members(), securityObjectModel);
    assertEquals(putSecurityOptionsModel.cloudant(), new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
        }
    });
    assertEquals(putSecurityOptionsModel.couchdbAuthOnly(), Boolean.valueOf(true));
}
Also used : SecurityObject(com.ibm.cloud.cloudant.v1.model.SecurityObject) PutSecurityOptions(com.ibm.cloud.cloudant.v1.model.PutSecurityOptions) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 4 with SecurityObject

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

the class SecurityObjectTest method testSecurityObject.

@Test
public void testSecurityObject() throws Throwable {
    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();
    assertEquals(securityObjectModel.names(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(securityObjectModel.roles(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    String json = TestUtilities.serialize(securityObjectModel);
    SecurityObject securityObjectModelNew = TestUtilities.deserialize(json, SecurityObject.class);
    assertTrue(securityObjectModelNew instanceof SecurityObject);
}
Also used : SecurityObject(com.ibm.cloud.cloudant.v1.model.SecurityObject) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 5 with SecurityObject

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

the class CloudantTest method testPutSecurityWOptions.

@Test
public void testPutSecurityWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"ok\": true}";
    String putSecurityPath = "/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 PutSecurityOptions model
    PutSecurityOptions putSecurityOptionsModel = new PutSecurityOptions.Builder().db("testString").admins(securityObjectModel).members(securityObjectModel).cloudant(new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
        }
    }).couchdbAuthOnly(true).build();
    // Invoke operation with valid options model (positive test)
    Response<Ok> response = cloudantService.putSecurity(putSecurityOptionsModel).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, putSecurityPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) SecurityObject(com.ibm.cloud.cloudant.v1.model.SecurityObject) ArrayList(java.util.ArrayList) PutSecurityOptions(com.ibm.cloud.cloudant.v1.model.PutSecurityOptions) 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