Search in sources :

Example 81 with Test

use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.

the class IndexListTests method listSimpleJsonIndex.

@Test
public void listSimpleJsonIndex() throws Exception {
    enqueueList(JSON_SIMPLE);
    List<JsonIndex> indexes = db.listIndexes().jsonIndexes();
    assertEquals(1, indexes.size(), "There should be 1 JSON index");
    JsonIndex simple = indexes.get(0);
    assertSimpleJson(simple);
}
Also used : JsonIndex(com.cloudant.client.api.query.JsonIndex) Test(org.junit.jupiter.api.Test)

Example 82 with Test

use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.

the class AttachmentsTest method attachmentStandaloneGivenId.

@Test
public void attachmentStandaloneGivenId() throws IOException, URISyntaxException {
    String docId = Utils.generateUUID();
    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", docId, null);
    assertEquals(docId, response.getId(), "The saved document ID should match");
    InputStream in = db.getAttachment(docId, "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) Test(org.junit.jupiter.api.Test)

Example 83 with Test

use of org.junit.jupiter.api.Test 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 84 with Test

use of org.junit.jupiter.api.Test 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 85 with Test

use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.

the class AttachmentsTest method attachmentStandaloneUpdate.

@Test
public void attachmentStandaloneUpdate() throws Exception {
    byte[] bytesToDB = "binary data".getBytes("UTF-8");
    ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytesToDB);
    Response response = db.saveAttachment(bytesIn, "foo.txt", "text/plain");
    bytesToDB = "updated binary data".getBytes("UTF-8");
    bytesIn = new ByteArrayInputStream(bytesToDB);
    response = db.saveAttachment(bytesIn, "foo.txt", "text/plain", response.getId(), response.getRev());
    Document doc = db.find(Document.class, response.getId(), response.getRev());
    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

Test (org.junit.jupiter.api.Test)67450 lombok.val (lombok.val)3880 File (java.io.File)2228 HashMap (java.util.HashMap)2180 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2164 ArrayList (java.util.ArrayList)2137 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2027 SqlSession (org.apache.ibatis.session.SqlSession)1845 List (java.util.List)1799 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1484 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1184 Map (java.util.Map)1143 IOException (java.io.IOException)1048 Path (java.nio.file.Path)1006 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)935 Date (java.util.Date)914 Method (java.lang.reflect.Method)862 TestBean (org.springframework.beans.testfixture.beans.TestBean)822 Transaction (org.neo4j.graphdb.Transaction)752 BaseDataTest (org.apache.ibatis.BaseDataTest)740