11package com .couchbase .lite ;
22
3+ import com .couchbase .lite .utils .IOUtils ;
4+
35import org .junit .Test ;
46
7+ import java .io .IOException ;
8+ import java .io .InputStream ;
9+ import java .util .Arrays ;
10+
11+ import static org .junit .Assert .assertEquals ;
512import static org .junit .Assert .assertFalse ;
13+ import static org .junit .Assert .assertNotNull ;
614import static org .junit .Assert .assertTrue ;
715
816public class BlobTest extends BaseTest {
@@ -88,4 +96,49 @@ public void testHashCode() throws CouchbaseLiteException {
8896 assertTrue (blob1a .hashCode () == data1c .hashCode ());
8997 assertTrue (data1c .hashCode () == blob1a .hashCode ());
9098 }
99+
100+ @ Test
101+ public void testGetContent () throws IOException , CouchbaseLiteException {
102+ byte [] bytes ;
103+
104+ InputStream is = getAsset ("attachment.png" );
105+ try {
106+ bytes = IOUtils .toByteArray (is );
107+ } finally {
108+ is .close ();
109+ }
110+
111+ Blob blob = new Blob ("image/png" , bytes );
112+ MutableDocument mDoc = new MutableDocument ("doc1" );
113+ mDoc .setBlob ("blob" , blob );
114+ Document doc = save (mDoc );
115+ Blob savedBlob = doc .getBlob ("blob" );
116+ assertNotNull (savedBlob );
117+ assertEquals ("image/png" , savedBlob .getContentType ());
118+ byte [] content = blob .getContent ();
119+ assertTrue (Arrays .equals (content , bytes ));
120+ }
121+
122+ // https://github.com/couchbase/couchbase-lite-android/issues/1438
123+ @ Test
124+ public void testGetContent6MBFile () throws IOException , CouchbaseLiteException {
125+ byte [] bytes ;
126+
127+ InputStream is = getAsset ("iTunesMusicLibrary.json" );
128+ try {
129+ bytes = IOUtils .toByteArray (is );
130+ } finally {
131+ is .close ();
132+ }
133+
134+ Blob blob = new Blob ("application/json" , bytes );
135+ MutableDocument mDoc = new MutableDocument ("doc1" );
136+ mDoc .setBlob ("blob" , blob );
137+ Document doc = save (mDoc );
138+ Blob savedBlob = doc .getBlob ("blob" );
139+ assertNotNull (savedBlob );
140+ assertEquals ("application/json" , savedBlob .getContentType ());
141+ byte [] content = blob .getContent ();
142+ assertTrue (Arrays .equals (content , bytes ));
143+ }
91144}
0 commit comments