source: josm/trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.groovy@ 6564

Last change on this file since 6564 was 6564, checked in by simon04, 10 years ago

fix 9492 - Tools>"Create Multipolygon": updates multipolygon if a multipolygon relation is selected

File size: 3.4 KB
Line 
1package org.openstreetmap.josm.actions
2
3import org.openstreetmap.TestUtils
4import org.openstreetmap.josm.Main
5import org.openstreetmap.josm.actions.search.SearchCompiler
6import org.openstreetmap.josm.data.osm.Relation
7import org.openstreetmap.josm.data.osm.Way
8import org.openstreetmap.josm.data.projection.Projections
9import org.openstreetmap.josm.io.OsmReader
10import org.openstreetmap.josm.tools.Utils
11
12class 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}
Note: See TracBrowser for help on using the repository browser.