diff --git a/dist/lib/hayashi.jar b/dist/lib/hayashi.jar index 3adbe8a..54090a3 100644 --- a/dist/lib/hayashi.jar +++ b/dist/lib/hayashi.jar Binary files differ diff --git a/src/osm/jp/api/OsmExist.java b/src/osm/jp/api/OsmExist.java index f52b680..dbac962 100644 --- a/src/osm/jp/api/OsmExist.java +++ b/src/osm/jp/api/OsmExist.java @@ -2,6 +2,7 @@ import java.io.*; import java.sql.Connection; +import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -18,6 +19,49 @@ super(hsqldb, tableName); } + /** + * 'HSQLDB.table.OSM_EXIST'を新規に作る + * 'HSQLDB.table.AREA_NODE'を新規に作る + * 既にテーブルが存在する時にはERROR + * @throws SQLException + */ + @Override + public void create() throws SQLException { + String createSt; + + sql("DROP TABLE IF EXISTS "+ tableName +" CASCADE"); + sql("DROP INDEX IF EXISTS "+ tableName +"_index;"); + sql("DROP TABLE IF EXISTS AREA_NODE CASCADE"); + + // 'table.OSM_EXIST'を新規に作る + createSt = "CREATE TABLE "+ tableName + + " (" + + "idref VARCHAR(12) NOT NULL, " + + "name VARCHAR(128), " + + "lat DOUBLE, " + + "lon DOUBLE, " + + "score INT, " + + "gmlid VARCHAR(12), " + + "area INT, " + + "PRIMARY KEY(idref), " + + "removed BOOLEAN DEFAULT FALSE NOT NULL" + + ");"; + Db.updateSQL(hsqldb, createSt); + createSt = "CREATE INDEX "+ tableName +"_index ON "+ tableName + + " (lat, lon);"; + Db.updateSQL(hsqldb, createSt); + + // 'table.AREA_NODE'を新規に作る + createSt = "CREATE TABLE AREA_NODE " + + "(" + + "idref VARCHAR(12) NOT NULL, " + + "pid VARCHAR(12), " + + "lat DOUBLE, " + + "lon DOUBLE" + + ");"; + Db.updateSQL(hsqldb, createSt); + } + /* Test data: ノード: エネオス (2015835273) 場所: 35.4367770, 139.403571TABLE_NAME0 diff --git a/src/osm/jp/api/Osmdb.java b/src/osm/jp/api/Osmdb.java index d07cc49..ad965c1 100644 --- a/src/osm/jp/api/Osmdb.java +++ b/src/osm/jp/api/Osmdb.java @@ -22,62 +22,19 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import osm.jp.coverage.busstop.DbBusstop; public abstract class Osmdb { - public String TABLE_NAME = "EXIST_osm"; - public String tableName = TABLE_NAME; - public Connection hsqldb = null; // hsqldb DatabaseTool.openDb("database"); + public String tableName; + public Connection hsqldb = null; // hsqldb DatabaseTool.openDb("database"); + public Osmdb(Connection hsqldb, String tableName) { this.hsqldb = hsqldb; - if (tableName != null) { - this.tableName = tableName; - } + this.tableName = tableName; } - - /** - * 'HSQLDB.table.OSM_EXIST'を新規に作る - * 'HSQLDB.table.AREA_NODE'を新規に作る - * 既にテーブルが存在する時にはERROR - * @throws SQLException - */ - public void create() throws SQLException { - String createSt; + + abstract public void create() throws SQLException; - sql("DROP TABLE IF EXISTS "+ tableName +" CASCADE"); - sql("DROP INDEX IF EXISTS "+ tableName +"_index;"); - sql("DROP TABLE IF EXISTS AREA_NODE CASCADE"); - - // 'table.OSM_EXIST'を新規に作る - createSt = "CREATE TABLE "+ tableName - + " (" - + "idref VARCHAR(12) NOT NULL, " - + "name VARCHAR(128), " - + "lat DOUBLE, " - + "lon DOUBLE, " - + "score INT, " - + "gmlid VARCHAR(12), " - + "area INT, " - + "PRIMARY KEY(idref), " - + "removed BOOLEAN DEFAULT FALSE NOT NULL" - + ");"; - Db.updateSQL(hsqldb, createSt); - createSt = "CREATE INDEX "+ tableName +"_index ON "+ tableName - + " (lat, lon);"; - Db.updateSQL(hsqldb, createSt); - - // 'table.AREA_NODE'を新規に作る - createSt = "CREATE TABLE AREA_NODE " - + "(" - + "idref VARCHAR(12) NOT NULL, " - + "pid VARCHAR(12), " - + "lat DOUBLE, " - + "lon DOUBLE" - + ");"; - Db.updateSQL(hsqldb, createSt); - } - void sql(String sql) throws SQLException { System.out.println(sql); try (PreparedStatement ps = hsqldb.prepareStatement(sql)) { @@ -610,7 +567,7 @@ */ public void outputRemoved(File removedFile) throws SQLException, IOException { String whereStr = "WHERE (removed=?)"; - String fromStr = "FROM "+ DbBusstop.TABLE_NAME; + String fromStr = "FROM "+ tableName; String sortStr = "ORDER BY area,gmlid"; String sql = String.format("SELECT * %s %s %s", fromStr, whereStr, sortStr); diff --git a/src/osm/jp/coverage/busstop/DbBusstop.java b/src/osm/jp/coverage/busstop/DbBusstop.java index 8cc5da9..1455baa 100644 --- a/src/osm/jp/coverage/busstop/DbBusstop.java +++ b/src/osm/jp/coverage/busstop/DbBusstop.java @@ -20,7 +20,7 @@ public class DbBusstop extends Osmdb { @SuppressWarnings("FieldNameHidesFieldInSuperclass") - public static final String TABLE_NAME = "busstop"; + public static String TABLE_NAME = "busstop"; public static final String CLASS_NAME = "DbBusstop"; /** diff --git a/src/osm/jp/coverage/busstop/DbExistBusstop.java b/src/osm/jp/coverage/busstop/DbExistBusstop.java index 1921e81..6dcd71a 100644 --- a/src/osm/jp/coverage/busstop/DbExistBusstop.java +++ b/src/osm/jp/coverage/busstop/DbExistBusstop.java @@ -13,9 +13,9 @@ import java.sql.SQLException; import jp.co.areaweb.tools.database.*; -import osm.jp.api.Osmdb; +import osm.jp.api.OsmExist; -public class DbExistBusstop extends Osmdb { +public class DbExistBusstop extends OsmExist { @SuppressWarnings("FieldNameHidesFieldInSuperclass") public static final String TABLE_NAME = "BUSSTOP_EXIST"; public static final String CLASS_NAME = "DbExistFuel"; @@ -101,7 +101,7 @@ public DbExistBusstop(Connection hsqldb) { super(hsqldb, DbExistBusstop.TABLE_NAME); } - + /** * *
{@code
diff --git a/src/osm/jp/coverage/fuel/DbExistFuel.java b/src/osm/jp/coverage/fuel/DbExistFuel.java
index 7179c84..aaa3520 100644
--- a/src/osm/jp/coverage/fuel/DbExistFuel.java
+++ b/src/osm/jp/coverage/fuel/DbExistFuel.java
@@ -4,9 +4,9 @@
import java.io.FileNotFoundException;
import java.sql.Connection;
import jp.co.areaweb.tools.database.*;
-import osm.jp.api.Osmdb;
+import osm.jp.api.OsmExist;
-public class DbExistFuel extends Osmdb {
+public class DbExistFuel extends OsmExist {
@SuppressWarnings("FieldNameHidesFieldInSuperclass")
public static final String TABLE_NAME = "FUEL_EXIST";
public static final String CLASS_NAME = "DbExistFuel";
diff --git a/src/osm/jp/coverage/fuel/DbFuel.java b/src/osm/jp/coverage/fuel/DbFuel.java
index 752388c..aee0f42 100644
--- a/src/osm/jp/coverage/fuel/DbFuel.java
+++ b/src/osm/jp/coverage/fuel/DbFuel.java
@@ -19,7 +19,7 @@
public class DbFuel extends Osmdb {
@SuppressWarnings("FieldNameHidesFieldInSuperclass")
- public static final String TABLE_NAME = "FUEL";
+ public static String TABLE_NAME = "FUEL";
public static final String CLASS_NAME = "DbFuel";
/** メイン
diff --git a/src/osm/jp/coverage/fuel/OsmExistFuel.java b/src/osm/jp/coverage/fuel/OsmExistFuel.java
index 63dfbc9..c0aa614 100644
--- a/src/osm/jp/coverage/fuel/OsmExistFuel.java
+++ b/src/osm/jp/coverage/fuel/OsmExistFuel.java
@@ -51,5 +51,4 @@
public OsmExistFuel(Connection hsqldb) {
super(hsqldb, DbExistFuel.TABLE_NAME);
}
-
}
\ No newline at end of file
diff --git a/src/osm/jp/coverage/police/DbExistPolice.java b/src/osm/jp/coverage/police/DbExistPolice.java
index dbe89e8..c7c25d0 100644
--- a/src/osm/jp/coverage/police/DbExistPolice.java
+++ b/src/osm/jp/coverage/police/DbExistPolice.java
@@ -1,10 +1,11 @@
package osm.jp.coverage.police;
import java.sql.Connection;
+import java.sql.SQLException;
import jp.co.areaweb.tools.database.*;
-import osm.jp.api.Osmdb;
+import osm.jp.api.OsmExist;
-public class DbExistPolice extends Osmdb {
+public class DbExistPolice extends OsmExist {
public static final String EXIST_TABLE_NAME = "POLICE_EXIST";
/** メイン
@@ -37,7 +38,7 @@
public DbExistPolice(Connection hsqldb) {
super(hsqldb, EXIST_TABLE_NAME);
}
-
+
/*
Test data:
diff --git a/src/osm/jp/coverage/postoffice/DbExistPostoffice.java b/src/osm/jp/coverage/postoffice/DbExistPostoffice.java
index 97fe203..945ab2b 100644
--- a/src/osm/jp/coverage/postoffice/DbExistPostoffice.java
+++ b/src/osm/jp/coverage/postoffice/DbExistPostoffice.java
@@ -1,10 +1,11 @@
package osm.jp.coverage.postoffice;
import java.sql.Connection;
+import java.sql.SQLException;
import jp.co.areaweb.tools.database.*;
-import osm.jp.api.Osmdb;
+import osm.jp.api.OsmExist;
-public class DbExistPostoffice extends Osmdb {
+public class DbExistPostoffice extends OsmExist {
public static final String EXIST_TABLE_NAME = "POSTOFFICE_EXIST";
/** メイン
diff --git a/test/osm/jp/coverage/CoverageTest.java b/test/osm/jp/coverage/CoverageTest.java
new file mode 100644
index 0000000..ce427a3
--- /dev/null
+++ b/test/osm/jp/coverage/CoverageTest.java
@@ -0,0 +1,129 @@
+package osm.jp.coverage;
+
+import hayashi.tools.files.DeleteDir;
+import hayashi.yuu.tools.json.JsonTool;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import javax.json.JsonArray;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonValue;
+import javax.json.JsonValue.ValueType;
+import jp.co.areaweb.tools.csv.CsvFile;
+import jp.co.areaweb.tools.csv.CsvRecord;
+import static org.hamcrest.CoreMatchers.is;
+import org.junit.AfterClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.junit.BeforeClass;
+import tools.Compless;
+import tools.Copy;
+
+public abstract class CoverageTest {
+ public static String gmlFolderName = "GML_";
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+
+ File gmlDir = new File(gmlFolderName);
+ if (!gmlDir.exists()) {
+ File tgzFile = new File("data", gmlFolderName +".tar.gz");
+ Compless.uncomplessTarGz(new File("."), tgzFile);
+ }
+ Copy.copyFile(new File("data", "pbfDate.json"), new File(gmlDir, "pbfDate.json"));
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ DeleteDir.delete(new File(gmlFolderName));
+ }
+
+ @Test
+ @SuppressWarnings("UseSpecificCatch")
+ public static void testCoverage_main() {
+ File outDir = new File(gmlFolderName);
+
+ File out1 = new File(outDir, "coverage.csv");
+ assertNotNull(out1);
+ assertTrue(out1.exists());
+ assertTrue(out1.isFile());
+ try {
+ CsvFile csv = new CsvFile(out1);
+ csv.setCharsetName("utf-8");
+ csv.load();
+ assertThat(csv.size(), is(49));
+ int num = -1;
+ for (CsvRecord line : csv) {
+ if (num == -1) {
+ assertThat(line.get(0), is("コード"));
+ assertThat(line.get(1), is("都道府県"));
+ assertThat(line.get(2), is("母数"));
+ assertThat(line.get(3), is("入力数"));
+ assertThat(line.get(4), is("率(%)"));
+ }
+ else {
+ assertThat(line.get(0), is(String.valueOf(num)));
+ String vStr = line.get(4);
+ double v = Double.valueOf(vStr);
+ assertTrue(v > 0.0D);
+ assertTrue(v <= 100.0D);
+ }
+ num++;
+ }
+ }
+ catch (Exception e) {
+ fail(e.toString());
+ }
+
+ File out2 = new File(outDir, "coverage.json");
+ assertNotNull(out2);
+ assertTrue(out2.exists());
+ assertTrue(out2.isFile());
+ try {
+ LineNumberReader reader = new LineNumberReader(
+ new InputStreamReader(new FileInputStream(out2), "utf-8")
+ );
+ String content = "";
+ String str;
+ while ((str = reader.readLine()) != null) {
+ content += str;
+ }
+ JsonObject json = JsonTool.parse(content);
+
+ String vstr = json.getString("timestamp");
+ assertNotNull(vstr);
+ assertThat(vstr.length() > 0, is(true));
+
+ vstr = json.getString("sourcedata");
+ assertNotNull(vstr);
+ //assertThat(vstr, is("国土数値情報 バス停留所データ 平成22年"));
+
+ JsonArray arry = json.getJsonArray("coverage");
+ assertNotNull(arry);
+ assertThat(arry.size(), is(48));
+ int i = 0;
+ for (JsonValue v : arry) {
+ assertThat(v.getValueType(), is(ValueType.OBJECT));
+ JsonObject obj = (JsonObject)v;
+
+ int code = obj.getInt("code");
+ assertThat(code, is(i));
+ JsonNumber par = obj.getJsonNumber("par");
+ assertNotNull(par);
+
+ double pard = par.doubleValue();
+ assertTrue(pard > 0.0D);
+ assertTrue(pard <= 100.0D);
+ i++;
+ }
+
+ }
+ catch (Exception e) {
+ fail(e.toString());
+ }
+
+ }
+
+}
diff --git a/test/osm/jp/coverage/DbTest.java b/test/osm/jp/coverage/DbTest.java
index bda03aa..7e489be 100644
--- a/test/osm/jp/coverage/DbTest.java
+++ b/test/osm/jp/coverage/DbTest.java
@@ -1,78 +1,39 @@
package osm.jp.coverage;
+import hayashi.tools.files.DeleteDir;
import java.io.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import javax.xml.parsers.ParserConfigurationException;
-
import jp.co.areaweb.tools.database.*;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.xml.sax.SAXException;
-import osm.jp.api.HttpPOST;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+import static osm.jp.coverage.fuel.DbFuelTest.gmlFolderName;
+import tools.Compless;
-public class DbTest {
+@FixMethodOrder (MethodSorters.NAME_ASCENDING)
+public abstract class DbTest {
public static final String TABLE_NAME = "test";
-
- File inputFile;
- String filter = "";
- int iCounter = 0;
- String urlStr = "";
- Connection con;
- String timeStampStr = null;
- File dir = null;
-
- /** メイン
- * 動作条件; HSQLDBのフォルダを削除した状態で実行すること。
- * @param args
- * @throws IOException
- * @throws SQLException
- * @throws ClassNotFoundException
- * @throws FileNotFoundException
- * @throws javax.xml.parsers.ParserConfigurationException
- * @throws org.xml.sax.SAXException */
- public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException, IOException, SQLException, ParserConfigurationException, SAXException
- {
- // HSQLディレクトリがなければエラー
- File dbdir = new File("database");
- if (!dbdir.isDirectory()) {
- throw new FileNotFoundException("Directory 'database' is not found.");
- }
-
- Connection conHsql = null;
- try {
- conHsql = DatabaseTool.openDb("database");
- HttpPOST hsql = new HttpPOST(conHsql, null);
- hsql.sql("DROP TABLE IF EXISTS "+ TABLE_NAME +" CASCADE");
- //HttpPOST.sql(conHsql, "DROP INDEX "+ TABLE_NAME +"_index;");
- create(conHsql);
- try (PreparedStatement ps = conHsql.prepareStatement("DELETE FROM "+ TABLE_NAME)) {
- ps.executeUpdate();
- }
-
- // 対象のファイルが「数値地図情報のGMLデータファイル」の時のみ処理を行う。
- importTest(conHsql, 14);
-
- DbTest.export(conHsql);
- }
- finally {
- if (conHsql != null) {
- DatabaseTool.closeDb(conHsql);
- }
- }
- }
+ public static String gmlFolderName = "GML_";
@BeforeClass
public static void setUpClass() throws Exception {
+ File gmlDir = new File(gmlFolderName);
+ if (!gmlDir.exists()) {
+ File tgzFile = new File("data", gmlFolderName + ".tar.gz");
+ Compless.uncomplessTarGz(new File("."), tgzFile);
+ }
}
@AfterClass
public static void tearDownClass() throws Exception {
+ DeleteDir.delete(new File(gmlFolderName));
}
@Before
@@ -82,52 +43,6 @@
@After
public void tearDown() throws Exception {
}
-
-
- /**
- * 数値地図情報のGMLデータファイルを読み取ってローカルベータベースへ記録する
- * @param conHsql
- * @param areacode
- * @throws FileNotFoundException
- * @throws ClassNotFoundException
- * @throws SQLException
- * @throws IOException
- * @throws ParserConfigurationException
- * @throws SAXException
- */
- public static void importTest (Connection conHsql, int areacode) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
- int iCounter = 0;
- iCounter += showNodes(conHsql, areacode);
- System.out.println("("+ areacode +") Node数["+ iCounter +"]");
- }
-
- static final double CENTER_LAT = 35.4342443D;
- static final double CENTER_LON = 139.4092180D;
- static final int LOOP = 50;
- static final double SIDE = 0.015D;
-
- /**
- * ノード: 綾西 (368434484) 35.4342443, 139.4092180
- *
- * @param con
- * @param areacode
- * @return
- * @throws IOException
- * @throws SQLException
- */
- public static int showNodes(Connection con, int areacode) throws IOException, SQLException {
- int iCounter = 0;
- double lon = CENTER_LON - SIDE;
- for (int x = 0; x <= LOOP; x++) {
- double lat = CENTER_LAT - SIDE;
- for (int y = 0; y <= LOOP; y++) {
- showGmlPoint(con, lat, lon, areacode, iCounter++);
- lat += SIDE * 2 / LOOP;
- }
- lon += SIDE * 2 / LOOP;
- }
- return iCounter;
- }
/**
*
@@ -149,25 +64,6 @@
}
}
-
- /**
- * 'table.BUSSTOP'を新規に作る
- * 既にテーブルが存在する時には何もしない
- * @param conHsql
- * @throws SQLException
- */
- public static void create(Connection conHsql) throws SQLException {
- String createSt;
- HttpPOST hsql = new HttpPOST(conHsql, null);
-
- // 'table.TEST'を新規に作る
- createSt = "CREATE TABLE "+ TABLE_NAME +" (gmlid VARCHAR(12) NOT NULL, name VARCHAR(128), lat DOUBLE, lon DOUBLE, fixed INT, fixed1 INT, area INT, ifile VARCHAR(128), up INT, CONSTRAINT "+ TABLE_NAME +"_pk PRIMARY KEY(gmlid, area));";
- hsql.sql(createSt);
-
- createSt = "CREATE INDEX "+ TABLE_NAME +"_index ON "+ TABLE_NAME +" (lat,lon);";
- hsql.sql(createSt);
- }
-
/**
* 'table.BUSSTOP'の内容をCSV形式にして標準出力に出力する
* @param con
@@ -317,7 +213,19 @@
if (Double.compare(base, down) < 0) {
ret = false;
}
- System.out.println("d1: "+ d1 +" : "+ str +" --> "+ (ret ? "IN" : "out"));
+ //System.out.println("d1: "+ d1 +" : "+ str +" --> "+ (ret ? "IN" : "out"));
return ret;
}
+
+ public static 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;
+ }
+
}
\ No newline at end of file
diff --git a/test/osm/jp/coverage/PoiTest.java b/test/osm/jp/coverage/PoiTest.java
index e21aa7f..58fa1ba 100644
--- a/test/osm/jp/coverage/PoiTest.java
+++ b/test/osm/jp/coverage/PoiTest.java
@@ -13,7 +13,7 @@
import static org.junit.Assert.fail;
import osm.jp.coverage.postoffice.PostofficeTest;
-public class PoiTest {
+public abstract class PoiTest {
/**
* 許容できる誤差は 0.00000009D 固定
diff --git a/test/osm/jp/coverage/busstop/CoverageTest.java b/test/osm/jp/coverage/busstop/CoverageTest.java
index b9aec58..ebadfb2 100644
--- a/test/osm/jp/coverage/busstop/CoverageTest.java
+++ b/test/osm/jp/coverage/busstop/CoverageTest.java
@@ -1,51 +1,25 @@
package osm.jp.coverage.busstop;
-import hayashi.tools.files.DeleteDir;
-import hayashi.yuu.tools.json.JsonTool;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
import java.sql.SQLException;
-import javax.json.JsonArray;
-import javax.json.JsonNumber;
-import javax.json.JsonObject;
-import javax.json.JsonValue;
-import javax.json.JsonValue.ValueType;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
-import jp.co.areaweb.tools.csv.CsvFile;
-import jp.co.areaweb.tools.csv.CsvRecord;
-import static org.hamcrest.CoreMatchers.is;
-import org.junit.AfterClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.xml.sax.SAXException;
-import tools.Compless;
-import tools.Copy;
-public class CoverageTest {
+public class CoverageTest extends osm.jp.coverage.CoverageTest {
+ @SuppressWarnings("FieldNameHidesFieldInSuperclass")
+ static String gmlFolderName = "GML_BUSSTOP";
@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);
- }
- Copy.copyFile(new File("data", "pbfDate.json"), new File(gmlDir, "pbfDate.json"));
+ osm.jp.coverage.CoverageTest.gmlFolderName = gmlFolderName;
+ osm.jp.coverage.CoverageTest.setUpClass();
}
- @AfterClass
- public static void tearDownClass() throws Exception {
- DeleteDir.delete(new File("GML_BUSSTOP"));
- }
-
@Test
- @SuppressWarnings("UseSpecificCatch")
public void testBusstopCoverage_main() {
System.out.println("testBusstopCoverage_main");
try {
@@ -56,87 +30,7 @@
fail(e.toString());
}
- File outDir = new File("GML_BUSSTOP");
-
- File out1 = new File(outDir, "coverage.busstop.csv");
- assertNotNull(out1);
- assertTrue(out1.exists());
- assertTrue(out1.isFile());
- try {
- CsvFile csv = new CsvFile(out1);
- csv.setCharsetName("utf-8");
- csv.load();
- assertThat(csv.size(), is(49));
- int num = -1;
- for (CsvRecord line : csv) {
- if (num == -1) {
- assertThat(line.get(0), is("コード"));
- assertThat(line.get(1), is("都道府県"));
- assertThat(line.get(2), is("母数"));
- assertThat(line.get(3), is("入力数"));
- assertThat(line.get(4), is("率(%)"));
- }
- else {
- assertThat(line.get(0), is(String.valueOf(num)));
- String vStr = line.get(4);
- double v = Double.valueOf(vStr);
- assertTrue(v > 0.0D);
- assertTrue(v <= 100.0D);
- }
- num++;
- }
- }
- catch (Exception e) {
- fail(e.toString());
- }
-
- File out2 = new File(outDir, "coverage.busstop.json");
- assertNotNull(out2);
- assertTrue(out2.exists());
- assertTrue(out2.isFile());
- try {
- LineNumberReader reader = new LineNumberReader(
- new InputStreamReader(new FileInputStream(out2), "utf-8")
- );
- String content = "";
- String str;
- while ((str = reader.readLine()) != null) {
- content += str;
- }
- JsonObject json = JsonTool.parse(content);
-
- String vstr = json.getString("timestamp");
- assertNotNull(vstr);
- assertThat(vstr.length() > 0, is(true));
-
- vstr = json.getString("sourcedata");
- assertNotNull(vstr);
- assertThat(vstr, is("国土数値情報 バス停留所データ 平成22年"));
-
- JsonArray arry = json.getJsonArray("coverage");
- assertNotNull(arry);
- assertThat(arry.size(), is(48));
- int i = 0;
- for (JsonValue v : arry) {
- assertThat(v.getValueType(), is(ValueType.OBJECT));
- JsonObject obj = (JsonObject)v;
-
- int code = obj.getInt("code");
- assertThat(code, is(i));
- JsonNumber par = obj.getJsonNumber("par");
- assertNotNull(par);
-
- double pard = par.doubleValue();
- assertTrue(pard > 0.0D);
- assertTrue(pard <= 100.0D);
- i++;
- }
-
- }
- catch (Exception e) {
- fail(e.toString());
- }
-
+ osm.jp.coverage.CoverageTest.testCoverage_main();
}
}
diff --git a/test/osm/jp/coverage/busstop/DbBusstopTest.java b/test/osm/jp/coverage/busstop/DbBusstopTest.java
index 28ab80c..c34afcc 100644
--- a/test/osm/jp/coverage/busstop/DbBusstopTest.java
+++ b/test/osm/jp/coverage/busstop/DbBusstopTest.java
@@ -2,11 +2,6 @@
import hayashi.tools.files.DeleteDir;
import java.io.File;
-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;
@@ -18,13 +13,17 @@
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 {
+public class DbBusstopTest extends DbTest {
+ @SuppressWarnings("FieldNameHidesFieldInSuperclass")
+ public static String gmlFolderName = "GML_BUSSTOP";
+
String databaseName = "database";
String tableName = "busstop";
+ static final int REMOVED_COUNT = 12;
+ static final String REMOVED_FILE_NAME = "P11-10.removed.json.txt";
/**
* Folder[GML_BUSSTOP]がなければ作る
@@ -34,18 +33,23 @@
*/
@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);
- }
+ DbTest.gmlFolderName = gmlFolderName;
+ DbTest.setUpClass();
+
+ Copy.copyFile(
+ new File("data", REMOVED_FILE_NAME),
+ new File(gmlFolderName, REMOVED_FILE_NAME)
+ );
}
@AfterClass
public static void tearDownClass() throws Exception {
- DeleteDir.delete(new File("GML_BUSSTOP"));
- DeleteDir.delete(new File("P11-10.removed.json.txt"));
+ DbTest.gmlFolderName = gmlFolderName;
+ DbTest.tearDownClass();
+ File file = new File(REMOVED_FILE_NAME);
+ if (file.exists()) {
+ DeleteDir.delete(file);
+ }
}
/**
@@ -134,7 +138,7 @@
@Test
public void t25_main_import() throws Exception {
try {
- String[] args = new String[]{"-IMPORT", "GML_BUSSTOP"};
+ String[] args = new String[]{"-IMPORT", gmlFolderName};
DbBusstop.main(args);
}
catch(Exception e) {
@@ -162,13 +166,13 @@
*/
@Test
public void t30_main_removed() throws Exception {
- File file = new File("GML_BUSSTOP", "P11-10.removed.json.txt");
+ File file = new File(gmlFolderName, REMOVED_FILE_NAME);
if (!file.exists()) {
- Copy.copyFile(new File("data","P11-10.removed.json.txt"), file); // Apache common-io
+ Copy.copyFile(new File("data",REMOVED_FILE_NAME), file); // Apache common-io
}
try {
- String[] args = new String[]{"-REMOVED", "GML_BUSSTOP/P11-10.removed.json.txt"};
+ String[] args = new String[]{"-REMOVED", gmlFolderName +"/"+ REMOVED_FILE_NAME};
DbBusstop.main(args);
}
catch(Exception e) {
@@ -179,7 +183,7 @@
try (Connection hsqldb = DatabaseTool.openDb(databaseName)) {
tableCount = DbTest.getRecordCount(hsqldb, tableName, "REMOVED=TRUE");
System.out.println("'FUEL REMOVED=TRUE' table count = " + tableCount);
- assertThat(tableCount, is(12));
+ assertThat(tableCount, is(REMOVED_COUNT));
}
catch (Exception e) {
fail(e.toString());
@@ -212,7 +216,7 @@
}
File file = new File(fileName);
- assertThat(getFileLineCount(file), is(12));
+ assertThat(getFileLineCount(file), is(REMOVED_COUNT));
}
/**
@@ -222,28 +226,18 @@
*/
@Test
public void t41_main_output() throws Exception {
- File file = new File("GML_BUSSTOP","P11-10.removed.json.txt");
+ File file = new File("GML_BUSSTOP",REMOVED_FILE_NAME);
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, is(12));
+ assertThat(cnt1, is(REMOVED_COUNT));
}
catch (Exception e) {
fail(e.toString());
}
- assertThat(getFileLineCount(file), is(12));
+ assertThat(getFileLineCount(file), is(REMOVED_COUNT));
}
- 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/osm/jp/coverage/fuel/CoverageTest.java b/test/osm/jp/coverage/fuel/CoverageTest.java
index 8284b7a..a99805d 100644
--- a/test/osm/jp/coverage/fuel/CoverageTest.java
+++ b/test/osm/jp/coverage/fuel/CoverageTest.java
@@ -1,25 +1,32 @@
package osm.jp.coverage.fuel;
-import java.io.IOException;
-import java.sql.SQLException;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
import org.junit.Test;
import static org.junit.Assert.*;
-import org.xml.sax.SAXException;
+import org.junit.BeforeClass;
public class CoverageTest {
+ @SuppressWarnings("FieldNameHidesFieldInSuperclass")
+ static String gmlFolderName = "GML_FUEL";
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ osm.jp.coverage.CoverageTest.gmlFolderName = gmlFolderName;
+ osm.jp.coverage.CoverageTest.setUpClass();
+ }
@Test
- public void testMain() throws Exception {
+ @SuppressWarnings("UseSpecificCatch")
+ public void testFuelCoverage_main() throws Exception {
try {
- System.out.println("main");
- String[] args = new String[0];
+ System.out.println("testFuelCoverage_main");
+ String[] args = new String[]{};
Coverage.main(args);
}
- catch (IOException | ClassNotFoundException | SQLException | ParserConfigurationException | TransformerException | SAXException e) {
+ catch (Exception e) {
fail("The test case is a prototype.");
}
+
+ osm.jp.coverage.CoverageTest.testCoverage_main();
}
}
diff --git a/test/osm/jp/coverage/fuel/DbExistTest.java b/test/osm/jp/coverage/fuel/DbExistTest.java
index f69b13e..7dca265 100644
--- a/test/osm/jp/coverage/fuel/DbExistTest.java
+++ b/test/osm/jp/coverage/fuel/DbExistTest.java
@@ -18,14 +18,6 @@
@FixMethodOrder (MethodSorters.NAME_ASCENDING)
public class DbExistTest {
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
String databaseName = "database";
String tableName = "FUEL_EXIST";
diff --git a/test/osm/jp/coverage/fuel/DbFuelTest.java b/test/osm/jp/coverage/fuel/DbFuelTest.java
index 13cde83..0f043a1 100644
--- a/test/osm/jp/coverage/fuel/DbFuelTest.java
+++ b/test/osm/jp/coverage/fuel/DbFuelTest.java
@@ -1,42 +1,52 @@
package osm.jp.coverage.fuel;
+import hayashi.tools.files.DeleteDir;
+import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import jp.co.areaweb.tools.database.DatabaseTool;
import static org.hamcrest.CoreMatchers.is;
-import org.junit.After;
import org.junit.AfterClass;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
-import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import osm.jp.coverage.DbTest;
+import tools.Copy;
@FixMethodOrder (MethodSorters.NAME_ASCENDING)
-public class DbFuelTest {
+public class DbFuelTest extends DbTest {
@BeforeClass
public static void setUpClass() throws Exception {
+ DbTest.gmlFolderName = gmlFolderName;
+ DbTest.setUpClass();
+ Copy.copyFile(
+ new File("data", REMOVED_FILE_NAME),
+ new File(gmlFolderName, REMOVED_FILE_NAME)
+ );
}
@AfterClass
public static void tearDownClass() throws Exception {
+ DbTest.gmlFolderName = gmlFolderName;
+ DbTest.tearDownClass();
+ File file = new File(REMOVED_FILE_NAME);
+ if (file.exists()) {
+ DeleteDir.delete(file);
+ }
}
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
+ @SuppressWarnings("FieldNameHidesFieldInSuperclass")
+ public static String gmlFolderName = "GML_FUEL";
String databaseName = "database";
String tableName = "FUEL";
+ static final int REMOVED_COUNT = 46;
+ static final String REMOVED_FILE_NAME = "P07-15.removed.json.txt";
/**
* コマンド引数チェック
@@ -124,7 +134,7 @@
@Test
public void t25_main_import() throws Exception {
try {
- String[] args = new String[]{"-IMPORT", "GML_FUEL"};
+ String[] args = new String[]{"-IMPORT", gmlFolderName};
DbFuel.main(args);
}
catch(Exception e) {
@@ -152,8 +162,13 @@
*/
@Test
public void t30_main_removed() throws Exception {
+ File file = new File(gmlFolderName, REMOVED_FILE_NAME);
+ if (!file.exists()) {
+ Copy.copyFile(new File("data", REMOVED_FILE_NAME), file); // Apache common-io
+ }
+
try {
- String[] args = new String[]{"-REMOVED", "GML_FUEL/P07-15.removed.json.txt"};
+ String[] args = new String[]{"-REMOVED", gmlFolderName +"/" + REMOVED_FILE_NAME};
DbFuel.main(args);
}
catch(Exception e) {
@@ -163,7 +178,7 @@
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 > 10, is(true));
+ assertThat(cnt, is(REMOVED_COUNT));
}
catch (Exception e) {
fail(e.toString());
@@ -178,7 +193,7 @@
@Test
public void t40_main_output() throws Exception {
try {
- String[] args = new String[]{"-OUTPUT", "GML_FUEL/P07-15.removed.txt"};
+ String[] args = new String[]{"-OUTPUT", gmlFolderName +"/"+ REMOVED_FILE_NAME};
DbFuel.main(args);
}
catch(Exception e) {
@@ -188,18 +203,33 @@
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 > 10, is(true));
+ assertThat(cnt, is(REMOVED_COUNT));
// 35.5955359, 139.5096330
// node: "removed:amenity=fuel" (5338111023) https://www.openstreetmap.org/node/5338111023
// ノード: removed (5338111023) 場所: 35.4305614, 139.3662339
- PreparedStatement ps1 = hsqldb.prepareStatement("SELECT * FROM " + tableName);
+ PreparedStatement ps1 = hsqldb.prepareStatement(
+ String.format("SELECT * FROM %s", tableName)
+ );
try (ResultSet rset1 = ps1.executeQuery()) {
while (rset1.next()) {
if (DbTest.checkRenge(rset1, "35.5955359", "139.5096330", 0.001D)) {
String gmlid = rset1.getString("gmlid");
+ System.out.print("\t");
+ assertNotNull(gmlid);
+ System.out.print(gmlid);
+
String idref = rset1.getString("idref");
- boolean rmd = rset1.getBoolean("removed");
+ assertNotNull(idref);
+ System.out.print("\t");
+ System.out.print(idref);
+ //assertThat(rset1.getString("idref"), is("5338111023"));
+
+ boolean removed = rset1.getBoolean("removed");
+ System.out.print("\t");
+ System.out.print(removed);
+ assertThat(removed, is(true));
+
System.out.println();
}
}
@@ -208,6 +238,7 @@
catch (Exception e) {
fail(e.toString());
}
+ assertThat(getFileLineCount(new File(gmlFolderName, REMOVED_FILE_NAME)), is(REMOVED_COUNT));
}
/**
diff --git a/test/osm/jp/coverage/fuel/FuelTest.java b/test/osm/jp/coverage/fuel/FuelTest.java
index 311e110..0e33186 100644
--- a/test/osm/jp/coverage/fuel/FuelTest.java
+++ b/test/osm/jp/coverage/fuel/FuelTest.java
@@ -14,7 +14,7 @@
import osm.jp.coverage.PoiTest;
@FixMethodOrder (MethodSorters.NAME_ASCENDING)
-public class FuelTest extends PoiTest{
+public class FuelTest extends PoiTest {
@Before
public void setUp() throws Exception {
}
@@ -91,7 +91,6 @@
}
}
catch(Exception e){
- e.printStackTrace();
fail(e.toString());
} finally {
DatabaseTool.closeDb(hsqldb);
diff --git a/test/osm/jp/coverage/police/Coverage2Test.java b/test/osm/jp/coverage/police/Coverage2Test.java
index f3694a4..abf1cd7 100644
--- a/test/osm/jp/coverage/police/Coverage2Test.java
+++ b/test/osm/jp/coverage/police/Coverage2Test.java
@@ -6,14 +6,19 @@
import javax.xml.transform.TransformerException;
import org.junit.Test;
import static org.junit.Assert.*;
+import org.junit.BeforeClass;
import org.xml.sax.SAXException;
-/**
- *
- * @author yuu
- */
public class Coverage2Test {
-
+ @SuppressWarnings("FieldNameHidesFieldInSuperclass")
+ static String gmlFolderName = "GML_POLICE";
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ osm.jp.coverage.CoverageTest.gmlFolderName = gmlFolderName;
+ osm.jp.coverage.CoverageTest.setUpClass();
+ }
+
@Test
public void testMain() {
System.out.println("Coverage2Test");
@@ -24,6 +29,8 @@
catch (IOException | ClassNotFoundException | SQLException | ParserConfigurationException | TransformerException | SAXException e) {
fail("The test case is a prototype.");
}
+
+ osm.jp.coverage.CoverageTest.testCoverage_main();
}
}
diff --git a/test/osm/jp/coverage/police/Coverage4Test.java b/test/osm/jp/coverage/police/Coverage4Test.java
index 6013127..e1392b5 100644
--- a/test/osm/jp/coverage/police/Coverage4Test.java
+++ b/test/osm/jp/coverage/police/Coverage4Test.java
@@ -6,13 +6,18 @@
import javax.xml.transform.TransformerException;
import org.junit.Test;
import static org.junit.Assert.*;
+import org.junit.BeforeClass;
import org.xml.sax.SAXException;
-/**
- *
- * @author yuu
- */
public class Coverage4Test {
+ @SuppressWarnings("FieldNameHidesFieldInSuperclass")
+ static String gmlFolderName = "GML_POLICE";
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ osm.jp.coverage.CoverageTest.gmlFolderName = gmlFolderName;
+ osm.jp.coverage.CoverageTest.setUpClass();
+ }
@Test
public void testMain() {
@@ -24,6 +29,8 @@
catch (IOException | ClassNotFoundException | SQLException | ParserConfigurationException | TransformerException | SAXException e) {
fail("The test case is a prototype.");
}
+
+ osm.jp.coverage.CoverageTest.testCoverage_main();
}
}
diff --git a/test/osm/jp/coverage/police/Coverage5Test.java b/test/osm/jp/coverage/police/Coverage5Test.java
index a829520..c998e8d 100644
--- a/test/osm/jp/coverage/police/Coverage5Test.java
+++ b/test/osm/jp/coverage/police/Coverage5Test.java
@@ -6,13 +6,18 @@
import javax.xml.transform.TransformerException;
import org.junit.Test;
import static org.junit.Assert.*;
+import org.junit.BeforeClass;
import org.xml.sax.SAXException;
-/**
- *
- * @author yuu
- */
public class Coverage5Test {
+ @SuppressWarnings("FieldNameHidesFieldInSuperclass")
+ static String gmlFolderName = "GML_POLICE";
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ osm.jp.coverage.CoverageTest.gmlFolderName = gmlFolderName;
+ osm.jp.coverage.CoverageTest.setUpClass();
+ }
@Test
public void testMain() {
@@ -24,6 +29,8 @@
catch (IOException | ClassNotFoundException | SQLException | ParserConfigurationException | TransformerException | SAXException e) {
fail("The test case is a prototype.");
}
+
+ osm.jp.coverage.CoverageTest.testCoverage_main();
}
}
diff --git a/test/osm/jp/coverage/police/Coverage6Test.java b/test/osm/jp/coverage/police/Coverage6Test.java
index b2f9deb..1d56fb6 100644
--- a/test/osm/jp/coverage/police/Coverage6Test.java
+++ b/test/osm/jp/coverage/police/Coverage6Test.java
@@ -6,6 +6,7 @@
import javax.xml.transform.TransformerException;
import org.junit.Test;
import static org.junit.Assert.*;
+import org.junit.BeforeClass;
import org.xml.sax.SAXException;
/**
@@ -13,6 +14,14 @@
* @author yuu
*/
public class Coverage6Test {
+ @SuppressWarnings("FieldNameHidesFieldInSuperclass")
+ static String gmlFolderName = "GML_POLICE";
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ osm.jp.coverage.CoverageTest.gmlFolderName = gmlFolderName;
+ osm.jp.coverage.CoverageTest.setUpClass();
+ }
@Test
public void testMain() {
@@ -24,6 +33,8 @@
catch (IOException | ClassNotFoundException | SQLException | ParserConfigurationException | TransformerException | SAXException e) {
fail("The test case is a prototype.");
}
+
+ osm.jp.coverage.CoverageTest.testCoverage_main();
}
}
diff --git a/test/osm/jp/coverage/police/DbPoliceTest.java b/test/osm/jp/coverage/police/DbPoliceTest.java
index fb02c8a..40cb663 100644
--- a/test/osm/jp/coverage/police/DbPoliceTest.java
+++ b/test/osm/jp/coverage/police/DbPoliceTest.java
@@ -8,13 +8,11 @@
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.xml.parsers.ParserConfigurationException;
import jp.co.areaweb.tools.database.DatabaseTool;
import static org.hamcrest.CoreMatchers.is;
import org.junit.*;
import static org.junit.Assert.*;
import org.junit.runners.MethodSorters;
-import org.xml.sax.SAXException;
/**
*
@@ -36,8 +34,7 @@
String[] args = new String[0];
DbPolice.main(args);
}
- catch (IOException | ClassNotFoundException | SQLException | ParserConfigurationException | SAXException ex) {
- ex.printStackTrace();
+ catch (Exception ex) {
fail(ex.toString());
}
diff --git a/test/osm/jp/coverage/postoffice/CoverageTest.java b/test/osm/jp/coverage/postoffice/CoverageTest.java
index 6ea2d63..3296ec3 100644
--- a/test/osm/jp/coverage/postoffice/CoverageTest.java
+++ b/test/osm/jp/coverage/postoffice/CoverageTest.java
@@ -1,25 +1,32 @@
package osm.jp.coverage.postoffice;
-import java.io.IOException;
-import java.sql.SQLException;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
import org.junit.Test;
import static org.junit.Assert.*;
-import org.xml.sax.SAXException;
+import org.junit.BeforeClass;
public class CoverageTest {
+ @SuppressWarnings("FieldNameHidesFieldInSuperclass")
+ static String gmlFolderName = "GML_POSTOFFICE";
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ osm.jp.coverage.CoverageTest.gmlFolderName = gmlFolderName;
+ osm.jp.coverage.CoverageTest.setUpClass();
+ }
+
@Test
+ @SuppressWarnings("UseSpecificCatch")
public void testMain() {
try {
System.out.println("main");
String[] args = new String[0];
Coverage.main(args);
}
- catch (IOException | ClassNotFoundException | SQLException | ParserConfigurationException | TransformerException | SAXException e) {
- fail("The test case is a prototype.");
+ catch (Exception e) {
+ fail(e.toString());
}
+
+ osm.jp.coverage.CoverageTest.testCoverage_main();
}
}