@Test
  public void buildRevisionFromMapValidMapWithAttachments() throws Exception {

    // lets the get the attachment encoded

    File file = TestUtils.loadFixture("fixture/bonsai-boston.jpg");

    byte[] unencodedAttachment = FileUtils.readFileToByteArray(file);
    byte[] encodedAttachment = this.encodeAttachment(unencodedAttachment);

    Map<String, Map<String, Object>> attachments = new HashMap<String, Map<String, Object>>();
    Map<String, Object> bonsai = createAttachmentMap(encodedAttachment, "image/jpeg", false);

    attachments.put("bonsai-boston.jpg", bonsai);
    documentRev.put("_attachments", attachments);

    DocumentRevision revision =
        DocumentRevisionBuilder.buildRevisionFromMap(documentURI, documentRev);

    Assert.assertNotNull(revision);
    Assert.assertEquals(body, revision.getBody().asMap());
    Assert.assertEquals(revision.getId(), "someIdHere");
    Assert.assertEquals(revision.getRevision(), "3-750dac460a6cc41e6999f8943b8e603e");
    Assert.assertEquals(revision.getAttachments().size(), 1);
    ByteArrayInputStream expected = new ByteArrayInputStream(unencodedAttachment);
    InputStream actual = revision.getAttachments().get("bonsai-boston.jpg").getInputStream();
    Assert.assertTrue(TestUtils.streamsEqual(expected, actual));
  }
  @Test
  public void buildRevisionFromMapValidMapWithAttachmentsDataExcluded() throws Exception {

    Assume.assumeFalse(
        "Not running test as 'buildRevisionFromMap' can't retrieve the "
            + "attachment with cookie authentication enabled",
        TestOptions.COOKIE_AUTH);

    // lets the get the attachment encoded

    File file = TestUtils.loadFixture("fixture/bonsai-boston.jpg");

    byte[] unencodedAttachment = FileUtils.readFileToByteArray(file);
    byte[] encodedAttachment = this.encodeAttachment(unencodedAttachment);

    // create a revision on a couchDB instance so we can test the download
    // of attachments
    Map<String, Object> remoteDoc = new HashMap<String, Object>();
    remoteDoc.put("_id", "someIdHere");
    Map<String, Map<String, Object>> remoteAttachments = new HashMap<String, Map<String, Object>>();
    Map<String, Object> remoteBonsai = createAttachmentMap(encodedAttachment, "image/jpeg", false);

    remoteAttachments.put("bonsai-boston.jpg", remoteBonsai);
    remoteDoc.put("_attachments", remoteAttachments);

    remoteDb.create(remoteDoc);

    // build up the test json map

    Map<String, Map<String, Object>> attachments = new HashMap<String, Map<String, Object>>();
    Map<String, Object> bonsai = createAttachmentMap(encodedAttachment, "image/jpeg", true);

    attachments.put("bonsai-boston.jpg", bonsai);
    documentRev.put("_attachments", attachments);

    URI uri = new URI(remoteDb.getCouchClient().getRootUri().toString() + "/" + "someIdHere");

    // create the document revision and test

    DocumentRevision revision = DocumentRevisionBuilder.buildRevisionFromMap(uri, documentRev);

    Assert.assertNotNull(revision);
    Assert.assertEquals(body, revision.getBody().asMap());
    Assert.assertEquals(revision.getId(), "someIdHere");
    Assert.assertEquals(revision.getRevision(), "3-750dac460a6cc41e6999f8943b8e603e");
    Assert.assertEquals(revision.getAttachments().size(), 1);
    InputStream attachmentInputStream =
        revision.getAttachments().get("bonsai-boston.jpg").getInputStream();
    InputStream expectedInputStream = new ByteArrayInputStream(unencodedAttachment);
    Assert.assertTrue(TestUtils.streamsEqual(expectedInputStream, attachmentInputStream));
  }
  @Test
  public void buildRevisionFromMapValidMapWithTextAttachmentsDataExcluded() throws Exception {

    Assume.assumeFalse(
        "Not running test as 'buildRevisionFromMap' can't retrieve the "
            + "attachment with cookie authentication enabled",
        TestOptions.COOKIE_AUTH);

    // lets the get the attachment encoded

    String attachmentText = "Hello World";

    byte[] unencodedAttachment = attachmentText.getBytes();
    byte[] encodedAttachment = this.encodeAttachment(unencodedAttachment);

    // create a revision on a couchDB instance so we can test the download
    // of attachments
    Map<String, Object> remoteDoc = new HashMap<String, Object>();
    remoteDoc.put("_id", "someIdHere");
    Map<String, Map<String, Object>> remoteAttachments = new HashMap<String, Map<String, Object>>();

    remoteAttachments.put(
        "hello.txt", this.createAttachmentMap(encodedAttachment, "text/plain", false));
    remoteDoc.put("_attachments", remoteAttachments);

    remoteDb.create(remoteDoc);
    documentURI = new URI(remoteDb.getCouchClient().getRootUri().toString() + "/" + "someIdHere");

    Map<String, Map<String, Object>> attachments = new HashMap<String, Map<String, Object>>();
    Map<String, Object> bonsai =
        createAttachmentMap(encodedAttachment, "text/plain", true); // new HashMap<String,Object>();
    bonsai.put("encoding", "gzip");

    attachments.put("hello.txt", bonsai);
    documentRev.put("_attachments", attachments);

    // create the document revision and test

    DocumentRevision revision =
        DocumentRevisionBuilder.buildRevisionFromMap(documentURI, documentRev);

    Assert.assertNotNull(revision);
    Assert.assertEquals(body, revision.getBody().asMap());
    Assert.assertEquals(revision.getId(), "someIdHere");
    Assert.assertEquals(revision.getRevision(), "3-750dac460a6cc41e6999f8943b8e603e");
    Assert.assertEquals(revision.getAttachments().size(), 1);
    InputStream attachmentInputStream = revision.getAttachments().get("hello.txt").getInputStream();
    InputStream expectedInputStream = new ByteArrayInputStream(unencodedAttachment);
    Assert.assertTrue(TestUtils.streamsEqual(expectedInputStream, attachmentInputStream));
  }