2016-01-04 13:19:28 +03:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2016-06-15 15:26:50 +03:00
|
|
|
"io/ioutil"
|
2016-02-08 06:29:57 +03:00
|
|
|
"math"
|
2016-06-15 15:26:50 +03:00
|
|
|
"os"
|
2016-01-04 13:19:28 +03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/omniscale/imposm3/geom/geos"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRouteRelation_Prepare(t *testing.T) {
|
2016-06-15 15:26:50 +03:00
|
|
|
var err error
|
|
|
|
|
|
|
|
ts.dir, err = ioutil.TempDir("", "imposm3test")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-01-04 13:19:28 +03:00
|
|
|
ts.config = importConfig{
|
|
|
|
connection: "postgis://",
|
|
|
|
cacheDir: ts.dir,
|
|
|
|
osmFileName: "build/route_relation.pbf",
|
2016-01-04 14:10:34 +03:00
|
|
|
mappingFileName: "route_relation_mapping.yml",
|
2016-01-04 13:19:28 +03:00
|
|
|
}
|
|
|
|
ts.g = geos.NewGeos()
|
|
|
|
|
|
|
|
ts.db, err = sql.Open("postgres", "sslmode=disable")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
ts.dropSchemas()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRouteRelation_Import(t *testing.T) {
|
|
|
|
if ts.tableExists(t, dbschemaImport, "osm_routes") != false {
|
|
|
|
t.Fatalf("table osm_routes exists in schema %s", dbschemaImport)
|
|
|
|
}
|
|
|
|
ts.importOsm(t)
|
|
|
|
if ts.tableExists(t, dbschemaImport, "osm_routes") != true {
|
|
|
|
t.Fatalf("table osm_routes does not exists in schema %s", dbschemaImport)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRouteRelation_Deploy(t *testing.T) {
|
|
|
|
ts.deployOsm(t)
|
|
|
|
if ts.tableExists(t, dbschemaImport, "osm_routes") != false {
|
|
|
|
t.Fatalf("table osm_routes exists in schema %s", dbschemaImport)
|
|
|
|
}
|
|
|
|
if ts.tableExists(t, dbschemaProduction, "osm_routes") != true {
|
|
|
|
t.Fatalf("table osm_routes does not exists in schema %s", dbschemaProduction)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 11:07:14 +03:00
|
|
|
func TestRouteRelation_RelationData(t *testing.T) {
|
|
|
|
// check tags of relation
|
|
|
|
r := ts.queryTags(t, "osm_routes", -100901)
|
|
|
|
if r.tags["name"] != "Bus 301: A => B" {
|
|
|
|
t.Error(r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRouteRelation_MemberGeomUpdated1(t *testing.T) {
|
|
|
|
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100502")
|
|
|
|
if len(rows) != 1 {
|
|
|
|
t.Fatal(rows)
|
|
|
|
}
|
|
|
|
g := ts.g.FromWkt(rows[0]["wkt"])
|
2016-04-27 10:45:28 +03:00
|
|
|
if math.Abs(g.Length()-111.32448543701321) > 0.00000001 {
|
2016-01-06 11:07:14 +03:00
|
|
|
t.Fatal(g.Length())
|
|
|
|
}
|
|
|
|
|
|
|
|
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100503")
|
|
|
|
if len(rows) != 1 {
|
|
|
|
t.Fatal(rows)
|
|
|
|
}
|
|
|
|
if rows[0]["name"] != "" {
|
|
|
|
t.Error(rows[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 10:45:28 +03:00
|
|
|
func TestRouteRelation_NoRouteWithMissingMember(t *testing.T) {
|
|
|
|
// current implementation: route members are all or nothing.
|
|
|
|
// if one member is missing, no member is imported
|
|
|
|
if r := ts.queryDynamic(t, "osm_route_members", "osm_id = -120901 AND member = 120101"); len(r) > 0 {
|
|
|
|
t.Error("found member from route with missing members")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-04 13:19:28 +03:00
|
|
|
// #######################################################################
|
|
|
|
|
|
|
|
func TestRouteRelation_Update(t *testing.T) {
|
|
|
|
ts.updateOsm(t, "./build/route_relation.osc.gz")
|
|
|
|
}
|
2016-01-06 11:07:14 +03:00
|
|
|
|
|
|
|
// #######################################################################
|
|
|
|
|
|
|
|
func TestRouteRelation_MemberGeomUpdated2(t *testing.T) {
|
|
|
|
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100502")
|
|
|
|
if len(rows) != 1 {
|
|
|
|
t.Fatal(rows)
|
|
|
|
}
|
|
|
|
g := ts.g.FromWkt(rows[0]["wkt"])
|
2016-04-27 10:45:28 +03:00
|
|
|
if math.Abs(g.Length()-184.97560221624542) > 0.00000001 {
|
2016-01-06 11:07:14 +03:00
|
|
|
t.Fatal(g.Length())
|
|
|
|
}
|
|
|
|
|
2016-01-08 18:08:00 +03:00
|
|
|
// tag from member is updated
|
2016-01-06 11:07:14 +03:00
|
|
|
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100503")
|
|
|
|
if len(rows) != 1 {
|
|
|
|
t.Fatal(rows)
|
|
|
|
}
|
|
|
|
if rows[0]["name"] != "new name" {
|
|
|
|
t.Error(rows[0])
|
|
|
|
}
|
|
|
|
|
2016-01-08 18:08:00 +03:00
|
|
|
// member is removed
|
|
|
|
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100512")
|
|
|
|
if len(rows) != 0 {
|
|
|
|
t.Fatal(rows)
|
|
|
|
}
|
|
|
|
|
|
|
|
// role from member is updated
|
|
|
|
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100102")
|
2016-01-06 11:07:14 +03:00
|
|
|
if len(rows) != 1 {
|
|
|
|
t.Fatal(rows)
|
|
|
|
}
|
2016-01-08 18:08:00 +03:00
|
|
|
if rows[0]["role"] != "halt" {
|
|
|
|
t.Error(rows[0])
|
2016-01-06 11:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-01-08 18:08:00 +03:00
|
|
|
|
|
|
|
func TestRouteRelation_MemberUpdatedByNode(t *testing.T) {
|
|
|
|
// check that member is updated after node was modified
|
|
|
|
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -110901 AND member = 110101")
|
|
|
|
if len(rows) != 1 {
|
|
|
|
t.Fatal(rows)
|
|
|
|
}
|
|
|
|
if rows[0]["name"] != "Stop2" {
|
|
|
|
t.Error(rows[0])
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 15:26:50 +03:00
|
|
|
|
|
|
|
func TestRouteRelation_Cleanup(t *testing.T) {
|
|
|
|
ts.dropSchemas()
|
|
|
|
if err := os.RemoveAll(ts.dir); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|