Search in sources :

Example 46 with Cloudant

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));
}
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 47 with Cloudant

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

Example 48 with Cloudant

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

Example 49 with Cloudant

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

Example 50 with Cloudant

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

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)70 HashMap (java.util.HashMap)51 JsonObject (com.google.gson.JsonObject)23 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)17 Ok (com.ibm.cloud.cloudant.v1.model.Ok)11 Document (com.ibm.cloud.cloudant.v1.model.Document)9 List (java.util.List)8 AllDocsResult (com.ibm.cloud.cloudant.v1.model.AllDocsResult)6 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)6 ArrayList (java.util.ArrayList)6 Cloudant (com.ibm.cloud.cloudant.v1.Cloudant)5 SecurityObject (com.ibm.cloud.cloudant.v1.model.SecurityObject)5 Test (org.testng.annotations.Test)5 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)3 GetDocumentOptions (com.ibm.cloud.cloudant.v1.model.GetDocumentOptions)3 PostAllDocsOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions)3 PostDocumentOptions (com.ibm.cloud.cloudant.v1.model.PostDocumentOptions)3 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3