package asia.gkc.vneedu.storage;

import asia.gkc.vneedu.utils.BaseTest;
import org.junit.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import static org.junit.Assert.*;

/**
 * Created by jakes on 4/9/16.
 */
public class StorageFactoryTest extends BaseTest {
    private File createTextFile() throws Exception {
        String testFile = this.getClass().getResource("/").getFile() + "the-file-name.txt";
        PrintWriter writer = new PrintWriter(testFile, "UTF-8");
        writer.println("The first line");
        writer.println("The second line");
        writer.close();
        return new File(testFile);
    }

    @Test
    public void getStorage() throws Exception {
        Storage storage = StorageFactory.getStorage("qiniu");

        assertNotNull(storage);

        String path = storage.uploadFile(createTextFile(), "/hello/haha.txt");

        logger.debug(path);

        assertTrue(path != null && path.length() > 0);
    }

}
@@ -87,73 +87,102 @@
 nit.
-Test
+Before
 ;%0A
-%0A
 import 
-java.io.File;%0Aimport java.io.FileNotFoundException;
+org.junit.Test;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0A
 %0Aimp
@@ -193,27 +193,20 @@
 java.io.
-PrintWriter
+File
 ;%0Aimport
@@ -218,36 +218,19 @@
 .io.
-UnsupportedEncodingException
+PrintWriter
 ;%0A%0Ai
@@ -353,16 +353,112 @@
 eTest %7B%0A
+    private final String tmp = %22/hello/haha.txt%22;%0A%0A    @Autowired%0A    private Storage storage;%0A%0A
     priv
@@ -872,71 +872,8 @@
 n %7B%0A
-        Storage storage = StorageFactory.getStorage(%22qiniu%22);%0A%0A
     
@@ -960,33 +960,19 @@
 File(), 
-%22/hello/haha.txt%22
+tmp
 );%0A%0A    
@@ -1058,9 +1058,122 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void deleteFile() %7B%0A        assertNotNull(storage);%0A%0A        storage.deleteFile(tmp);%0A    %7D%0A
 %7D

add test for storage factory