Search in sources :

Example 1 with Attachment

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

the class AttachmentsTest method removeAttachment.

@Test
public void removeAttachment() {
    String attachmentName = "txt_1.txt";
    Attachment attachment1 = new Attachment("VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=", "text/plain");
    // Bar extends Document
    Bar bar = new Bar();
    bar.addAttachment(attachmentName, attachment1);
    Response response = db.save(bar);
    Bar bar2 = db.find(Bar.class, response.getId(), new Params().attachments());
    String base64Data = bar2.getAttachments().get("txt_1.txt").getData();
    assertNotNull(base64Data);
    response = db.removeAttachment(bar2, attachmentName);
    Bar bar3 = db.find(Bar.class, response.getId(), new Params().attachments());
    assertNull(bar3.getAttachments());
}
Also used : Response(com.cloudant.client.api.model.Response) Params(com.cloudant.client.api.model.Params) Attachment(com.cloudant.client.api.model.Attachment) Test(org.junit.jupiter.api.Test)

Example 2 with Attachment

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

the class AttachmentsTest method attachmentInline_getWithDocument.

@Test
public void attachmentInline_getWithDocument() {
    Attachment attachment = new Attachment("VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=", "text/plain");
    Bar bar = new Bar();
    bar.addAttachment("txt_1.txt", attachment);
    Response response = db.save(bar);
    Bar bar2 = db.find(Bar.class, response.getId(), new Params().attachments());
    String base64Data = bar2.getAttachments().get("txt_1.txt").getData();
    assertNotNull(base64Data);
}
Also used : Response(com.cloudant.client.api.model.Response) Params(com.cloudant.client.api.model.Params) Attachment(com.cloudant.client.api.model.Attachment) Test(org.junit.jupiter.api.Test)

Example 3 with Attachment

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

the class AttachmentsTest method attachmentInline.

@Test
public void attachmentInline() {
    Attachment attachment1 = new Attachment("VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=", "text/plain");
    Attachment attachment2 = new Attachment();
    attachment2.setData(Base64.encodeBase64String("binary string".getBytes()));
    attachment2.setContentType("text/plain");
    // Bar extends Document
    Bar bar = new Bar();
    bar.addAttachment("txt_1.txt", attachment1);
    bar.addAttachment("txt_2.txt", attachment2);
    db.save(bar);
}
Also used : Attachment(com.cloudant.client.api.model.Attachment) Test(org.junit.jupiter.api.Test)

Aggregations

Attachment (com.cloudant.client.api.model.Attachment)3 Test (org.junit.jupiter.api.Test)3 Params (com.cloudant.client.api.model.Params)2 Response (com.cloudant.client.api.model.Response)2