7
7
import org .junit .*;
8
8
9
9
import java .io .*;
10
- import java .net .*;
11
10
import java .nio .file .*;
12
11
import java .util .*;
13
12
import java .util .function .*;
@@ -82,10 +81,30 @@ public void singleFileTest() {
82
81
fileTest (file );
83
82
}
84
83
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
+
85
104
@ Test
86
105
public void dirTest () throws IOException {
87
106
NamedStreamable .DirWrapper dir = new NamedStreamable .DirWrapper ("root" , Arrays .asList ());
88
- MerkleNode addResult = ipfs .add (dir );
107
+ MerkleNode addResult = ipfs .add (dir ). get ( 0 ) ;
89
108
List <MerkleNode > ls = ipfs .ls (addResult .hash );
90
109
Assert .assertTrue (ls .size () > 0 );
91
110
}
@@ -115,7 +134,8 @@ public void directoryTest() throws IOException {
115
134
fout2 .flush ();
116
135
fout2 .close ();
117
136
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 );
119
139
List <MerkleNode > lsResult = ipfs .ls (addResult .hash );
120
140
if (lsResult .size () != 1 )
121
141
throw new IllegalStateException ("Incorrect number of objects in ls!" );
@@ -144,7 +164,7 @@ public void hugeFileStreamTest() {
144
164
new Random (1 ).nextBytes (hugeData );
145
165
NamedStreamable .ByteArrayWrapper largeFile = new NamedStreamable .ByteArrayWrapper ("massive.txt" , hugeData );
146
166
try {
147
- MerkleNode addResult = ipfs .add (largeFile );
167
+ MerkleNode addResult = ipfs .add (largeFile ). get ( 0 ) ;
148
168
InputStream in = ipfs .catStream (addResult .hash );
149
169
150
170
byte [] res = new byte [hugeData .length ];
@@ -179,7 +199,7 @@ public void hostFileTest() throws IOException {
179
199
180
200
public void fileTest (NamedStreamable file ) {
181
201
try {
182
- MerkleNode addResult = ipfs .add (file );
202
+ MerkleNode addResult = ipfs .add (file ). get ( 0 ) ;
183
203
byte [] catResult = ipfs .cat (addResult .hash );
184
204
byte [] getResult = ipfs .get (addResult .hash );
185
205
if (!Arrays .equals (catResult , file .getContents ()))
@@ -196,7 +216,7 @@ public void fileTest(NamedStreamable file) {
196
216
@ Test
197
217
public void pinTest () {
198
218
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 ) ;
200
220
Multihash hash = file .hash ;
201
221
Map <Multihash , Object > ls1 = ipfs .pin .ls (IPFS .PinType .all );
202
222
boolean pinned = ls1 .containsKey (hash );
@@ -220,7 +240,7 @@ public void pinTest() {
220
240
@ Test
221
241
public void pinUpdate () {
222
242
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 ) ;
224
244
Multihash hashChild1 = child1 .hash ;
225
245
System .out .println ("child1: " + hashChild1 );
226
246
0 commit comments