Search in sources :

Example 1 with DeleteDatabaseOptions

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

the class CloudantTest method testDeleteDatabaseWOptions.

@Test
public void testDeleteDatabaseWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"ok\": true}";
    String deleteDatabasePath = "/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the DeleteDatabaseOptions model
    DeleteDatabaseOptions deleteDatabaseOptionsModel = new DeleteDatabaseOptions.Builder().db("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Ok> response = cloudantService.deleteDatabase(deleteDatabaseOptionsModel).execute();
    assertNotNull(response);
    Ok responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "DELETE");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteDatabasePath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteDatabaseOptions(com.ibm.cloud.cloudant.v1.model.DeleteDatabaseOptions) Ok(com.ibm.cloud.cloudant.v1.model.Ok) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with DeleteDatabaseOptions

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

the class Cloudant method deleteDatabase.

/**
 * Delete a database.
 *
 * Deletes the specified database and all documents and attachments contained within it. To avoid deleting a database,
 * the server responds with a 400 HTTP status code when the request URL includes a `?rev=` parameter. This response
 * suggests that a user wanted to delete a document but forgot to add the document ID to the URL.
 *
 * @param deleteDatabaseOptions the {@link DeleteDatabaseOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> deleteDatabase(DeleteDatabaseOptions deleteDatabaseOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDatabaseOptions, "deleteDatabaseOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", deleteDatabaseOptions.db());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDatabase");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 3 with DeleteDatabaseOptions

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

the class DeleteDatabaseOptionsTest method testDeleteDatabaseOptions.

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

Aggregations

DeleteDatabaseOptions (com.ibm.cloud.cloudant.v1.model.DeleteDatabaseOptions)2 Ok (com.ibm.cloud.cloudant.v1.model.Ok)2 Test (org.testng.annotations.Test)2 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