package io.ipfs.api;

import java.io.*;
import java.nio.file.*;

import org.junit.Assert;
import org.junit.Test;

import io.ipfs.multiaddr.MultiAddress;

public class RecursiveAddTest {

    private final IPFS ipfs = new IPFS(new MultiAddress("/ip4/127.0.0.1/tcp/5001"));
    
    @Test
    public void testAdd() throws Exception {
        
        String TEST_HASH = "QmWVMRbFTrA6pMhsfXzsyoWqmrhy5FPd4VitfX79R5bguw";
        
        System.out.println("ipfs version: " + ipfs.version());
        System.out.println("pwd: " + new File("").getAbsolutePath());
        
        Path path = Paths.get("src/test/resources/html");
        MerkleNode node = ipfs.add(new NamedStreamable.FileWrapper(path.toFile())).get(0);
        Assert.assertEquals(TEST_HASH, node.hash.toBase58());
    }
}

@@ -56,16 +56,36 @@
 .file.*;
+%0Aimport java.util.*;
 %0A%0Aimport
@@ -349,103 +349,8 @@
 n %7B%0A
-        %0A        String TEST_HASH = %22QmWVMRbFTrA6pMhsfXzsyoWqmrhy5FPd4VitfX79R5bguw%22;%0A        %0A
     
@@ -404,24 +404,25 @@
 version());%0A
+%0A
         Syst
@@ -422,144 +422,395 @@
    S
-ystem.out.println(%22pwd: %22 + new File(%22%22).getAbsolutePath());%0A        %0A        Path path = Paths.get(%22src/test/resources/html%22
+tring EXPECTED = %22QmX5fZ6aUxNTAS7ZfYc8f4wPoMx6LctuNbMjuJZ9EmUSr6%22;%0A%0A        Path base = Paths.get(%22tmpdata%22);%0A        base.toFile().mkdirs();%0A        Files.write(base.resolve(%22index.html%22), %22%3Chtml%3E%3C/html%3E%22.getBytes());%0A        Path js = base.resolve(%22js%22);%0A        js.toFile().mkdirs();%0A        Files.write(js.resolve(%22func.js%22), %22function() %7Bconsole.log('Hey');%7D%22.getBytes()
 );%0A
+%0A
         
 Merk
@@ -805,16 +805,21 @@
         
+List%3C
 MerkleNo
@@ -820,21 +820,21 @@
 rkleNode
- node
+%3E add
  = ipfs.
@@ -873,12 +873,12 @@
 per(
-path
+base
 .toF
@@ -888,14 +888,58 @@
 ()))
-.get(0
+;%0A        MerkleNode node = add.get(add.size() - 1
 );%0A 
@@ -969,17 +969,16 @@
 als(
-TEST_HASH
+EXPECTED
 , no

fix test