diff --git a/src/osm/jp/coverage/busstop/Busstop.java b/src/osm/jp/coverage/busstop/Busstop.java index 1ee3df2..a96fc48 100644 --- a/src/osm/jp/coverage/busstop/Busstop.java +++ b/src/osm/jp/coverage/busstop/Busstop.java @@ -37,6 +37,12 @@ * @throws ParserConfigurationException */ public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException, TransformerException { + // HSQLディレクトリがなければ作る + File dbdir = new File("database"); + if (!dbdir.isDirectory()) { + dbdir.mkdir(); + } + Connection con = DatabaseTool.openDb("database"); try { new Busstop(con); diff --git a/test/osm/jp/coverage/busstop/BusstopTest.java b/test/osm/jp/coverage/busstop/BusstopTest.java new file mode 100644 index 0000000..f27082d --- /dev/null +++ b/test/osm/jp/coverage/busstop/BusstopTest.java @@ -0,0 +1,160 @@ +package osm.jp.coverage.busstop; + +import java.io.File; +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 javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; +import jp.co.areaweb.tools.database.DatabaseTool; +import static org.hamcrest.CoreMatchers.is; +import org.junit.*; +import static org.junit.Assert.*; +import org.xml.sax.SAXException; +import static osm.jp.api.Osmdb.create; + +/** + * + * @author yuu + */ +public class BusstopTest { + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test02_busstop() { + try { + String[] args = new String[0]; + DbExistBusstop.main(args); + DbBusstop.main(args); + Busstop.main(args); + } + catch (Exception ex) { + fail(ex.toString()); + } + + File dir = new File("database"); + assertTrue(dir.exists()); + assertTrue(dir.isDirectory()); + + Connection hsqldb = null; + try { + hsqldb = DatabaseTool.openDb("database"); + + PreparedStatement ps1 = hsqldb.prepareStatement("SELECT count(*) FROM OSM_EXIST"); + try (ResultSet rset1 = ps1.executeQuery()) { + if (rset1.next()) { + long cnt = rset1.getLong(1); + assertThat((cnt > 0), is(true)); + } + else { + fail(); + } + } + + // ノード: 八幡前 (3152604023) 場所: 33.9808001, 133.3123441 fixme有り + ps1 = hsqldb.prepareStatement("SELECT score,name,lat,lon FROM OSM_EXIST where idref='3152604023'"); + try (ResultSet rset1 = ps1.executeQuery()) { + if (rset1.next()) { + // fixme有り + assertThat(rset1.getInt("score"), is(1)); + assertThat(checkRenge(rset1, "33.9808001", "133.3123441"), is(true)); + } + else { + fail(); + } + } + + // ノード: 4940018338 場所: 35.5909251, 139.1498642 highway=bus_stop, name=null, bus=null,public_transport=platform + ps1 = hsqldb.prepareStatement("SELECT score,name,lat,lon FROM OSM_EXIST where idref='4940018338'"); + try (ResultSet rset1 = ps1.executeQuery()) { + if (rset1.next()) { + // nameなし + assertThat(rset1.getInt("score"), is(1)); + assertThat(checkRenge(rset1, "35.5909251", "139.1498642"), is(true)); + } + else { + fail(); + } + } + + // ノード: 海老名高校前 (2043102034) 場所: 35.4435042, 139.3878934 highway=bus_stop + ps1 = hsqldb.prepareStatement("SELECT score,name,lat,lon FROM OSM_EXIST where idref='2043102034'"); + try (ResultSet rset1 = ps1.executeQuery()) { + if (rset1.next()) { + assertThat(rset1.getInt("score"), is(50)); + assertThat(checkRenge(rset1, "35.4435042", "139.3878934"), is(true)); + } + else { + fail(); + } + } + + // ノード: 厚木ナイロン (1995040609) 場所: 35.4433312, 139.3932098 public_transport=stop_position,bus=yes + ps1 = hsqldb.prepareStatement("SELECT score,name,lat,lon FROM OSM_EXIST where idref='1995040609'"); + try (ResultSet rset1 = ps1.executeQuery()) { + if (rset1.next()) { + assertThat(rset1.getInt("score"), is(50)); + assertThat(checkRenge(rset1, "35.4433312", "139.3932098"), is(true)); + } + else { + fail(); + } + } + + // ウェイ: 国分寺台第12 (154659062) bus_station + ps1 = hsqldb.prepareStatement("SELECT score,name,lat,lon FROM OSM_EXIST where idref='154659062'"); + try (ResultSet rset1 = ps1.executeQuery()) { + if (rset1.next()) { + assertThat(rset1.getInt("score"), is(50)); + } + else { + fail(); + } + } + + } catch (ClassNotFoundException ex) { + Logger.getLogger(BusstopTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(BusstopTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(BusstopTest.class.getName()).log(Level.SEVERE, null, ex); + } finally { + DatabaseTool.closeDb(hsqldb); + } + } + + 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.00000009D; + double down = d1 - 0.00000009D; + 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; + } +} diff --git a/test/osm/jp/coverage/newSQLTemplate.sql b/test/osm/jp/coverage/newSQLTemplate.sql new file mode 100644 index 0000000..63c980c --- /dev/null +++ b/test/osm/jp/coverage/newSQLTemplate.sql @@ -0,0 +1,10 @@ +sudo curl --user yuu:yuu8844 -O http://192.168.0.26:8080/job/osmCoverage_FuelTile/lastSuccessfulBuild/artifact/tileFuel0.tgz +sudo curl --user yuu:yuu8844 -O http://192.168.0.26:8080/job/osmCoverage_FuelTile/lastSuccessfulBuild/artifact/tileFuel1.tgz +sudo curl --user yuu:yuu8844 -O http://192.168.0.26:8080/job/osmCoverage_FuelTile/lastSuccessfulBuild/artifact/tileFuel2.tgz +sudo rm -rf tileFuel0 +sudo rm -rf tileFuel1 +sudo rm -rf tileFuel2 +sudo tar zxvf tileFuel0.tgz +sudo tar zxvf tileFuel1.tgz +sudo tar zxvf tileFuel2.tgz +