1 | package org.openstreetmap.josm.actions
|
---|
2 |
|
---|
3 | import org.openstreetmap.TestUtils
|
---|
4 | import org.openstreetmap.josm.Main
|
---|
5 | import org.openstreetmap.josm.actions.search.SearchCompiler
|
---|
6 | import org.openstreetmap.josm.data.osm.Relation
|
---|
7 | import org.openstreetmap.josm.data.osm.Way
|
---|
8 | import org.openstreetmap.josm.data.projection.Projections
|
---|
9 | import org.openstreetmap.josm.io.OsmReader
|
---|
10 | import org.openstreetmap.josm.tools.Utils
|
---|
11 |
|
---|
12 | class CreateMultipolygonActionTest extends GroovyTestCase {
|
---|
13 |
|
---|
14 | @Override
|
---|
15 | void setUp() {
|
---|
16 | Main.initApplicationPreferences()
|
---|
17 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
18 | }
|
---|
19 |
|
---|
20 | def getRefToRoleMap(Relation relation) {
|
---|
21 | def refToRole = new TreeMap<String, String>()
|
---|
22 | for (i in relation.getMembers()) {
|
---|
23 | refToRole.put(i.member.get("ref"), i.role);
|
---|
24 | }
|
---|
25 | return refToRole;
|
---|
26 | }
|
---|
27 |
|
---|
28 | void testCreate1() {
|
---|
29 | def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
|
---|
30 | def mp = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), Collections.emptyList())
|
---|
31 | assert mp.a.getDescriptionText() == "Sequence: Create multipolygon"
|
---|
32 | assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.1.2:outer, 1.2:inner]"
|
---|
33 | }
|
---|
34 |
|
---|
35 | void testCreate2() {
|
---|
36 | def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
|
---|
37 | def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.", false, false))
|
---|
38 | def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, Collections.emptyList())
|
---|
39 | assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner, 1.1.2:inner]"
|
---|
40 | }
|
---|
41 |
|
---|
42 | void testUpdate1() {
|
---|
43 | def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
|
---|
44 | def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=\".*1\$\"", false, true))
|
---|
45 | def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, Collections.emptyList())
|
---|
46 | assert mp.b.getMembersCount() == 3
|
---|
47 | assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer]"
|
---|
48 | def ways2 = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1.2", false, true))
|
---|
49 | def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, Collections.singleton(mp.b))
|
---|
50 | assert mp2.b.getMembersCount() == 4
|
---|
51 | assert getRefToRoleMap(mp2.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.2:inner]"
|
---|
52 | }
|
---|
53 |
|
---|
54 | void testUpdate2() {
|
---|
55 | def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
|
---|
56 | def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.1", false, false))
|
---|
57 | def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, Collections.emptyList())
|
---|
58 | assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner]"
|
---|
59 | def ways2 = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1.1 OR ref=1.2 OR ref=1.1.2", false, true))
|
---|
60 | def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, Collections.singleton(mp.b))
|
---|
61 | assert getRefToRoleMap(mp2.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.1.2:outer, 1.2:inner]"
|
---|
62 | }
|
---|
63 | }
|
---|