Changeset 12740 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2017-09-05T20:28:46+02:00 (7 years ago)
Author:
Don-vip
Message:

see #13036 - fix CreateMultipolygonActionTest - tags from outer ways are moved to the multipolygon relation, test has not been designed with this in mind

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java

    r12731 r12740  
    4141    private static Map<String, String> getRefToRoleMap(Relation relation) {
    4242        Map<String, String> refToRole = new TreeMap<>();
     43        String ref = relation.get("ref");
     44        if (ref != null) {
     45            refToRole.put(ref, "outer");
     46        }
    4347        for (RelationMember i : relation.getMembers()) {
    44             String ref = i.getMember().get("ref");
     48            ref = i.getMember().get("ref");
    4549            if (ref != null) {
    4650                refToRole.put(ref, i.getRole());
     
    5862
    5963    @SuppressWarnings("unchecked")
    60     private static Pair<SequenceCommand, Relation> createMultipolygonCommand(Collection<Way> ways, String pattern, Relation r)
     64    private static Relation createMultipolygon(Collection<Way> ways, String pattern, Relation r, boolean runCmd)
    6165            throws SearchParseError {
    62         return CreateMultipolygonAction.createMultipolygonCommand(
     66        Pair<SequenceCommand, Relation> cmd = CreateMultipolygonAction.createMultipolygonCommand(
    6367            (Collection<Way>) (Collection<?>) SubclassFilteredCollection.filter(ways, SearchCompiler.compile(regexpSearch(pattern))), r);
     68        if (runCmd) {
     69            cmd.a.executeCommand();
     70        }
     71        return cmd.b;
    6472    }
    6573
     
    7583    public void testCreate2() throws Exception {
    7684        DataSet ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    77         Pair<SequenceCommand, Relation> mp = createMultipolygonCommand(ds.getWays(), "ref=1 OR ref:1.1.", null);
    78         assertEquals("{1=outer, 1.1.1=inner, 1.1.2=inner}", getRefToRoleMap(mp.b).toString());
     85        Relation mp = createMultipolygon(ds.getWays(), "ref=1 OR ref:1.1.", null, true);
     86        assertEquals("{1=outer, 1.1.1=inner, 1.1.2=inner}", getRefToRoleMap(mp).toString());
    7987    }
    8088
     
    8290    public void testUpdate1() throws Exception {
    8391        DataSet ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    84         Pair<SequenceCommand, Relation> mp = createMultipolygonCommand(ds.getWays(), "ref=\".*1$\"", null);
    85         mp.a.executeCommand();
    86         assertEquals(3, mp.b.getMembersCount());
    87         assertEquals("{1=outer, 1.1=inner, 1.1.1=outer}", getRefToRoleMap(mp.b).toString());
    88         Pair<SequenceCommand, Relation> mp2 = createMultipolygonCommand(ds.getWays(), "ref=1.2", mp.b);
    89         assertEquals(4, mp2.b.getMembersCount());
    90         assertEquals("{1=outer, 1.1=inner, 1.1.1=outer, 1.2=inner}", getRefToRoleMap(mp2.b).toString());
     92        Relation mp = createMultipolygon(ds.getWays(), "ref=\".*1$\"", null, true);
     93        assertEquals(3, mp.getMembersCount());
     94        assertEquals("{1=outer, 1.1=inner, 1.1.1=outer}", getRefToRoleMap(mp).toString());
     95        Relation mp2 = createMultipolygon(ds.getWays(), "ref=1.2", mp, true);
     96        assertEquals(4, mp2.getMembersCount());
     97        assertEquals("{1=outer, 1.1=inner, 1.1.1=outer, 1.2=inner}", getRefToRoleMap(mp2).toString());
    9198    }
    9299
     
    94101    public void testUpdate2() throws Exception {
    95102        DataSet ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    96         Pair<SequenceCommand, Relation> mp = createMultipolygonCommand(ds.getWays(), "ref=1 OR ref:1.1.1", null);
    97         mp.a.executeCommand();
    98         assertEquals("{1=outer, 1.1.1=inner}", getRefToRoleMap(mp.b).toString());
    99         Pair<SequenceCommand, Relation> mp2 = createMultipolygonCommand(ds.getWays(), "ref=1.1 OR ref=1.2 OR ref=1.1.2", mp.b);
    100         assertEquals("{1=outer, 1.1=inner, 1.1.1=outer, 1.1.2=outer, 1.2=inner}", getRefToRoleMap(mp2.b).toString());
     103        Relation mp = createMultipolygon(ds.getWays(), "ref=1 OR ref:1.1.1", null, true);
     104        assertEquals("{1=outer, 1.1.1=inner}", getRefToRoleMap(mp).toString());
     105        Relation mp2 = createMultipolygon(ds.getWays(), "ref=1.1 OR ref=1.2 OR ref=1.1.2", mp, false);
     106        assertEquals("{1=outer, 1.1=inner, 1.1.1=outer, 1.1.2=outer, 1.2=inner}", getRefToRoleMap(mp2).toString());
    101107    }
    102108}
Note: See TracChangeset for help on using the changeset viewer.