Search in sources :

Example 6 with Response

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

the class DocumentsCRUDTest method findById.

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

Example 7 with Response

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

the class ReplicatorTest method replication_filteredWithQueryParams.

@Test
public void replication_filteredWithQueryParams() throws Exception {
    Map<String, Object> queryParams = new HashMap<String, Object>();
    queryParams.put("somekey1", "value 1");
    Response response = account.replicator().createTarget(true).replicatorDocId(repDocId).source(db1URI).target(db2URI).filter("example/example_filter").queryParams(queryParams).save();
    // find and remove replicator doc
    ReplicatorDocument repDoc = Utils.waitForReplicatorToComplete(account, response.getId());
    assertTrue("completed".equalsIgnoreCase(repDoc.getReplicationState()), "The replicator " + "should reach completed state");
}
Also used : Response(com.cloudant.client.api.model.Response) HashMap(java.util.HashMap) ReplicatorDocument(com.cloudant.client.api.model.ReplicatorDocument) Test(org.junit.jupiter.api.Test)

Example 8 with Response

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

the class ReplicatorTest method replication.

@Test
public void replication() throws Exception {
    Response response = account.replicator().replicatorDocId(repDocId).createTarget(true).source(db1URI).target(db2URI).save();
    // find and remove replicator doc
    ReplicatorDocument repDoc = Utils.waitForReplicatorToComplete(account, response.getId());
    assertTrue("completed".equalsIgnoreCase(repDoc.getReplicationState()), "The replicator " + "should reach completed state");
}
Also used : Response(com.cloudant.client.api.model.Response) ReplicatorDocument(com.cloudant.client.api.model.ReplicatorDocument) Test(org.junit.jupiter.api.Test)

Example 9 with Response

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

the class ReplicatorTest method replication_conflict.

@Test
public void replication_conflict() throws Exception {
    String docId = Utils.generateUUID();
    Foo foodb1 = new Foo(docId, "titleX");
    Foo foodb2 = new Foo(docId, "titleY");
    // save Foo(X) in DB1
    db1.save(foodb1);
    // save Foo(Y) in DB2
    db2.save(foodb2);
    // replicate with DB1 with DB2
    Response response = account.replicator().source(db1URI).target(db2URI).replicatorDocId(repDocId).save();
    // we need the replication to finish before continuing
    Utils.waitForReplicatorToComplete(account, response.getId());
    // we replicated with a doc with the same ID but different content in each DB, we should get
    // a conflict
    assertConflictsNotZero(db2);
}
Also used : Response(com.cloudant.client.api.model.Response) Test(org.junit.jupiter.api.Test)

Example 10 with Response

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

the class ResponseTest method verifyBulkDocumentRequest.

@Test
public void verifyBulkDocumentRequest() {
    ArrayList<Foo> foos = new ArrayList<Foo>();
    foos.add(new Foo(Utils.generateUUID()));
    foos.add(new Foo(Utils.generateUUID()));
    foos.add(new Foo(Utils.generateUUID()));
    List<Response> responses = db.bulk(foos);
    for (Response response : responses) {
        assertEquals(2, response.getStatusCode() / 100);
    }
}
Also used : Response(com.cloudant.client.api.model.Response) ArrayList(java.util.ArrayList) 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