Search in sources :

Example 21 with Response

use of com.cloudant.client.api.model.Response in project java-cloudant by cloudant.

the class DesignDocumentsTest method designDocRemoveNoPrefixWithRevision.

/**
 * Validate that a design document can be retrieved without using the "_design" prefix when a
 * revision is supplied
 *
 * @throws Exception
 */
@Test
public void designDocRemoveNoPrefixWithRevision() throws Exception {
    // Write a doc with a _design prefix
    Response r = designManager.put(designDocExample);
    // Retrieve it without a prefix
    Utils.assertOKResponse(designManager.remove("example", r.getRev()));
}
Also used : Response(com.cloudant.client.api.model.Response) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.jupiter.api.Test)

Example 22 with Response

use of com.cloudant.client.api.model.Response in project java-cloudant by cloudant.

the class DesignDocumentsTest method designDocGetNoPrefixWithRevision.

/**
 * Validate that a design document can be retrieved without using the "_design" prefix when a
 * revision is supplied
 *
 * @throws Exception
 */
@Test
public void designDocGetNoPrefixWithRevision() throws Exception {
    // Write a doc with a _design prefix
    Response r = designManager.put(designDocExample);
    // Retrieve it without a prefix
    assertNotNull(designManager.get("example", r.getRev()), "The design doc should be " + "retrieved without a _design prefix");
}
Also used : Response(com.cloudant.client.api.model.Response) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.jupiter.api.Test)

Example 23 with Response

use of com.cloudant.client.api.model.Response in project java-cloudant by cloudant.

the class Utils method removeReplicatorTestDoc.

public static void removeReplicatorTestDoc(CloudantClient account, String replicatorDocId) throws Exception {
    // Grab replicator doc revision using HTTP HEAD command
    String replicatorDb = "_replicator";
    URI uri = new URIBase(account.getBaseUri()).path(replicatorDb).path(replicatorDocId).build();
    HttpConnection head = Http.HEAD(uri);
    // add a response interceptor to allow us to retrieve the ETag revision header
    final AtomicReference<String> revisionRef = new AtomicReference<String>();
    head.responseInterceptors.add(new HttpConnectionResponseInterceptor() {

        @Override
        public HttpConnectionInterceptorContext interceptResponse(HttpConnectionInterceptorContext context) {
            revisionRef.set(context.connection.getConnection().getHeaderField("ETag"));
            return context;
        }
    });
    account.executeRequest(head);
    String revision = revisionRef.get();
    assertNotNull("The revision should not be null", revision);
    Database replicator = account.database(replicatorDb, false);
    Response removeResponse = replicator.remove(replicatorDocId, revision.replaceAll("\"", ""));
    assertThat(removeResponse.getError(), is(nullValue()));
}
Also used : Response(com.cloudant.client.api.model.Response) HttpConnection(com.cloudant.http.HttpConnection) Database(com.cloudant.client.api.Database) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpConnectionResponseInterceptor(com.cloudant.http.HttpConnectionResponseInterceptor) HttpConnectionInterceptorContext(com.cloudant.http.HttpConnectionInterceptorContext) URI(java.net.URI) URIBase(com.cloudant.client.internal.URIBase)

Example 24 with Response

use of com.cloudant.client.api.model.Response in project java-cloudant by cloudant.

the class DocumentsCRUDTest method findByIdAndRev.

@Test
public void findByIdAndRev() {
    Response response = db.save(new Foo());
    Foo foo = db.find(Foo.class, response.getId(), response.getRev());
    assertNotNull(foo);
}
Also used : Response(com.cloudant.client.api.model.Response) Test(org.junit.jupiter.api.Test)

Example 25 with Response

use of com.cloudant.client.api.model.Response in project java-cloudant by cloudant.

the class DocumentsCRUDTest method deleteByIdAndRevValues.

@Test
public void deleteByIdAndRevValues() {
    Response response = db.save(new Foo());
    db.remove(response.getId(), response.getRev());
}
Also used : Response(com.cloudant.client.api.model.Response) Test(org.junit.jupiter.api.Test)

Aggregations

Response (com.cloudant.client.api.model.Response)41 Test (org.junit.jupiter.api.Test)40 InputStream (java.io.InputStream)7 MockResponse (okhttp3.mockwebserver.MockResponse)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Document (com.cloudant.client.api.model.Document)5 Params (com.cloudant.client.api.model.Params)5 DesignDocument (com.cloudant.client.api.model.DesignDocument)4 JsonObject (com.google.gson.JsonObject)4 ReplicatorDocument (com.cloudant.client.api.model.ReplicatorDocument)3 Attachment (com.cloudant.client.api.model.Attachment)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Changes (com.cloudant.client.api.Changes)1 Database (com.cloudant.client.api.Database)1 ChangesResult (com.cloudant.client.api.model.ChangesResult)1 Row (com.cloudant.client.api.model.ChangesResult.Row)1 DbInfo (com.cloudant.client.api.model.DbInfo)1 URIBase (com.cloudant.client.internal.URIBase)1