diff --git a/.gitignore b/.gitignore
index a69c6c9..f2dd24b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,10 +6,8 @@
sample/
**/ConvBusstop.jar
**/osmCoverage.jar
-database/
-GML_*/
-
-postgis.properties
+test/database/
+test/GML_*/
P*-*_GML/
@@ -35,4 +33,3 @@
**/nbproject/private/
/build/**
-/dist/*.jar
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
index 9cc275a..bc57e7c 100644
--- a/nbproject/build-impl.xml
+++ b/nbproject/build-impl.xml
@@ -916,6 +916,14 @@
+
+
+
+
+
+
+
+
@@ -1411,6 +1419,14 @@
+
+
+
+
+
+
+
+
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
index d9744a4..d28085f 100644
--- a/nbproject/genfiles.properties
+++ b/nbproject/genfiles.properties
@@ -1,8 +1,8 @@
-nbbuild.xml.data.CRC32=4bf27971
+nbbuild.xml.data.CRC32=758709f1
nbbuild.xml.script.CRC32=e7ea1557
nbbuild.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=4bf27971
-nbproject/build-impl.xml.script.CRC32=ea55f081
+nbproject/build-impl.xml.data.CRC32=758709f1
+nbproject/build-impl.xml.script.CRC32=df3bce5b
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
diff --git a/nbproject/project.properties b/nbproject/project.properties
index 8f5353c..fa141b0 100644
--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -31,6 +31,7 @@
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
+file.reference.commons-compress-1.18.jar=/home/yuu/hayashi/workspace/commons-compress-1.18.jar
file.reference.hsqldb_2.2.9.jar=lib\\hsqldb_2.2.9.jar
file.reference.javax.json.jar=lib/javax.json.jar
file.reference.osmCoverage-src=src
@@ -43,7 +44,8 @@
${file.reference.hsqldb_2.2.9.jar}:\
${file.reference.javax.json.jar}:\
${file.reference.postgresql-42.2.4.jar}:\
- ${reference.hayashi-1.jar}
+ ${reference.hayashi-1.jar}:\
+ ${reference.hayashi.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
@@ -56,7 +58,8 @@
${javac.classpath}:\
${build.classes.dir}:\
${libs.junit_4.classpath}:\
- ${libs.hamcrest.classpath}
+ ${libs.hamcrest.classpath}:\
+ ${file.reference.commons-compress-1.18.jar}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
@@ -92,8 +95,10 @@
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
+project.hayashi=../../../../../mnt/hayashi/workspace/hayashi
project.hayashi-1=../../../../mnt/hayashi/workspace/hayashi
reference.hayashi-1.jar=${project.hayashi-1}/dist/hayashi.jar
+reference.hayashi.jar=${project.hayashi}/dist/hayashi.jar
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
diff --git a/nbproject/project.xml b/nbproject/project.xml
index eb3081e..e93cc6a 100644
--- a/nbproject/project.xml
+++ b/nbproject/project.xml
@@ -14,6 +14,14 @@
+ hayashi
+ jar
+
+ jar
+ clean
+ jar
+
+
hayashi-1
jar
diff --git a/src/osm/jp/api/Osmdb.java b/src/osm/jp/api/Osmdb.java
index f9709d9..d07cc49 100644
--- a/src/osm/jp/api/Osmdb.java
+++ b/src/osm/jp/api/Osmdb.java
@@ -579,8 +579,8 @@
LineNumberReader reader = new LineNumberReader(
new InputStreamReader(new FileInputStream(revovedFile))
);
- while (reader.readLine() != null) {
- String lineStr = reader.readLine();
+ String lineStr;
+ while ((lineStr = reader.readLine()) != null) {
if (lineStr == null) {
continue;
}
diff --git a/test/P11-10.removed.json.txt b/test/P11-10.removed.json.txt
new file mode 100644
index 0000000..ecc16db
--- /dev/null
+++ b/test/P11-10.removed.json.txt
@@ -0,0 +1,12 @@
+{"gmlid":"n12211","idref":"","area":1}
+{"gmlid":"n6515","idref":"","area":12}
+{"gmlid":"n6517","idref":"","area":12}
+{"gmlid":"n3247","idref":"","area":14}
+{"gmlid":"n3248","idref":"","area":14}
+{"gmlid":"n3249","idref":"","area":14}
+{"gmlid":"n4281","idref":"","area":14}
+{"gmlid":"n4425","idref":"","area":14}
+{"gmlid":"n4445","idref":"","area":14}
+{"gmlid":"n6924","idref":"","area":14}
+{"gmlid":"n4439","idref":"","area":27}
+{"gmlid":"n4441","idref":"","area":27}
diff --git a/test/data/GML_BUSSTOP.tar.gz b/test/data/GML_BUSSTOP.tar.gz
new file mode 100644
index 0000000..902123f
--- /dev/null
+++ b/test/data/GML_BUSSTOP.tar.gz
Binary files differ
diff --git a/test/data/GML_FUEL.tar.gz b/test/data/GML_FUEL.tar.gz
new file mode 100644
index 0000000..16d0d4a
--- /dev/null
+++ b/test/data/GML_FUEL.tar.gz
Binary files differ
diff --git a/test/data/GML_POLICE.tar.gz b/test/data/GML_POLICE.tar.gz
new file mode 100644
index 0000000..0beee9a
--- /dev/null
+++ b/test/data/GML_POLICE.tar.gz
Binary files differ
diff --git a/test/data/GML_POSTOFFICE.tar.gz b/test/data/GML_POSTOFFICE.tar.gz
new file mode 100644
index 0000000..fad0786
--- /dev/null
+++ b/test/data/GML_POSTOFFICE.tar.gz
Binary files differ
diff --git a/test/data/P11-10.removed.json.txt b/test/data/P11-10.removed.json.txt
new file mode 100644
index 0000000..ecc16db
--- /dev/null
+++ b/test/data/P11-10.removed.json.txt
@@ -0,0 +1,12 @@
+{"gmlid":"n12211","idref":"","area":1}
+{"gmlid":"n6515","idref":"","area":12}
+{"gmlid":"n6517","idref":"","area":12}
+{"gmlid":"n3247","idref":"","area":14}
+{"gmlid":"n3248","idref":"","area":14}
+{"gmlid":"n3249","idref":"","area":14}
+{"gmlid":"n4281","idref":"","area":14}
+{"gmlid":"n4425","idref":"","area":14}
+{"gmlid":"n4445","idref":"","area":14}
+{"gmlid":"n6924","idref":"","area":14}
+{"gmlid":"n4439","idref":"","area":27}
+{"gmlid":"n4441","idref":"","area":27}
diff --git a/test/database.properties b/test/database.properties
new file mode 100644
index 0000000..e66e66c
--- /dev/null
+++ b/test/database.properties
@@ -0,0 +1,4 @@
+db_driver=org.hsqldb.jdbcDriver
+db_url=jdbc:hsqldb:file:./database/db
+db_user=sa
+db_passwd=
diff --git a/test/osm/jp/coverage/busstop/DbBusstopTest.java b/test/osm/jp/coverage/busstop/DbBusstopTest.java
index 76988af..780ee51 100644
--- a/test/osm/jp/coverage/busstop/DbBusstopTest.java
+++ b/test/osm/jp/coverage/busstop/DbBusstopTest.java
@@ -1,16 +1,23 @@
package osm.jp.coverage.busstop;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
import java.sql.Connection;
import jp.co.areaweb.tools.database.DatabaseTool;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
+import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import osm.jp.coverage.DbTest;
+import tools.Compless;
+import tools.Copy;
@FixMethodOrder (MethodSorters.NAME_ASCENDING)
public class DbBusstopTest {
@@ -18,6 +25,22 @@
String tableName = "busstop";
/**
+ * Folder[GML_BUSSTOP]がなければ作る
+ * tar xvf
+ *
+ * @throws Exception
+ */
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ String gmlFolderName = "GML_BUSSTOP";
+ File gmlDir = new File(gmlFolderName);
+ if (!gmlDir.exists()) {
+ File tgzFile = new File("data", "GML_BUSSTOP.tar.gz");
+ Compless.uncomplessTarGz(new File("."), tgzFile);
+ }
+ }
+
+ /**
* コマンド引数チェック
*
* @throws Exception
@@ -132,9 +155,8 @@
@Test
public void t30_main_removed() throws Exception {
File file = new File("GML_BUSSTOP", "P11-10.removed.json.txt");
- try (FileWriter fw = new FileWriter(file)) {
- fw.write("");
- fw.flush();
+ if (!file.exists()) {
+ Copy.copyFile(new File("data","P11-10.removed.json.txt"), file); // Apache common-io
}
try {
@@ -145,10 +167,11 @@
fail(e.toString());
}
+ int tableCount;
try (Connection hsqldb = DatabaseTool.openDb(databaseName)) {
- int cnt = DbTest.getRecordCount(hsqldb, tableName, "REMOVED=TRUE");
- System.out.println("'FUEL REMOVED=TRUE' table count = " + cnt);
- assertThat(cnt > 0, is(true));
+ tableCount = DbTest.getRecordCount(hsqldb, tableName, "REMOVED=TRUE");
+ System.out.println("'FUEL REMOVED=TRUE' table count = " + tableCount);
+ assertThat(tableCount, is(12));
}
catch (Exception e) {
fail(e.toString());
@@ -162,7 +185,8 @@
*/
@Test
public void t40_main_output() throws Exception {
- int cnt = 0;
+ String fileName = "P11-10.removed.json.txt";
+ int cnt;
try (Connection hsqldb = DatabaseTool.openDb(databaseName)) {
cnt = DbTest.getRecordCount(hsqldb, tableName, "REMOVED=TRUE");
System.out.println("'BUSSTOP REMOVED=TRUE' table count = " + cnt);
@@ -172,12 +196,15 @@
}
try {
- String[] args = new String[]{"-OUTPUT", "P11-10.removed.json.txt"};
+ String[] args = new String[]{"-OUTPUT", fileName};
DbBusstop.main(args);
}
catch(Exception e) {
fail(e.toString());
}
+
+ File file = new File(fileName);
+ assertThat(getFileLineCount(file), is(12));
}
/**
@@ -187,16 +214,28 @@
*/
@Test
public void t41_main_output() throws Exception {
- File file = new File("P11-10.removed.json.txt");
+ File file = new File("GML_BUSSTOP","P11-10.removed.json.txt");
assertThat(file.exists(), is(true));
try (Connection hsqldb = DatabaseTool.openDb(databaseName)) {
int cnt1 = DbTest.getRecordCount(hsqldb, tableName, "REMOVED=TRUE");
System.out.println("'BUSSTOP REMOVED=TRUE' table count = " + cnt1);
- assertThat(cnt1 > 0, is(true));
+ assertThat(cnt1, is(12));
}
catch (Exception e) {
fail(e.toString());
}
+ assertThat(getFileLineCount(file), is(12));
+ }
+
+ int getFileLineCount(File file) throws FileNotFoundException, IOException {
+ LineNumberReader reader = new LineNumberReader(
+ new InputStreamReader(new FileInputStream(file))
+ );
+ int cnt = 0;
+ while (reader.readLine() != null) {
+ cnt++;
+ }
+ return cnt;
}
}
diff --git a/test/osmdb.properties b/test/osmdb.properties
new file mode 100644
index 0000000..8c3ebe6
--- /dev/null
+++ b/test/osmdb.properties
@@ -0,0 +1,4 @@
+db_driver=org.postgresql.Driver
+db_url=jdbc:postgresql://localhost:5432/gis
+db_user=alex
+db_passwd=password
diff --git a/test/postgis.properties b/test/postgis.properties
new file mode 100644
index 0000000..04ba2fe
--- /dev/null
+++ b/test/postgis.properties
@@ -0,0 +1,4 @@
+db_driver=org.postgresql.Driver
+db_url=jdbc:postgresql://surveyor.mydns.jp:5432/gisdb
+db_user=gisuser
+db_passwd=gisuser
diff --git a/test/tools/Compless.java b/test/tools/Compless.java
new file mode 100644
index 0000000..45ef5eb
--- /dev/null
+++ b/test/tools/Compless.java
@@ -0,0 +1,57 @@
+package tools;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.zip.GZIPInputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+
+public class Compless {
+
+ /**
+ * `.tar.gz`形式のファイルを指定のディレクトリにuncompless
+ *
+ * @param outDir
+ * @param gzipFile
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
+ public static void uncomplessTarGz(File outDir, File gzipFile) throws FileNotFoundException, IOException {
+ try (FileInputStream fis = new FileInputStream(gzipFile)) {
+ try (GZIPInputStream gis = new GZIPInputStream(fis)) {
+ try (TarArchiveInputStream tis = new TarArchiveInputStream(gis)) {
+ for (TarArchiveEntry entry = tis.getNextTarEntry(); entry != null; entry = tis.getNextTarEntry()) {
+ if (entry.isDirectory()) {
+ File newDir = new File(outDir, entry.getName());
+ try {
+ newDir.mkdirs();
+ }
+ catch(Exception e) {
+ throw new IOException("directory '" + newDir.getAbsolutePath() + "' cannot create.");
+ }
+ }
+ else {
+ File newfile = new File(outDir, entry.getName());
+ File parentDir = newfile.getParentFile();
+ try {
+ parentDir.mkdirs();
+ }
+ catch(Exception e) {
+ throw new IOException("directory '" + parentDir.getAbsolutePath() + "' cannot create.");
+ }
+ try (FileOutputStream fos = new FileOutputStream(newfile)) {
+ IOUtils.copy(tis, fos); // Apache common-io
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+}
diff --git a/test/tools/Copy.java b/test/tools/Copy.java
new file mode 100644
index 0000000..fc8aec0
--- /dev/null
+++ b/test/tools/Copy.java
@@ -0,0 +1,23 @@
+package tools;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class Copy {
+
+ /**
+ * ファイルをコピーする
+ *
+ * @param source
+ * @param dest
+ * @throws IOException
+ */
+ public static void copyFile(File source, File dest) throws IOException {
+ Path sourcePath = Paths.get(source.getAbsolutePath());
+ Path targetPath = Paths.get(dest.getAbsolutePath());
+ Files.copy(sourcePath, targetPath);
+ }
+}