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

Last change on this file since 10657 was 10657, checked in by Don-vip, 8 years ago

see #11390, see #12890 - use Java 8 Predicates

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1package org.openstreetmap.josm.actions
2
3import org.junit.BeforeClass
4import org.junit.Test
5import org.openstreetmap.josm.JOSMFixture
6import org.openstreetmap.josm.TestUtils
7import org.openstreetmap.josm.actions.search.SearchAction
8import org.openstreetmap.josm.actions.search.SearchCompiler
9import org.openstreetmap.josm.data.osm.Relation
10import org.openstreetmap.josm.data.osm.Way
11import org.openstreetmap.josm.io.OsmReader
12import org.openstreetmap.josm.tools.SubclassFilteredCollection
13
14class CreateMultipolygonActionTest {
15
16 @BeforeClass
17 public static void setUp() {
18 JOSMFixture.createUnitTestFixture().init();
19 }
20
21 static def getRefToRoleMap(Relation relation) {
22 def refToRole = new TreeMap<String, String>()
23 for (i in relation.getMembers()) {
24 refToRole.put(i.member.get("ref"), i.role);
25 }
26 return refToRole;
27 }
28
29 static def regexpSearch(String search) {
30 def setting = new SearchAction.SearchSetting()
31 setting.text = search
32 setting.regexSearch = true
33 return setting
34 }
35
36 @Test
37 public void testCreate1() {
38 def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
39 def mp = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), null)
40 assert mp.a.getDescriptionText() == "Sequence: Create multipolygon"
41 assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.1.2:outer, 1.2:inner]"
42 }
43
44 @Test
45 public void testCreate2() {
46 def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
47 def ways = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1."))
48 def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null)
49 assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner, 1.1.2:inner]"
50 }
51
52 @Test
53 public void testUpdate1() {
54 def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
55 def ways = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=\".*1\$\"")))
56 def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null)
57 assert mp.b.getMembersCount() == 3
58 assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer]"
59 def ways2 = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=1.2")))
60 def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, mp.b)
61 assert mp2.b.getMembersCount() == 4
62 assert getRefToRoleMap(mp2.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.2:inner]"
63 }
64
65 @Test
66 public void testUpdate2() {
67 def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
68 def ways = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.1"))
69 def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null)
70 assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner]"
71 def ways2 = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=1.1 OR ref=1.2 OR ref=1.1.2")))
72 def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, mp.b)
73 assert getRefToRoleMap(mp2.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.1.2:outer, 1.2:inner]"
74 }
75}
Note: See TracBrowser for help on using the repository browser.