src/test/java/de/blau/android/osm/StorageDelegatorTest.java
/**
     * Split way at node with restriction relation
     */
Split way at node with restriction relation
Split way at node with restriction relation
@Test
    public void splitWithRestrictionRelation() {
        StorageDelegator d = new StorageDelegator();
        Way w = DelegatorUtil.addWayToStorage(d, false);
        Way temp = (Way) d.getOsmElement(Way.NAME, w.getOsmId());
        assertNotNull(temp);
        Node n = w.getNodes().get(2);
        Relation r = w.getParentRelations().get(0);
        List<Result> splitResult = d.splitAtNode(w, n);
        assertNotNull(splitResult);
        assertEquals(1, splitResult.size());
        Way newWay = (Way) splitResult.get(0).getElement();
        Map<String, String> routeTag = new HashMap<>();
        routeTag.put(Tags.KEY_TYPE, Tags.VALUE_RESTRICTION);
        r.setTags(routeTag);
        RelationMember from = r.getMember(w);
        from.setRole(Tags.ROLE_FROM);
        RelationMember to = r.getMember(newWay);
        to.setRole(Tags.ROLE_TO);
        r.addMember(new RelationMember(Tags.ROLE_VIA, n));
        splitResult = d.splitAtNode(w, w.getNodes().get(1));
        assertNotNull(splitResult);
        assertEquals(1, splitResult.size());
        List<RelationMember> froms = r.getMembersWithRole(Tags.ROLE_FROM);
        assertEquals(1, froms.size());
        Way fromWay = (Way) froms.get(0).getElement();
        assertTrue(fromWay.getLastNode().equals(n) || fromWay.getFirstNode().equals(n));
        assertTrue(fromWay.hasCommonNode(newWay));
    }
@ Test public void splitWithRestrictionRelation ( ) { StorageDelegator d = new StorageDelegator ( ) ; Way w = DelegatorUtil . addWayToStorage ( d , false ) ; Way temp = ( Way ) d . getOsmElement ( Way . NAME , w . getOsmId ( ) ) ; assertNotNull ( temp ) ; Node n = w . getNodes ( ) . get ( 2 ) ; Relation r = w . getParentRelations ( ) . get ( 0 ) ; List < Result > splitResult = d . splitAtNode ( w , n ) ; assertNotNull ( splitResult ) ; assertEquals ( 1 , splitResult . size ( ) ) ; Way newWay = ( Way ) splitResult . get ( 0 ) . getElement ( ) ; Map < String , String > routeTag = new HashMap < > ( ) ; routeTag . put ( Tags . KEY_TYPE , Tags . VALUE_RESTRICTION ) ; r . setTags ( routeTag ) ; RelationMember from = r . getMember ( w ) ; from . setRole ( Tags . ROLE_FROM ) ; RelationMember to = r . getMember ( newWay ) ; to . setRole ( Tags . ROLE_TO ) ; r . addMember ( new RelationMember ( Tags . ROLE_VIA , n ) ) ; splitResult = d . splitAtNode ( w , w . getNodes ( ) . get ( 1 ) ) ; assertNotNull ( splitResult ) ; assertEquals ( 1 , splitResult . size ( ) ) ; List < RelationMember > froms = r . getMembersWithRole ( Tags . ROLE_FROM ) ; assertEquals ( 1 , froms . size ( ) ) ; Way fromWay = ( Way ) froms . get ( 0 ) . getElement ( ) ; assertTrue ( fromWay . getLastNode ( ) . equals ( n ) || fromWay . getFirstNode ( ) . equals ( n ) ) ; assertTrue ( fromWay . hasCommonNode ( newWay ) ) ; }
Split way at node with restriction relation
Split way at node with restriction relation
// split from