77import org .junit .*;
88
99import java .io .*;
10- import java .net .*;
1110import java .nio .file .*;
1211import java .util .*;
1312import java .util .function .*;
@@ -82,10 +81,30 @@ public void singleFileTest() {
8281 fileTest (file );
8382 }
8483
84+ @ Test
85+ public void wrappedSingleFileTest () {
86+ NamedStreamable .ByteArrayWrapper file = new NamedStreamable .ByteArrayWrapper ("hello.txt" , "G'day world! IPFS rocks!" .getBytes ());
87+ try {
88+ List <MerkleNode > addParts = ipfs .add (file , true );
89+ MerkleNode filePart = addParts .get (0 );
90+ MerkleNode dirPart = addParts .get (1 );
91+ byte [] catResult = ipfs .cat (filePart .hash );
92+ byte [] getResult = ipfs .get (filePart .hash );
93+ if (!Arrays .equals (catResult , file .getContents ()))
94+ throw new IllegalStateException ("Different contents!" );
95+ List <Multihash > pinRm = ipfs .pin .rm (dirPart .hash , true );
96+ if (!pinRm .get (0 ).equals (dirPart .hash ))
97+ throw new IllegalStateException ("Didn't remove file!" );
98+ Object gc = ipfs .repo .gc ();
99+ } catch (IOException e ) {
100+ throw new RuntimeException (e );
101+ }
102+ }
103+
85104 @ Test
86105 public void dirTest () throws IOException {
87106 NamedStreamable .DirWrapper dir = new NamedStreamable .DirWrapper ("root" , Arrays .asList ());
88- MerkleNode addResult = ipfs .add (dir );
107+ MerkleNode addResult = ipfs .add (dir ). get ( 0 ) ;
89108 List <MerkleNode > ls = ipfs .ls (addResult .hash );
90109 Assert .assertTrue (ls .size () > 0 );
91110 }
@@ -115,7 +134,8 @@ public void directoryTest() throws IOException {
115134 fout2 .flush ();
116135 fout2 .close ();
117136
118- MerkleNode addResult = ipfs .add (new NamedStreamable .FileWrapper (tmpDir .toFile ()));
137+ List <MerkleNode > addParts = ipfs .add (new NamedStreamable .FileWrapper (tmpDir .toFile ()));
138+ MerkleNode addResult = addParts .get (addParts .size () - 1 );
119139 List <MerkleNode > lsResult = ipfs .ls (addResult .hash );
120140 if (lsResult .size () != 1 )
121141 throw new IllegalStateException ("Incorrect number of objects in ls!" );
@@ -144,7 +164,7 @@ public void hugeFileStreamTest() {
144164 new Random (1 ).nextBytes (hugeData );
145165 NamedStreamable .ByteArrayWrapper largeFile = new NamedStreamable .ByteArrayWrapper ("massive.txt" , hugeData );
146166 try {
147- MerkleNode addResult = ipfs .add (largeFile );
167+ MerkleNode addResult = ipfs .add (largeFile ). get ( 0 ) ;
148168 InputStream in = ipfs .catStream (addResult .hash );
149169
150170 byte [] res = new byte [hugeData .length ];
@@ -179,7 +199,7 @@ public void hostFileTest() throws IOException {
179199
180200 public void fileTest (NamedStreamable file ) {
181201 try {
182- MerkleNode addResult = ipfs .add (file );
202+ MerkleNode addResult = ipfs .add (file ). get ( 0 ) ;
183203 byte [] catResult = ipfs .cat (addResult .hash );
184204 byte [] getResult = ipfs .get (addResult .hash );
185205 if (!Arrays .equals (catResult , file .getContents ()))
@@ -196,7 +216,7 @@ public void fileTest(NamedStreamable file) {
196216 @ Test
197217 public void pinTest () {
198218 try {
199- MerkleNode file = ipfs .add (new NamedStreamable .ByteArrayWrapper ("some data" .getBytes ()));
219+ MerkleNode file = ipfs .add (new NamedStreamable .ByteArrayWrapper ("some data" .getBytes ())). get ( 0 ) ;
200220 Multihash hash = file .hash ;
201221 Map <Multihash , Object > ls1 = ipfs .pin .ls (IPFS .PinType .all );
202222 boolean pinned = ls1 .containsKey (hash );
@@ -220,7 +240,7 @@ public void pinTest() {
220240 @ Test
221241 public void pinUpdate () {
222242 try {
223- MerkleNode child1 = ipfs .add (new NamedStreamable .ByteArrayWrapper ("some data" .getBytes ()));
243+ MerkleNode child1 = ipfs .add (new NamedStreamable .ByteArrayWrapper ("some data" .getBytes ())). get ( 0 ) ;
224244 Multihash hashChild1 = child1 .hash ;
225245 System .out .println ("child1: " + hashChild1 );
226246
0 commit comments