OSDN Git Service

tar.gz ファイルを回答するクラスをtestに追加
[importpicture/importpicture.git] / importPicture / test / osm / jp / gpx / ImportPictureTest.java
diff --git a/importPicture/test/osm/jp/gpx/ImportPictureTest.java b/importPicture/test/osm/jp/gpx/ImportPictureTest.java
new file mode 100644 (file)
index 0000000..444df63
--- /dev/null
@@ -0,0 +1,101 @@
+package osm.jp.gpx;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.nio.channels.FileChannel;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import hayashi.tools.files.DeleteDir;
+
+public class ImportPictureTest {
+
+       @BeforeClass
+       public static void setUpBeforeClass() throws Exception {
+               // カメラディレクトリを削除する
+               File dir = new File("testdata/cameradata");
+               if (dir.exists()) {
+                       DeleteDir.delete(dir);
+               }
+               
+               // カメラディレクトリを作成する
+               TarGz.uncompress(new File("testdata", "Sony20170518.tar.gz"), dir);
+               
+               // GPXファイルをセット
+               FileInputStream inStream = new FileInputStream(new File("testdata", "20170517.gpx"));
+               FileOutputStream outStream = new FileOutputStream(new File("testdata/cameradata/10070517/10070517/20170517.gpx"));
+        FileChannel inChannel = inStream.getChannel();
+        FileChannel outChannel = outStream.getChannel();
+        try {
+            inChannel.transferTo(0, inChannel.size(),outChannel);
+        }
+        finally {
+            if (inChannel != null) inChannel.close();
+            if (outChannel != null) outChannel.close();
+            inStream.close();
+            outStream.close();
+            inChannel = null;
+            outChannel = null;
+        }
+        
+        // プロパティファイルを設定
+               File iniFile = new File("AdjustTime.ini");
+               File orgFile = new File("AdjustTime.ini.org");
+               File testFile = new File("testdata", "AdjustTime.20170517.ini");
+               
+               if (orgFile.exists()) {
+                       orgFile.delete();
+               }
+               if (iniFile.exists()) {
+                       iniFile.renameTo(orgFile);
+               }
+               
+               inStream = new FileInputStream(testFile);
+               outStream = new FileOutputStream(new File("AdjustTime.ini"));
+        inChannel = inStream.getChannel();
+        outChannel = outStream.getChannel();
+        try {
+            inChannel.transferTo(0, inChannel.size(),outChannel);
+        }
+        finally {
+            if (inChannel != null) inChannel.close();
+            if (outChannel != null) outChannel.close();
+            inStream.close();
+            outStream.close();
+        }
+        
+        // 実行する
+        String[] argv = {
+                       "./testdata/cameradata/10070517/10070517",
+                       "DSC05105.JPG",
+                       "2017-05-17T10:02:51",
+                       "./testdata/cameradata/",
+                       "./testdata/cameradata/10070517/10070517"
+        };
+        ImportPicture.main(argv);
+        
+       }
+
+       @Test
+       public void INIファイルにパラメータIMG_TIMEが書き込まれていること() {
+               try {
+                       AppParameters params = new AppParameters();
+                       String valueStr = params.getProperty(AppParameters.IMG_TIME);
+                       assertThat(valueStr, is("2017-05-17T10:02:51"));
+               }
+               catch (Exception e) {
+                       fail("Exceptionが発生した。");
+               }
+       }
+
+       @Test
+       public void 出力フォルダにGPXが作成されていること() {
+               File newGpxFile = new File("./testdata/cameradata/10070517/20170517_.gpx");
+               assertThat(newGpxFile.exists(), is(true));
+       }
+}