package es.tid.cosmos.platform.injection.server;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.junit.Before;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
 * HadoopFileSystemViewTest
 *
 * @author logc
 * @since 15/05/12
 */
public class HadoopFileSystemViewTest {
    private HadoopFileSystemView hadoopFileSystemView;

    @Before
    public void setUp() throws Exception {
        String userName = "test";
        Configuration conf = new Configuration();
        this.hadoopFileSystemView = new HadoopFileSystemView(userName, conf);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testGetFileWithEmptyFilename() throws Exception {
        this.hadoopFileSystemView.getFile("");
    }

    @Test
    public void testGetFile() throws Exception {
        HadoopSshFile bar = this.hadoopFileSystemView.getFile("/foo/bar");
        assertEquals("bar", bar.getName());
        assertEquals("/foo/bar", bar.getAbsolutePath());
        assertFalse(bar.doesExist());

        HadoopSshFile bq = this.hadoopFileSystemView.getFile(bar, "bq");
        assertEquals("bq", bq.getName());
        assertEquals("/foo/bar/bq", bq.getAbsolutePath());
        assertFalse(bq.doesExist());
    }

    @Test
    public void testRedirectionToHomePath() throws Exception {
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(URI.create(conf.get("fs.default.name")),
                conf, "test");
        String homePath = fs.getHomeDirectory().toString().replaceFirst(
                fs.getUri().toString(), "");
        HadoopSshFile init = this.hadoopFileSystemView.getFile(
                new HadoopSshFile(".", "test", fs), ".");
        assertEquals(homePath, init.getAbsolutePath());
    }
}
@@ -603,16 +603,77 @@
 wTest %7B%0A
+    private String userName;%0A    private Configuration conf;%0A
     priv
@@ -783,23 +783,21 @@
         
-String 
+this.
 userName
@@ -811,38 +811,29 @@
 t%22;%0A        
-Configuration 
+this.
 conf = new C
@@ -946,51 +946,8 @@
 Test
-(expected = IllegalArgumentException.class)
 %0A   
@@ -1008,32 +1008,53 @@
 eption %7B%0A       
+ HadoopSshFile file =
  this.hadoopFile
@@ -1073,24 +1073,482 @@
 etFile(%22%22);%0A
+        FileSystem hadoopFS = FileSystem.get(%0A                URI.create(this.conf.get(%22fs.default.name%22)),%0A                           this.conf, this.userName);%0A        String homePath = hadoopFS.getHomeDirectory().toString()%0A                .replaceFirst(hadoopFS.getUri().toString(), %22%22);%0A        assertEquals(homePath, file.getAbsolutePath());%0A        assertEquals(homePath.substring(homePath.lastIndexOf(%22/%22) + 1),%0A                     file.getName());%0A
     %7D%0A%0A    @

Fix test break.