Changeset 17375 in josm for trunk/test


Ignore:
Timestamp:
2020-11-29T10:57:33+01:00 (4 years ago)
Author:
GerdP
Message:

fix #20163: Split way corrupts relation when splitting via way

  • if via way in turn restriction is split we have to insert new member
Location:
trunk/test
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/command/SplitWayCommandTest.java

    r17275 r17375  
    396396        }
    397397    }
     398
     399    /**
     400     * Non-regression test for issue #20163 (Split way corrupts relation when splitting via way)
     401     *
     402     * @throws IOException if any I/O error occurs
     403     * @throws IllegalDataException if OSM parsing fails
     404     */
     405    @Test
     406    void testTicket20163() throws IOException, IllegalDataException {
     407        try (InputStream is = TestUtils.getRegressionDataStream(20163, "data-20163.osm")) {
     408            DataSet ds = OsmReader.parseDataSet(is, null);
     409
     410            Way splitWay = (Way) ds.getPrimitiveById(757606841L, OsmPrimitiveType.WAY);
     411            Node splitNode = splitWay.getNode(1);
     412            Relation r = (Relation) ds.getPrimitiveById(10452821L, OsmPrimitiveType.RELATION);
     413            assertEquals(3, r.getMembersCount());
     414            assertFalse(r.getMembersFor(Collections.singleton(splitWay)).isEmpty());
     415            assertEquals(1, r.getMembers().stream().filter(rm -> "via".equals(rm.getRole())).count());
     416            assertEquals("via", r.getMembersFor(Collections.singleton(splitWay)).iterator().next().getRole());
     417            final Optional<SplitWayCommand> result = SplitWayCommand.splitWay(
     418                    splitWay,
     419                    SplitWayCommand.buildSplitChunks(splitWay, Collections.singletonList(splitNode)),
     420                    new ArrayList<>(),
     421                    Strategy.keepLongestChunk(),
     422                    // This split requires additional downloads but problem occured before the download
     423                    SplitWayCommand.WhenRelationOrderUncertain.SPLIT_ANYWAY
     424            );
     425
     426            // Should not result in aborting the split.
     427            assertTrue(result.isPresent());
     428            result.get().executeCommand();
     429
     430            assertTrue(r.isModified());
     431            assertEquals(4, r.getMembersCount());
     432            assertEquals(2, r.getMembers().stream().filter(rm -> "via".equals(rm.getRole())).count());
     433        }
     434    }
     435
    398436}
Note: See TracChangeset for help on using the changeset viewer.