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));
}
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));
}
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));
}
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);
}
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);
}
Aggregations