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

Last change on this file since 6774 was 6597, checked in by simon04, 11 years ago

see #9492 - split "Create Multipolyon" in % and "Update Multipolygon"; for the latter obtain the relation from the selected ways (if unambiguous)

File size: 3.3 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 static 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(), null)
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>, null)
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>, null)
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>, 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>, null)
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>, 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.