Changeset 19619 in josm for trunk/test


Ignore:
Timestamp:
2026-08-29T10:42:43+02:00 (4 days ago)
Author:
GerdP
Message:

Fix #24851: Power line checks won't report existing non-power nodes

  • add the related parent objects to the error message so that they are not considered as unrelated when a partial validation is done on upload
  • unit test by gaben (thanks!)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/PowerLinesTest.java

    r19519 r19619  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.validation.tests;
    3 
    4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    5 import static org.junit.jupiter.api.Assertions.assertFalse;
    6 import static org.junit.jupiter.api.Assertions.assertTrue;
    7 
    8 import java.util.ArrayList;
    93
    104import org.junit.jupiter.api.BeforeEach;
     
    1812import org.openstreetmap.josm.data.osm.TagMap;
    1913import org.openstreetmap.josm.data.osm.Way;
     14import org.openstreetmap.josm.data.validation.TestError;
    2015import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2116import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    2217import org.openstreetmap.josm.testutils.annotations.Projection;
     18
     19import java.util.ArrayList;
     20
     21import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     22import static org.junit.jupiter.api.Assertions.assertFalse;
     23import static org.junit.jupiter.api.Assertions.assertTrue;
    2324
    2425/**
     
    160161        assertTrue(this.powerLines.getErrors().isEmpty());
    161162    }
     163
     164    /**
     165     * Test for ticket #24851.
     166     * Simulates connecting a power line to an existing highway node without power tags.
     167     * Validates that the resulting error contains both the Node AND the Way, so it
     168     * doesn't get filtered out during partial validation on upload.
     169     */
     170    @Test
     171    void testTicket24851_ReportExistingNonPowerNodes() {
     172        Node sharedNode = new Node(new LatLon(0, 0)); // no power tag attached
     173
     174        // unrelated highway way
     175        Way highway = TestUtils.newWay("highway=unclassified",
     176                sharedNode, new Node(new LatLon(0.1, 0)));
     177
     178        // power line way
     179        Way powerline = TestUtils.newWay("power=line",
     180                sharedNode, new Node(new LatLon(0, 0.1)));
     181
     182        // second node has a valid tag
     183        powerline.getNode(1).put("power", "tower");
     184
     185        ds.addPrimitiveRecursive(highway);
     186        ds.addPrimitiveRecursive(powerline);
     187
     188        powerLines.startTest(NullProgressMonitor.INSTANCE);
     189        for (Way w : ds.getWays()) {
     190            powerLines.visit(w);
     191        }
     192        for (Node n : ds.getNodes()) {
     193            powerLines.visit(n);
     194        }
     195        powerLines.endTest();
     196
     197        assertFalse(powerLines.getErrors().isEmpty(), "Errors should be generated for the missing tag and bad connection");
     198
     199        boolean foundSupportError = false;
     200        boolean foundConnectionError = false;
     201
     202        for (TestError error : powerLines.getErrors()) {
     203            // verify POWER_SUPPORT behavior (missing tag)
     204            if (error.getCode() == PowerLines.POWER_SUPPORT && error.getPrimitives().contains(sharedNode)) {
     205                foundSupportError = true;
     206                assertTrue(error.getPrimitives().contains(powerline),
     207                        "MUST contain the parent powerline way. This prevents JOSM from discarding the error " +
     208                                "during partial validation if the node itself was unmodified.");
     209            }
     210            // verify POWER_CONNECTION behavior (bad connection)
     211            if (error.getCode() == PowerLines.POWER_CONNECTION && error.getPrimitives().contains(sharedNode)) {
     212                foundConnectionError = true;
     213                assertTrue(error.getPrimitives().contains(highway),
     214                        "MUST contain the unrelated parent way. This prevents JOSM from discarding the error" +
     215                                "during partial validation if the node itself was unmodified.");
     216            }
     217        }
     218
     219        assertTrue(foundSupportError, "Should report missing power tag on shared node");
     220        assertTrue(foundConnectionError, "Should report bad connection on shared node");
     221    }
    162222}
Note: See TracChangeset for help on using the changeset viewer.