Search in sources :

Example 31 with Response

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

the class DocumentsCRUDTest method updateWithIdContainSlash.

@Test
public void updateWithIdContainSlash() {
    String idWithSlash = "a/" + generateUUID();
    Response response = db.save(new Bar(idWithSlash));
    Bar bar = db.find(Bar.class, response.getId());
    Response responseUpdate = db.update(bar);
    assertEquals(idWithSlash, responseUpdate.getId());
}
Also used : Response(com.cloudant.client.api.model.Response) Test(org.junit.jupiter.api.Test)

Example 32 with Response

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

the class ReplicatorTest method replicatorDB.

@Test
public void replicatorDB() throws Exception {
    // trigger a replication
    Response response = account.replicator().replicatorDocId(repDocId).source(db1URI).target(db2URI).continuous(true).createTarget(true).save();
    // we need the replication to start before continuing
    Utils.waitForReplicatorToStart(account, response.getId());
    // find all replicator docs
    List<ReplicatorDocument> replicatorDocs = account.replicator().findAll();
    assertThat(replicatorDocs.size(), is(not(0)));
}
Also used : Response(com.cloudant.client.api.model.Response) ReplicatorDocument(com.cloudant.client.api.model.ReplicatorDocument) Test(org.junit.jupiter.api.Test)

Example 33 with Response

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

the class ResponseTest method verifyDocumentSaved.

@Test
public void verifyDocumentSaved() {
    Response response = db.save(foo);
    assertEquals(2, response.getStatusCode() / 100);
}
Also used : Response(com.cloudant.client.api.model.Response) Test(org.junit.jupiter.api.Test)

Example 34 with Response

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

the class ResponseTest method verifyDocumentConflict.

@Test
public void verifyDocumentConflict() {
    try {
        Response response = db.save(foo);
        assertEquals(2, response.getStatusCode() / 100);
        db.save(foo);
        fail("A DocumentConflictException should be thrown");
    } catch (DocumentConflictException e) {
        exceptionAsserts(e, 409, "");
    }
}
Also used : Response(com.cloudant.client.api.model.Response) DocumentConflictException(com.cloudant.client.org.lightcouch.DocumentConflictException) Test(org.junit.jupiter.api.Test)

Example 35 with Response

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

the class AttachmentsTest method attachmentStandaloneNullIdNullRev.

@Test
public void attachmentStandaloneNullIdNullRev() throws IOException, URISyntaxException {
    byte[] bytesToDB = "binary data".getBytes();
    ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytesToDB);
    // Save the attachment to a doc with the given ID
    Response response = db.saveAttachment(bytesIn, "foo.txt", "text/plain", null, null);
    Document doc = db.find(Document.class, response.getId());
    assertTrue(doc.getAttachments().containsKey("foo.txt"));
    InputStream in = db.getAttachment(response.getId(), "foo.txt");
    try {
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        IOUtils.copy(in, bytesOut);
        byte[] bytesFromDB = bytesOut.toByteArray();
        assertArrayEquals(bytesToDB, bytesFromDB);
    } finally {
        in.close();
    }
}
Also used : Response(com.cloudant.client.api.model.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.cloudant.client.api.model.Document) 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