diff --git a/importPicture/AdjustTime.ini.org b/importPicture/AdjustTime.ini.org new file mode 100644 index 0000000..67c1cc9 --- /dev/null +++ b/importPicture/AdjustTime.ini.org @@ -0,0 +1,17 @@ +#by AdjustTime +#Sat May 20 17:54:15 JST 2017 +GPX.BASETIME=FILE_UPDATE +IMG.OUTPUT_EXIF=true +GPX.OUTPUT_WPT=false +GPX.OUTPUT_SPEED=false +IMG.OUTPUT_ALL=true +GPX.noFirstNode=true +IMG.OUTPUT=true +GPX.gpxSplit=true +GPX.REUSE=false +GPX.OVERWRITE_MAGVAR=false +IMG.TIME=2017-05-18T09\:16\:48 +IMG.BASE_FILE=DSC05183.JPG +IMG.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/cameradata/10170518 +GPX.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/cameradata/10170518/20170518.gpx +IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/output diff --git a/importPicture/src/osm/jp/gpx/ImportPicture.java b/importPicture/src/osm/jp/gpx/ImportPicture.java index 784fa35..2b85272 100644 --- a/importPicture/src/osm/jp/gpx/ImportPicture.java +++ b/importPicture/src/osm/jp/gpx/ImportPicture.java @@ -473,6 +473,7 @@ transformer.transform(source, result); outputFile = new File(outDir, iStr +"_.gpx"); + outputFile.mkdirs(); os = new FileOutputStream(outputFile); result = new StreamResult(os); transformer.transform(source, result); diff --git a/importPicture/test/osm/jp/gpx/ImportPictureTest.java b/importPicture/test/osm/jp/gpx/ImportPictureTest.java index 444df63..3ee1024 100644 --- a/importPicture/test/osm/jp/gpx/ImportPictureTest.java +++ b/importPicture/test/osm/jp/gpx/ImportPictureTest.java @@ -8,94 +8,130 @@ 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 { + + public static class SONYのカメラの場合 { + + @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); + } + } - @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 { + @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)); - } } diff --git a/importPicture/test/osm/jp/gpx/TarGz.java b/importPicture/test/osm/jp/gpx/TarGz.java index 8260f48..b203ddb 100644 --- a/importPicture/test/osm/jp/gpx/TarGz.java +++ b/importPicture/test/osm/jp/gpx/TarGz.java @@ -21,7 +21,7 @@ { public static void main(String[] args) throws IOException { File baseDir = new File("testdata/cameradata"); - File tazFile = new File(baseDir, "Sony20170518.tar.gz"); + File tazFile = new File("testdata", "Sony20170518.tar.gz"); TarGz.uncompress(tazFile, baseDir); } diff --git a/importPicture/testdata/AdjustTime.20170518.ini b/importPicture/testdata/AdjustTime.20170518.ini new file mode 100644 index 0000000..9bf5d84 --- /dev/null +++ b/importPicture/testdata/AdjustTime.20170518.ini @@ -0,0 +1,16 @@ +#by AdjustTime +#Wed May 17 19:07:03 JST 2017 +GPX.BASETIME=FILE_UPDATE +IMG.OUTPUT_EXIF=true +GPX.OUTPUT_WPT=false +GPX.OUTPUT_SPEED=false +GPX.noFirstNode=true +IMG.OUTPUT=true +GPX.gpxSplit=true +IMG.TIME=2017-05-18T09\:16\:48 +GPX.OVERWRITE_MAGVAR=false +GPX.REUSE=false +IMG.BASE_FILE=DSC05183.JPG +IMG.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/cameradata/10170518 +GPX.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/cameradata/10170518/20170518.gpx +IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/output