- package osm.jp.coverage.busstop;
-
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import javax.json.Json;
- import javax.json.JsonArrayBuilder;
- import javax.json.JsonBuilderFactory;
- import javax.json.JsonObject;
- import javax.json.JsonObjectBuilder;
- 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.POINT_BUS_NO;
- import static osm.jp.api.Osmdb.POINT_FIXME;
- import static osm.jp.api.Osmdb.POINT_NO_NAME;
- import osm.jp.coverage.DbTest;
-
- /**
- *
- * @author yuu
- */
- @FixMethodOrder (MethodSorters.NAME_ASCENDING)
- public class DbExistBusstopTest {
- String databaseName = "database";
- String tableName = "BUSSTOP_EXIST";
-
- /**
- * コマンド引数チェック
- *
- * @throws Exception
- */
- @Test
- public void t00_main_null() throws Exception {
- try {
- String[] args = new String[]{};
- DbExistBusstop.main(args);
- fail();
- }
- catch(Exception e) {
- System.out.println("OK! --> "+ e.toString());
- }
- }
-
- @Test
- public void t01_main_illiegal() throws Exception {
- try {
- String[] args = new String[]{"-"};
- DbExistBusstop.main(args);
- fail();
- }
- catch(Exception e) {
- System.out.println("OK! --> "+ e.toString());
- }
- }
-
- /**
- * (1)テーブルを初期化する
- *
- * @throws Exception
- */
- @Test
- public void t10_main_init() throws Exception {
- try {
- String[] args = new String[]{"-INIT"};
- DbExistBusstop.main(args);
- }
- catch(Exception e) {
- fail(e.toString());
- }
-
- DbTest.checkDatabase(databaseName);
- try (Connection hsqldb = DatabaseTool.openDb(databaseName)) {
- assertThat(DbTest.isTable(hsqldb, tableName), is(true));
- assertThat(DbTest.getRecordCount(hsqldb, tableName), is(0));
-
- assertThat(DbTest.isTable(hsqldb, "AREA_NODE"), is(true));
- assertThat(DbTest.getRecordCount(hsqldb, "AREA_NODE"), is(0));
- }
- catch (Exception e) {
- fail(e.toString());
- }
- }
-
- /**
- * (2)GMLファイルを読み取る(国土数値情報の読み取り)
- *
- * @throws Exception
- */
- @Test
- public void t20_main_import() throws Exception {
- try {
- String[] args = new String[]{"-IMPORT"};
- DbExistBusstop.main(args);
- }
- catch(Exception e) {
- fail(e.toString());
- }
- }
-
- @Test
- public void t21_main_import() {
- try (Connection hsqldb = DatabaseTool.openDb(databaseName)) {
- int cnt = DbTest.getRecordCount(hsqldb, tableName);
- System.out.println("'BUSSTOP' table count = " + cnt);
- assertThat(cnt > 100, is(true));
-
- cnt = DbTest.getRecordCount(hsqldb, tableName, "REMOVED=TRUE");
- System.out.println("'BUSSTOP REMOVED=TRUE' table count = " + cnt);
- assertThat(cnt > 0, is(true));
-
- String sql = "SELECT * FROM "+ tableName +" WHERE ";
-
- // REMOVED
- PreparedStatement ps1 = hsqldb.prepareStatement(sql +"removed=true");
- try (ResultSet rset1 = ps1.executeQuery()) {
- while (rset1.next()) {
- String idref = rset1.getString("idref");
- int area = rset1.getInt("area");
- int score = rset1.getInt("score");
- System.out.println(
- String.format("'BUSSTOP REMOVED'{idref='%s', area=%d, score=%d}", idref, area, score)
- );
- //assertThat(score >= 50, is(true));
- }
- }
-
- // ノード: 八幡前 (3152604023)
- // 場所: 33.9808001, 133.3123441
- // fixme有り
- ps1 = hsqldb.prepareStatement(sql +"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));
- assertThat(rset1.getBoolean("removed"), is(false));
- }
- else {
- fail();
- }
- }
-
- // ノード: 4940018338
- // 場所: 35.5909251, 139.1498642
- // highway=bus_stop, name=null, bus=yes,public_transport=platform
- ps1 = hsqldb.prepareStatement(sql + "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));
- assertThat(rset1.getBoolean("removed"), is(false));
- }
- else {
- fail();
- }
- }
-
- // ノード: 海老名高校前 (2043102034)
- // 場所: 35.4435042, 139.3878934
- // disused:highway=bus_stop
- // operator=海老名市コミュニティバス
- // bench=yes
- // ref=11
- ps1 = hsqldb.prepareStatement(sql + "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));
- assertThat(rset1.getBoolean("removed"), is(true));
- }
- else {
- fail();
- }
- }
-
- // ノード: 厚木ナイロン (1995040609)
- // 場所: 35.4433312, 139.3932098
- // public_transport=stop_position,bus=yes
- ps1 = hsqldb.prepareStatement(sql + "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));
- assertThat(rset1.getBoolean("removed"), is(false));
- }
- else {
- fail();
- }
- }
-
- // ウェイ: 国分寺台第12 (154659062)
- // bus_station
- ps1 = hsqldb.prepareStatement(sql + "idref='154659062'");
- try (ResultSet rset1 = ps1.executeQuery()) {
- if (rset1.next()) {
- assertThat(rset1.getInt("score"), is(50));
- assertThat(rset1.getBoolean("removed"), is(false));
- }
- else {
- fail();
- }
- }
- }
- catch (Exception e) {
- fail(e.toString());
- }
- }
-
- @Test
- public void test03DbExistBusstopTest_busstop() {
- Connection hsqldb = null;
- try {
- hsqldb = DatabaseTool.openDb("database");
- DbExistBusstop osmExist = new DbExistBusstop(hsqldb);
- JsonBuilderFactory factory = Json.createBuilderFactory(null);
- JsonArrayBuilder abuilder = factory.createArrayBuilder();
-
- JsonObjectBuilder builder = factory.createObjectBuilder();
- builder.add("k","public_transport");
- builder.add("v", "platform");
- JsonObject tag = builder.build();
- abuilder.add(tag);
-
- builder = factory.createObjectBuilder();
- builder.add("k","bus");
- builder.add("v", "yes");
- tag = builder.build();
- abuilder.add(tag);
-
- osmExist.readExistingSub(abuilder.build(), POINT_BUS_NO | POINT_NO_NAME | POINT_FIXME, false);
- } catch (Exception ex) {
- fail(ex.toString());
- } finally {
- if (hsqldb != null) {
- DatabaseTool.closeDb(hsqldb);
- }
- }
-
- }
-
- /**
- * (3)'table.OSM_EXIST'の内容をCSV形式にして標準出力に出力する
- *
- * @throws Exception
- */
- @Test
- public void t30_main_expport() throws Exception {
- try {
- String[] args = new String[]{"-EXPORT"};
- DbExistBusstop.main(args);
- }
- catch(Exception e) {
- fail(e.toString());
- }
- }
-
- 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;
- }
- }