diff --git a/test/data/pbfDate.json b/test/data/pbfDate.json new file mode 100755 index 0000000..f8c4ae5 --- /dev/null +++ b/test/data/pbfDate.json @@ -0,0 +1 @@ +{"date": "2016-12-25"} diff --git a/test/osm/jp/coverage/DbTest.java b/test/osm/jp/coverage/DbTest.java index 8afdfc4..bda03aa 100644 --- a/test/osm/jp/coverage/DbTest.java +++ b/test/osm/jp/coverage/DbTest.java @@ -190,7 +190,7 @@ } } catch (SQLException e) { - e.printStackTrace(); + fail(e.toString()); } } diff --git a/test/osm/jp/coverage/PostgresqlTest.java b/test/osm/jp/coverage/PostgresqlTest.java index 79e22f8..d2080e5 100644 --- a/test/osm/jp/coverage/PostgresqlTest.java +++ b/test/osm/jp/coverage/PostgresqlTest.java @@ -1,13 +1,10 @@ package osm.jp.coverage; -import java.io.File; import java.sql.Connection; 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; @@ -37,6 +34,7 @@ /** * postgresql `postgis.properties` + * postgresql - PostGIS : gisdb */ @Test public void connectTest_postgis() { @@ -44,7 +42,17 @@ } /** + * postgresql `database.properties` + * HSQLDB.database + */ + @Test + public void connectTest_database() { + connect("database"); + } + + /** * postgresql `osmdb.properties` + * postgresql - PostGIS : postgis * ``` * docker run --name=postgis -d * -e POSTGRES_USER=alex diff --git a/test/osm/jp/coverage/busstop/BusstopTest.java b/test/osm/jp/coverage/busstop/BusstopTest.java index d6d8c15..699b8e6 100644 --- a/test/osm/jp/coverage/busstop/BusstopTest.java +++ b/test/osm/jp/coverage/busstop/BusstopTest.java @@ -264,9 +264,9 @@ if ((name != null) && !name.trim().isEmpty()) { score = 50; } - String gmlid = null; - int area = 0; - int fixed1 = 0; + String gmlid; + int area; + int fixed1; // 指定の緯度経度を中心とする半径200x2m四方の矩形領域 assertTrue(lat > 20.0D); @@ -330,7 +330,7 @@ * @throws Exception */ @Test - public void t40_main_output() throws Exception { + public void test40_main_output() throws Exception { int cnt = 0; String databaseName = "database"; String tableName = "busstop"; @@ -344,14 +344,14 @@ } try { - String[] args = new String[]{"-OUTPUT", "GML_BUSSTOP/P11-10.removed.json.txt"}; + String[] args = new String[]{"-OUTPUT", "P11-10.removed.json.txt"}; DbBusstop.main(args); } catch(Exception e) { fail(e.toString()); } - File file = new File("GML_BUSSTOP", "P11-10.removed.json.txt"); + File file = new File("P11-10.removed.json.txt"); assertThat(file.exists(), is(true)); try (Connection hsqldb = DatabaseTool.openDb(databaseName)) { diff --git a/test/osm/jp/coverage/busstop/CoverageTest.java b/test/osm/jp/coverage/busstop/CoverageTest.java index 4352c00..b9aec58 100644 --- a/test/osm/jp/coverage/busstop/CoverageTest.java +++ b/test/osm/jp/coverage/busstop/CoverageTest.java @@ -1,26 +1,142 @@ 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 { + @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")); + } + + @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 { - String[] args = new String[]{"outputfile.csv"}; + String[] args = new String[]{}; Coverage.main(args); } catch (IOException | ClassNotFoundException | SQLException | ParserConfigurationException | TransformerException | SAXException e) { - e.printStackTrace(); - fail(); + 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()); + } + } } diff --git a/test/osm/jp/coverage/busstop/ToPostgisTest.java b/test/osm/jp/coverage/busstop/ToPostgisTest.java index a1609f7..305ccd2 100644 --- a/test/osm/jp/coverage/busstop/ToPostgisTest.java +++ b/test/osm/jp/coverage/busstop/ToPostgisTest.java @@ -13,8 +13,7 @@ ToPostgis.main(argv); } catch (Exception e) { - e.printStackTrace(); - fail(); + fail(e.getMessage()); } }