/*
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.github.sakserv.minicluster;

import com.github.sakserv.minicluster.impl.HdfsLocalCluster;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

public class HdfsLocalClusterTest {

    // Logger
    private static final Logger LOG = Logger.getLogger(HdfsLocalClusterTest.class);

    private HdfsLocalCluster dfsCluster;

    @Before
    public void setUp(){
        dfsCluster = new HdfsLocalCluster();
        dfsCluster.start();
    }

    @After
    public void tearDown(){
        dfsCluster.stop(true);
    }

    @Test
    public void testDfsClusterStart() {
        FileSystem hdfsFsHandle = dfsCluster.getHdfsFileSystemHandle();
        try {
            FSDataOutputStream writer = hdfsFsHandle.create(new Path("/tmp/testing"));
            writer.writeUTF("This is a test");
            writer.close();

            FSDataInputStream reader = hdfsFsHandle.open(new Path("/tmp/testing"));
            LOG.info("HDFS READ: Output from test file: " + reader.readUTF());
            reader.close();

            hdfsFsHandle.close();
        } catch(IOException e) {
            e.printStackTrace();
        }

    }
}

@@ -937,16 +937,51 @@
 .Test;%0A%0A
+import static org.junit.Assert.*;%0A%0A
 import j
@@ -1133,24 +1133,82 @@
 st.class);%0A%0A
+    private static final String TEST_STRING = %22TESTING%22;%0A%0A
     private 
@@ -1479,17 +1479,104 @@
 Start() 
-%7B
+throws IOException %7B%0A        %0A        // Write a file to HDFS containing the test string
 %0A       
@@ -1644,26 +1644,8 @@
 ();%0A
-        try %7B%0A    
     
@@ -1727,28 +1727,24 @@
 ));%0A        
-   
- 
 writer.write
@@ -1751,31 +1751,22 @@
 UTF(
-%22This is a test%22);%0A    
+TEST_STRING);%0A
     
@@ -1782,32 +1782,80 @@
 r.close();%0A%0A    
+    // Read the file and compare to test string%0A
         FSDataIn
@@ -1930,60 +1930,21 @@
     
-    LOG.info(%22HDFS READ: Output from test file: %22 + 
+assertEquals(
 read
@@ -1955,16 +1955,29 @@
 eadUTF()
+, TEST_STRING
 );%0A     
@@ -1979,20 +1979,16 @@
         
-    
 reader.c
@@ -1991,29 +1991,24 @@
 er.close();%0A
-%0A    
         hdfs
@@ -2028,84 +2028,8 @@
 e();
-%0A        %7D catch(IOException e) %7B%0A            e.printStackTrace();%0A        %7D
 %0A%0A  

use proper assertions in the hdfs test