| |
---|
| | 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 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 |
---|
| | public void tearDown() throws Exception { |
---|
| | } |
---|
| | |
---|
| | @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()); |
---|
| | |
---|
| |
---|
| | } |
---|
| | catch (Exception ex) { |
---|
| | fail(ex.toString()); |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | @Test |
---|
| | public void test03_check() { |
---|
| | File dir = new File("database"); |
---|
| | assertTrue(dir.exists()); |
---|
| | assertTrue(dir.isDirectory()); |
---|
| | |
---|
| |
---|
| | fail(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | // ノード: 綾瀬郵便局 (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(); |
---|
| | } |
---|
| |
---|
| | } |
---|
| | |
---|
| | 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; |
---|
| | } |
---|
| |
---|
| | |