import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
-import org.junit.BeforeClass;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.*;
+import org.junit.experimental.runners.Enclosed;
import hayashi.tools.files.DeleteDir;
+@RunWith(Enclosed.class)
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);
+
+ public static class SONYのカメラの場合 {
- // 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);
+ @Before
+ public void setUp() throws Exception {
+ // カメラディレクトリを削除する
+ File dir = new File("testdata/cameradata");
+ if (dir.exists()) {
+ DeleteDir.delete(dir);
+ }
+ File outDir = new File("testdata/output");
+ if (outDir.exists()) {
+ DeleteDir.delete(outDir);
+ }
+ outDir.mkdir();
+
+ // カメラディレクトリを作成する
+ TarGz.uncompress(new File("testdata", "Sony20170518.tar.gz"), dir);
+
+ // GPXファイルをセット
+ try ( FileInputStream inStream = new FileInputStream(new File("testdata", "20170518.gpx"));
+ FileOutputStream outStream = new FileOutputStream(new File("testdata/cameradata/10170518/20170518.gpx"));
+ FileChannel inChannel = inStream.getChannel();
+ FileChannel outChannel = outStream.getChannel(); )
+ {
+ inChannel.transferTo(0, inChannel.size(), outChannel);
+ }
+
+ // プロパティファイルを設定
+ File iniFile = new File("AdjustTime.ini");
+ File orgFile = new File("AdjustTime.ini.org");
+ File testFile = new File("testdata", "AdjustTime.20170518.ini");
+ if (orgFile.exists()) {
+ orgFile.delete();
+ }
+ if (iniFile.exists()) {
+ iniFile.renameTo(orgFile);
+ }
+ try ( FileInputStream inStream = new FileInputStream(testFile);
+ FileOutputStream outStream = new FileOutputStream(new File("AdjustTime.ini"));
+ FileChannel inChannel = inStream.getChannel();
+ FileChannel outChannel = outStream.getChannel(); )
+ {
+ inChannel.transferTo(0, inChannel.size(),outChannel);
+ }
}
-
- 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 {
+ @Test
+ public void FILE_UPDATE時間を基準にして時間外のファイルはコピー対象外の時() throws Exception {
+ // "AdjustTime.20170517.ini"のデフォルト状態で実行
AppParameters params = new AppParameters();
- String valueStr = params.getProperty(AppParameters.IMG_TIME);
- assertThat(valueStr, is("2017-05-17T10:02:51"));
+ params.setProperty(AppParameters.GPX_BASETIME, "FILE_UPDATE");
+ params.setProperty(AppParameters.IMG_OUTPUT_ALL, "false");
+ params.store();
+
+ // 実行する
+ try {
+ String[] argv = {
+ "./testdata/cameradata/10170518",
+ "DSC05183.JPG",
+ "2017-05-18T09:16:48",
+ "./testdata/output",
+ "./testdata/cameradata/10170518"
+ };
+ ImportPicture.main(argv);
+ }
+ catch (Exception e) {
+ fail("Exceptionが発生した。");
+ }
+
+ File file0 = new File("./testdata/output/10170518", "DSC05183.JPG");
+ assertThat(file0.exists(), is(false));
+ File file1 = new File("./testdata/output/10170518", "DSC05184.JPG");
+ assertThat(file1.exists(), is(true));
+ File file2 = new File("./testdata/output/10170518", "DSC05196.JPG");
+ assertThat(file2.exists(), is(true));
+ File file3 = new File("./testdata/output/10170518", "DSC05204.JPG");
+ assertThat(file3.exists(), is(true));
+ File file4 = new File("./testdata/output/10170518", "DSC05205.JPG");
+ assertThat(file4.exists(), is(false));
}
- catch (Exception e) {
- fail("Exceptionが発生した。");
+
+ @Test
+ public void FILE_UPDATE時間を基準にして時間外のファイルもコピーする時() throws Exception {
+ AppParameters params = new AppParameters();
+ params.setProperty(AppParameters.GPX_BASETIME, "FILE_UPDATE");
+ params.setProperty(AppParameters.IMG_OUTPUT_ALL, "true");
+ params.store();
+
+ // 実行する
+ try {
+ String[] argv = {
+ "./testdata/cameradata/10170518",
+ "DSC05183.JPG",
+ "2017-05-18T09:16:48",
+ "./testdata/output",
+ "./testdata/cameradata/10170518"
+ };
+ ImportPicture.main(argv);
+ }
+ catch (Exception e) {
+ fail("Exceptionが発生した。");
+ }
+
+ File file0 = new File("./testdata/output/10170518", "DSC05183.JPG");
+ assertThat(file0.exists(), is(true));
+ File file1 = new File("./testdata/output/10170518", "DSC05184.JPG");
+ assertThat(file1.exists(), is(true));
+ File file2 = new File("./testdata/output/10170518", "DSC05196.JPG");
+ assertThat(file2.exists(), is(true));
+ File file3 = new File("./testdata/output/10170518", "DSC05204.JPG");
+ assertThat(file3.exists(), is(true));
+ File file4 = new File("./testdata/output/10170518", "DSC05205.JPG");
+ assertThat(file4.exists(), is(true));
}
}
- @Test
- public void 出力フォルダにGPXが作成されていること() {
- File newGpxFile = new File("./testdata/cameradata/10070517/20170517_.gpx");
- assertThat(newGpxFile.exists(), is(true));
- }
}