use of com.ibm.cloud.cloudant.v1.Cloudant 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.Cloudant 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);
}
use of com.ibm.cloud.cloudant.v1.Cloudant 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);
}
use of com.ibm.cloud.cloudant.v1.Cloudant 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);
}
use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.
the class Cloudant method postDesignDocs.
/**
* Query a list of all design documents in a database.
*
* Queries the index of all design document IDs. The results matching the request body parameters are returned in a
* JSON object, including a list of matching design documents with basic contents, such as the ID and revision. When
* no request body parameters are specified, results for all design documents in the database are returned.
* Optionally, the design document content or additional metadata can be included in the response.
*
* @param postDesignDocsOptions the {@link PostDesignDocsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link AllDocsResult}
*/
public ServiceCall<AllDocsResult> postDesignDocs(PostDesignDocsOptions postDesignDocsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postDesignDocsOptions, "postDesignDocsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postDesignDocsOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design_docs", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postDesignDocs");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
if (postDesignDocsOptions.accept() != null) {
builder.header("Accept", postDesignDocsOptions.accept());
}
final JsonObject contentJson = new JsonObject();
if (postDesignDocsOptions.attEncodingInfo() != null) {
contentJson.addProperty("att_encoding_info", postDesignDocsOptions.attEncodingInfo());
}
if (postDesignDocsOptions.attachments() != null) {
contentJson.addProperty("attachments", postDesignDocsOptions.attachments());
}
if (postDesignDocsOptions.conflicts() != null) {
contentJson.addProperty("conflicts", postDesignDocsOptions.conflicts());
}
if (postDesignDocsOptions.descending() != null) {
contentJson.addProperty("descending", postDesignDocsOptions.descending());
}
if (postDesignDocsOptions.includeDocs() != null) {
contentJson.addProperty("include_docs", postDesignDocsOptions.includeDocs());
}
if (postDesignDocsOptions.inclusiveEnd() != null) {
contentJson.addProperty("inclusive_end", postDesignDocsOptions.inclusiveEnd());
}
if (postDesignDocsOptions.limit() != null) {
contentJson.addProperty("limit", postDesignDocsOptions.limit());
}
if (postDesignDocsOptions.skip() != null) {
contentJson.addProperty("skip", postDesignDocsOptions.skip());
}
if (postDesignDocsOptions.updateSeq() != null) {
contentJson.addProperty("update_seq", postDesignDocsOptions.updateSeq());
}
if (postDesignDocsOptions.endkey() != null) {
contentJson.addProperty("endkey", postDesignDocsOptions.endkey());
}
if (postDesignDocsOptions.key() != null) {
contentJson.addProperty("key", postDesignDocsOptions.key());
}
if (postDesignDocsOptions.keys() != null) {
contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postDesignDocsOptions.keys()));
}
if (postDesignDocsOptions.startkey() != null) {
contentJson.addProperty("startkey", postDesignDocsOptions.startkey());
}
builder.bodyJson(contentJson);
ResponseConverter<AllDocsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations