[6564] | 1 | package org.openstreetmap.josm.actions
|
---|
| 2 |
|
---|
[7081] | 3 | import org.junit.BeforeClass
|
---|
| 4 | import org.junit.Test
|
---|
| 5 | import org.openstreetmap.josm.JOSMFixture
|
---|
| 6 | import org.openstreetmap.josm.TestUtils
|
---|
[8811] | 7 | import org.openstreetmap.josm.actions.search.SearchAction
|
---|
[6564] | 8 | import org.openstreetmap.josm.actions.search.SearchCompiler
|
---|
| 9 | import org.openstreetmap.josm.data.osm.Relation
|
---|
| 10 | import org.openstreetmap.josm.data.osm.Way
|
---|
| 11 | import org.openstreetmap.josm.io.OsmReader
|
---|
| 12 | import org.openstreetmap.josm.tools.Utils
|
---|
| 13 |
|
---|
[7081] | 14 | class CreateMultipolygonActionTest {
|
---|
[6564] | 15 |
|
---|
[7081] | 16 | @BeforeClass
|
---|
| 17 | public static void setUp() {
|
---|
| 18 | JOSMFixture.createUnitTestFixture().init();
|
---|
[6564] | 19 | }
|
---|
| 20 |
|
---|
[6597] | 21 | static def getRefToRoleMap(Relation relation) {
|
---|
[6564] | 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 |
|
---|
[8811] | 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 |
|
---|
[7081] | 36 | @Test
|
---|
| 37 | public void testCreate1() {
|
---|
[6564] | 38 | def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
|
---|
[6597] | 39 | def mp = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), null)
|
---|
[6564] | 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 |
|
---|
[7081] | 44 | @Test
|
---|
| 45 | public void testCreate2() {
|
---|
[6564] | 46 | def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
|
---|
[8811] | 47 | def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1."))
|
---|
[6597] | 48 | def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null)
|
---|
[6564] | 49 | assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner, 1.1.2:inner]"
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[7081] | 52 | @Test
|
---|
| 53 | public void testUpdate1() {
|
---|
[6564] | 54 | def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
|
---|
[8811] | 55 | def ways = Utils.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=\".*1\$\"")))
|
---|
[6597] | 56 | def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null)
|
---|
[6564] | 57 | assert mp.b.getMembersCount() == 3
|
---|
| 58 | assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer]"
|
---|
[8811] | 59 | def ways2 = Utils.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=1.2")))
|
---|
[6597] | 60 | def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, mp.b)
|
---|
[6564] | 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 |
|
---|
[7081] | 65 | @Test
|
---|
| 66 | public void testUpdate2() {
|
---|
[6564] | 67 | def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
|
---|
[8811] | 68 | def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.1"))
|
---|
[6597] | 69 | def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null)
|
---|
[6564] | 70 | assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner]"
|
---|
[8811] | 71 | def ways2 = Utils.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=1.1 OR ref=1.2 OR ref=1.1.2")))
|
---|
[6597] | 72 | def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, mp.b)
|
---|
[6564] | 73 | assert getRefToRoleMap(mp2.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.1.2:outer, 1.2:inner]"
|
---|
| 74 | }
|
---|
| 75 | }
|
---|