diff --git a/src/police.activity.violet.html b/src/police.activity.violet.html index b834f43..a01d0bc 100644 --- a/src/police.activity.violet.html +++ b/src/police.activity.violet.html @@ -133,7 +133,7 @@ DbExistPolice.main() OSMからPOLICEのノードを読み取って -HSQLDB.POLICE_EXISTテーブルに格納する +HSQLDB.OSM_EXISTテーブルに格納する @@ -899,1041 +899,1039 @@ ]]>

- embedded diagram image + embedded diagram image \ No newline at end of file diff --git a/test/osm/jp/coverage/fuel/DbExistTest.java b/test/osm/jp/coverage/fuel/DbExistTest.java index 849e49d..80ca038 100644 --- a/test/osm/jp/coverage/fuel/DbExistTest.java +++ b/test/osm/jp/coverage/fuel/DbExistTest.java @@ -237,8 +237,8 @@ boolean checkRenge(double d1, String str) throws SQLException { double base = Double.parseDouble(str); - double up = d1 + 0.0000005D; - double down = d1 - 0.0000005D; + double up = d1 + 0.0001D; + double down = d1 - 0.0001D; boolean ret = true; if (Double.compare(base, up) > 0) { ret = false; diff --git a/test/osm/jp/coverage/police/DbExistTest.java b/test/osm/jp/coverage/police/DbExistTest.java index 59c2b2c..c69a303 100644 --- a/test/osm/jp/coverage/police/DbExistTest.java +++ b/test/osm/jp/coverage/police/DbExistTest.java @@ -13,7 +13,6 @@ import org.junit.*; import static org.junit.Assert.*; import org.junit.runners.MethodSorters; -import static osm.jp.api.Osmdb.create; @FixMethodOrder (MethodSorters.NAME_ASCENDING) public class DbExistTest { diff --git a/test/osm/jp/coverage/postoffice/AllTest.java b/test/osm/jp/coverage/postoffice/AllTest.java new file mode 100644 index 0000000..9c14a5a --- /dev/null +++ b/test/osm/jp/coverage/postoffice/AllTest.java @@ -0,0 +1,38 @@ +package osm.jp.coverage.postoffice; + +import java.io.File; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + DbPostofficeTest.class, + DbExistTest.class, + PostofficeTest.class +}) +public class AllTest { + + @BeforeClass + public static void setUpClass() throws Exception { + File dir = new File("database"); + dir.deleteOnExit(); + dir.mkdir(); + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + +} diff --git a/test/osm/jp/coverage/postoffice/DbExistTest.java b/test/osm/jp/coverage/postoffice/DbExistTest.java index 3ad33f9..1d70be5 100644 --- a/test/osm/jp/coverage/postoffice/DbExistTest.java +++ b/test/osm/jp/coverage/postoffice/DbExistTest.java @@ -12,24 +12,17 @@ import static org.hamcrest.CoreMatchers.is; import org.junit.*; import static org.junit.Assert.*; +import org.junit.runners.MethodSorters; import static osm.jp.api.Osmdb.create; /** * * @author yuu */ +@FixMethodOrder (MethodSorters.NAME_ASCENDING) public class DbExistTest { @Before public void setUp() throws Exception { - File dir = new File("database"); - if (dir.exists()) { - if (dir.isDirectory()) { - dir.deleteOnExit(); - } - else { - throw new Exception("'database' is not directory."); - } - } } @After @@ -37,21 +30,34 @@ } @Test - public void test01_hsqldbの生成確認() { + public void test00_hsqldbの生成確認() { Connection con = null; try { + File dir = new File("database"); + if (dir.exists()) { + if (dir.isDirectory()) { + dir.deleteOnExit(); + } + else { + throw new Exception("'database' is not directory."); + } + } + // DB.tableを作成 con = DatabaseTool.openDb("database"); create(con); } - catch (ClassNotFoundException | SQLException | IOException ex) { - fail(); + catch (Exception ex) { + fail(ex.toString()); } finally { if (con != null) { DatabaseTool.closeDb(con); } } + } + @Test + public void test01_hsqldbの生成確認() { File dir = new File("database"); assertTrue(dir.exists()); assertTrue(dir.isDirectory()); @@ -99,7 +105,10 @@ catch (Exception ex) { fail(ex.toString()); } - + } + + @Test + public void test03_check() { File dir = new File("database"); assertTrue(dir.exists()); assertTrue(dir.isDirectory()); @@ -130,12 +139,48 @@ } } + // ノード: 綾瀬郵便局 (1420831800) 場所: 35.4470975, 139.4159210 + ps1 = hsqldb.prepareStatement("SELECT score,name,lat,lon FROM OSM_EXIST where idref='1420831800'"); + try (ResultSet rset1 = ps1.executeQuery()) { + if (rset1.next()) { + assertThat(rset1.getInt("score"), is(50)); + assertTrue(checkRenge(rset1, "35.4470975", "139.4159210")); + } + else { + fail(); + } + } + // ノード: 蒲田駅前郵便局 (1420797282) 場所: 35.5629710, 139.7145174 ps1 = hsqldb.prepareStatement("SELECT score,name,lat,lon FROM OSM_EXIST where idref='1420797282'"); try (ResultSet rset1 = ps1.executeQuery()) { if (rset1.next()) { assertThat(rset1.getInt("score"), is(50)); - assertThat(checkRenge(rset1, "35.5629710", "139.7145174"), is(true)); + assertTrue(checkRenge(rset1, "35.5629710", "139.7145174")); + } + else { + fail(); + } + } + + // ウェイ: 世田谷郵便局 (50810596) 場所: 35.6402036, 139.6678386 + ps1 = hsqldb.prepareStatement("SELECT score,name,lat,lon FROM OSM_EXIST where idref='50810596'"); + try (ResultSet rset1 = ps1.executeQuery()) { + if (rset1.next()) { + assertThat(rset1.getInt("score"), is(50)); + assertTrue(checkRenge(rset1, "35.6402036", "139.6678386")); + } + else { + fail(); + } + } + + // disused:amenity=post_office ノード: 南大和郵便局 (1420814864) 場所: 35.4714005, 139.4649291 + ps1 = hsqldb.prepareStatement("SELECT score,name,lat,lon FROM OSM_EXIST where idref='1420814864'"); + try (ResultSet rset1 = ps1.executeQuery()) { + if (rset1.next()) { + assertThat(rset1.getInt("score"), is(50)); + assertTrue(checkRenge(rset1, "35.4714005", "139.4649291")); } else { fail(); @@ -161,8 +206,8 @@ boolean checkRenge(double d1, String str) throws SQLException { double base = Double.parseDouble(str); - double up = d1 + 0.0000005D; - double down = d1 - 0.0000005D; + double up = d1 + 0.0001D; + double down = d1 - 0.0001D; boolean ret = true; if (Double.compare(base, up) > 0) { ret = false; diff --git a/test/osm/jp/coverage/postoffice/DbPostofficeTest.java b/test/osm/jp/coverage/postoffice/DbPostofficeTest.java index 8890430..b56d823 100644 --- a/test/osm/jp/coverage/postoffice/DbPostofficeTest.java +++ b/test/osm/jp/coverage/postoffice/DbPostofficeTest.java @@ -12,11 +12,13 @@ import static org.hamcrest.CoreMatchers.is; import org.junit.*; import static org.junit.Assert.*; +import org.junit.runners.MethodSorters; /** * * @author yuu */ +@FixMethodOrder (MethodSorters.NAME_ASCENDING) public class DbPostofficeTest { @Before public void setUp() throws Exception { @@ -27,7 +29,8 @@ } @Test - public void test02_postoffice() { + @SuppressWarnings("UseSpecificCatch") + public void test01_postoffice() { try { String[] args = new String[0]; DbPostoffice.main(args); @@ -35,7 +38,10 @@ catch (Exception ex) { fail(ex.toString()); } - + } + + @Test + public void test02_postoffice() { File dir = new File("database"); assertTrue(dir.exists()); assertTrue(dir.isDirectory()); @@ -116,7 +122,6 @@ fail(); } } - } catch (ClassNotFoundException | SQLException | IOException ex) { Logger.getLogger(DbPostofficeTest.class.getName()).log(Level.SEVERE, null, ex); fail(); diff --git a/test/osm/jp/coverage/postoffice/PostofficeTest.java b/test/osm/jp/coverage/postoffice/PostofficeTest.java new file mode 100644 index 0000000..abd5064 --- /dev/null +++ b/test/osm/jp/coverage/postoffice/PostofficeTest.java @@ -0,0 +1,138 @@ +package osm.jp.coverage.postoffice; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; +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 osm.jp.api.HttpPOST; + +@FixMethodOrder (MethodSorters.NAME_ASCENDING) +public class PostofficeTest { + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + @SuppressWarnings("UseSpecificCatch") + public void test00_Postoffice_main() { + + String[] args = new String[0]; + try { + Postoffice.main(args); + } catch (Exception ex) { + Logger.getLogger(PostofficeTest.class.getName()).log(Level.SEVERE, null, ex); + fail(ex.toString()); + } + } + + /** + * OSM: ノード: 国分寺台郵便局 (1420826283) 場所: 35.4316208, 139.4094861 + * GML: 14, n16243 35.431653 139.409527 + */ + @Test + public void test01_dataread() { + double lat = 35.4316208D; // 35.43035 35.4316208, 139.4094861 + double lon = 139.4094861D; //139.36622 + String idrefs = getRefid(lat, lon, 50); + System.out.println(idrefs); + } + + /** + * OSM: なし + * GML: 1, n24526 gml:id="po24526" name=岬町簡易郵便局 場所: 44.105486 145.246918 + */ + @Test + public void test92_normal() { + double lat = 44.105486D; + double lon = 145.246918D; + String idrefs = getRefid(lat, lon, 0); + System.out.println(idrefs); + } + + boolean checkRenge(ResultSet rset, String latStr, String lonStr) throws SQLException { + if (checkRenge(rset.getDouble("lat"), latStr)) { + if (checkRenge(rset.getDouble("lon"), lonStr)) { + return true; + } + } + return false; + } + + boolean checkRenge(double d1, String str) throws SQLException { + double base = Double.parseDouble(str); + double up = d1 + 0.0001D; + double down = d1 - 0.0001D; + boolean ret = true; + if (Double.compare(base, up) > 0) { + ret = false; + } + if (Double.compare(base, down) < 0) { + ret = false; + } + System.out.println("d1: "+ d1 +" : "+ str +" --> "+ (ret ? "IN" : "out")); + return ret; + } + + /** + * + * + * @param lat 35.43035D; // 35.43035 35.4305614, 139.3662339 + * @param lon 139.36622D + * @param fixed1 + * @return + */ + public String getRefid(double lat, double lon, int fixed1) { + String ret = ""; + + Connection hsqldb = null; + try { + hsqldb = DatabaseTool.openDb("database"); + + String where = String.format("(lat > '%s') and (lat < '%s') and (lon > '%s') and (lon < '%s')", + String.valueOf(lat-0.001D), String.valueOf(lat+0.001D), + String.valueOf(lon-0.001D), String.valueOf(lon+0.001D)); + String sql = String.format("SELECT * FROM %s WHERE %s", DbPostoffice.TABLE_NAME, where); + System.out.println(sql); + PreparedStatement ps1 = hsqldb.prepareStatement(sql); + try (ResultSet rset1 = ps1.executeQuery()) { + while (rset1.next()) { + int v = rset1.getInt("fixed1"); + System.out.println("{"); + System.out.println("idref:" + rset1.getString("idref")); + System.out.println("gid:" + rset1.getString("gid")); + System.out.println("area:" + rset1.getInt("area")); + System.out.println("fixed:" + rset1.getInt("fixed")); + System.out.println("fixed1:" + v); + System.out.println("lat:" + rset1.getDouble("lat")); + System.out.println("lon:" + rset1.getDouble("lon")); + System.out.println("}"); + if (ret.length() > 0) { + ret += ","; + } + ret += rset1.getString("idref"); + assertThat(v, is(fixed1)); + return ret; + } + fail("該当のデータがミツカラナイ"); + } + } catch (IOException | ClassNotFoundException | SQLException ex) { + Logger.getLogger(PostofficeTest.class.getName()).log(Level.SEVERE, null, ex); + fail(ex.toString()); + } finally { + DatabaseTool.closeDb(hsqldb); + } + return ret; + } +}