Search in sources :

Example 1 with GetDatabaseInformationOptions

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

the class GetInfoFromExistingDatabase method main.

public static void main(String[] args) {
    // 1. Create a Cloudant client with "EXAMPLES" service name ===========
    Cloudant client = Cloudant.newInstance("EXAMPLES");
    // 2. Get server information ==========================================
    ServerInformation serverInformation = client.getServerInformation().execute().getResult();
    System.out.println("Server Version: " + serverInformation.getVersion());
    // 3. Get database information for "animaldb" =========================
    String dbName = "animaldb";
    GetDatabaseInformationOptions dbInformationOptions = new GetDatabaseInformationOptions.Builder(dbName).build();
    DatabaseInformation dbInformationResponse = client.getDatabaseInformation(dbInformationOptions).execute().getResult();
    // 4. Show document count in database =================================
    Long documentCount = dbInformationResponse.getDocCount();
    System.out.println("Document count in \"" + dbInformationResponse.getDbName() + "\" database is " + documentCount + ".");
    // 5. Get zebra document out of the database by document id ===========
    GetDocumentOptions getDocOptions = new GetDocumentOptions.Builder().db(dbName).docId("zebra").build();
    Document documentAboutZebra = client.getDocument(getDocOptions).execute().getResult();
    System.out.println("Document retrieved from database:\n" + documentAboutZebra);
}
Also used : DatabaseInformation(com.ibm.cloud.cloudant.v1.model.DatabaseInformation) ServerInformation(com.ibm.cloud.cloudant.v1.model.ServerInformation) GetDatabaseInformationOptions(com.ibm.cloud.cloudant.v1.model.GetDatabaseInformationOptions) GetDocumentOptions(com.ibm.cloud.cloudant.v1.model.GetDocumentOptions) Cloudant(com.ibm.cloud.cloudant.v1.Cloudant) Document(com.ibm.cloud.cloudant.v1.model.Document)

Example 2 with GetDatabaseInformationOptions

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

the class GetDatabaseInformationOptionsTest method testGetDatabaseInformationOptions.

@Test
public void testGetDatabaseInformationOptions() throws Throwable {
    GetDatabaseInformationOptions getDatabaseInformationOptionsModel = new GetDatabaseInformationOptions.Builder().db("testString").build();
    assertEquals(getDatabaseInformationOptionsModel.db(), "testString");
}
Also used : GetDatabaseInformationOptions(com.ibm.cloud.cloudant.v1.model.GetDatabaseInformationOptions) Test(org.testng.annotations.Test)

Example 3 with GetDatabaseInformationOptions

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

the class CloudantTest method testGetDatabaseInformationWOptions.

@Test
public void testGetDatabaseInformationWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"cluster\": {\"n\": 1, \"q\": 1, \"r\": 1, \"w\": 1}, \"committed_update_seq\": \"committedUpdateSeq\", \"compact_running\": true, \"compacted_seq\": \"compactedSeq\", \"db_name\": \"dbName\", \"disk_format_version\": 17, \"doc_count\": 0, \"doc_del_count\": 0, \"engine\": \"engine\", \"props\": {\"partitioned\": false}, \"sizes\": {\"active\": 6, \"external\": 8, \"file\": 4}, \"update_seq\": \"updateSeq\", \"uuid\": \"uuid\"}";
    String getDatabaseInformationPath = "/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetDatabaseInformationOptions model
    GetDatabaseInformationOptions getDatabaseInformationOptionsModel = new GetDatabaseInformationOptions.Builder().db("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<DatabaseInformation> response = cloudantService.getDatabaseInformation(getDatabaseInformationOptionsModel).execute();
    assertNotNull(response);
    DatabaseInformation 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, getDatabaseInformationPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DatabaseInformation(com.ibm.cloud.cloudant.v1.model.DatabaseInformation) GetDatabaseInformationOptions(com.ibm.cloud.cloudant.v1.model.GetDatabaseInformationOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with GetDatabaseInformationOptions

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

the class Cloudant method getDatabaseInformation.

/**
 * Retrieve information about a database.
 *
 * @param getDatabaseInformationOptions the {@link GetDatabaseInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DatabaseInformation}
 */
public ServiceCall<DatabaseInformation> getDatabaseInformation(GetDatabaseInformationOptions getDatabaseInformationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getDatabaseInformationOptions, "getDatabaseInformationOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", getDatabaseInformationOptions.db());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDatabaseInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<DatabaseInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DatabaseInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : DatabaseInformation(com.ibm.cloud.cloudant.v1.model.DatabaseInformation) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Aggregations

DatabaseInformation (com.ibm.cloud.cloudant.v1.model.DatabaseInformation)3 GetDatabaseInformationOptions (com.ibm.cloud.cloudant.v1.model.GetDatabaseInformationOptions)3 Test (org.testng.annotations.Test)2 Cloudant (com.ibm.cloud.cloudant.v1.Cloudant)1 Document (com.ibm.cloud.cloudant.v1.model.Document)1 GetDocumentOptions (com.ibm.cloud.cloudant.v1.model.GetDocumentOptions)1 ServerInformation (com.ibm.cloud.cloudant.v1.model.ServerInformation)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1