1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import org.junit.Assert;
|
---|
5 | import org.junit.Test;
|
---|
6 | import org.openstreetmap.josm.Main;
|
---|
7 | import org.openstreetmap.josm.data.Bounds;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Unit tests of {@link OsmUrlToBounds} class.
|
---|
11 | */
|
---|
12 | public class OsmUrlToBoundsTest {
|
---|
13 | /**
|
---|
14 | * data for {@link #testParse}
|
---|
15 | */
|
---|
16 | private static final ParseTestItem[] parseTestData = {
|
---|
17 | new ParseTestItem("https://www.openstreetmap.org", null),
|
---|
18 | new ParseTestItem("https://www.openstreetmap.org/?bbox=-0.489,51.28,0.236,51.686",
|
---|
19 | new Bounds(51.28, -0.489, 51.686, 0.236)),
|
---|
20 | new ParseTestItem("https://www.openstreetmap.org/?minlon=-0.489&minlat=51.28&maxlon=0.236&maxlat=51.686",
|
---|
21 | new Bounds(51.28, -0.489, 51.686, 0.236)),
|
---|
22 | new ParseTestItem("https://www.openstreetmap.org/?maxlat=51.686&maxlon=0.236&minlat=51.28&minlon=-0.489",
|
---|
23 | new Bounds(51.28, -0.489, 51.686, 0.236)),
|
---|
24 | new ParseTestItem("https://www.openstreetmap.org/?zoom=17&lat=51.71873&lon=8.76164",
|
---|
25 | OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
|
---|
26 | new ParseTestItem("https://www.openstreetmap.org/?lon=8.76164&lat=51.71873&zoom=17&foo",
|
---|
27 | OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
|
---|
28 | new ParseTestItem("https://www.openstreetmap.org/?mlon=8.76164&mlat=51.71873",
|
---|
29 | OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 18)),
|
---|
30 | new ParseTestItem("http://osm.org/go/euulwp",
|
---|
31 | OsmUrlToBounds.positionToBounds(51.48262023925781, -0.29937744140625, 8)),
|
---|
32 | new ParseTestItem("https://www.openstreetmap.org/#map=17/51.71873/8.76164",
|
---|
33 | OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
|
---|
34 | new ParseTestItem("https://www.openstreetmap.org/#map=17/51.71873/8.76164&layers=CN",
|
---|
35 | OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
|
---|
36 | new ParseTestItem("https%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164",
|
---|
37 | OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)),
|
---|
38 | new ParseTestItem("https%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164%26layers%3DCN",
|
---|
39 | OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)),
|
---|
40 | new ParseTestItem("https://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020",
|
---|
41 | OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)),
|
---|
42 | new ParseTestItem("https://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020&layers=N",
|
---|
43 | OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)),
|
---|
44 | new ParseTestItem("https://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.1270",
|
---|
45 | OsmUrlToBounds.positionToBounds(51.4831, -0.1270, 10)),
|
---|
46 | new ParseTestItem("https://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.3509&layers=T",
|
---|
47 | OsmUrlToBounds.positionToBounds(51.4831, -0.3509, 10)),
|
---|
48 | new ParseTestItem("https://www.openstreetmap.org/#map", null),
|
---|
49 | new ParseTestItem("https://www.openstreetmap.org/#map=foo", null),
|
---|
50 | new ParseTestItem("https://www.openstreetmap.org/#map=fooz/foolat/foolon", null)
|
---|
51 | };
|
---|
52 |
|
---|
53 | private static class ParseTestItem {
|
---|
54 | public String url;
|
---|
55 | public Bounds bounds;
|
---|
56 |
|
---|
57 | ParseTestItem(String url, Bounds bounds) {
|
---|
58 | this.url = url;
|
---|
59 | this.bounds = bounds;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Test URL parsing
|
---|
65 | */
|
---|
66 | @Test
|
---|
67 | public void testParse() {
|
---|
68 | for (ParseTestItem item : parseTestData) {
|
---|
69 | Bounds bounds = null;
|
---|
70 | try {
|
---|
71 | bounds = OsmUrlToBounds.parse(item.url);
|
---|
72 | } catch (IllegalArgumentException e) {
|
---|
73 | // Ignore. check if bounds is null after
|
---|
74 | if (Main.isTraceEnabled()) {
|
---|
75 | Main.trace(e.getMessage());
|
---|
76 | }
|
---|
77 | }
|
---|
78 | Assert.assertEquals(item.url, item.bounds, bounds);
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|