Fix #46 (DataIntegrityProblemException)

Signed-off-by: Taylor Smock's avatarTaylor Smock <[email protected]>
parent a0162636
......@@ -161,6 +161,8 @@ public class MergeDuplicateWays extends Command {
.sorted((pair1, pair2) -> pair1.a.a - pair2.a.a).collect(Collectors.toSet());
if (compressed.parallelStream().anyMatch(entry -> entry.a.b.isDeleted() || entry.b.b.isDeleted())) {
Logging.error("Bad node");
Logging.error("{0}", way1);
Logging.error("{0}", way2);
}
if ((compressed.size() > 1)
&& duplicateEntrySet.parallelStream().noneMatch(entry -> entry.getValue().size() > 1)) {
......@@ -218,7 +220,17 @@ public class MergeDuplicateWays extends Command {
after.forEach(newWay::addNode);
if (newWay.getNodesCount() > 0) {
commands.add(new ChangeCommand(way1, newWay));
/*
* This must be executed, otherwise the delete command will believe that way2
* nodes don't belong to anything See Issue #46
*/
commands.get(commands.size() - 1).executeCommand();
commands.add(DeleteCommand.delete(Collections.singleton(way2), true, true));
/*
* Just to ensure that the dataset is consistent prior to the "real"
* executeCommand
*/
commands.get(commands.size() - 2).undoCommand();
}
if (commands.contains(null)) {
commands = commands.stream().filter(Objects::nonNull).collect(Collectors.toList());
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.backend;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.BBox;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;
......@@ -22,10 +30,37 @@ import org.openstreetmap.josm.data.projection.ProjectionRegistry;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.tools.Geometry;
import com.github.tomakehurst.wiremock.WireMockServer;
public class GetDataRunnableTest {
@Rule
public JOSMTestRules rule = new JOSMTestRules().projection();
WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock"));
@Before
public void setUp() {
wireMock.start();
MapWithAIPreferenceHelper.setMapWithAIURLs(MapWithAIPreferenceHelper.getMapWithAIURLs().stream().map(map -> {
map.put("url", getDefaultMapWithAIAPIForTest(
map.getOrDefault("url", MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API)));
return map;
}).collect(Collectors.toList()));
}
@After
public void tearDown() {
wireMock.stop();
}
private String getDefaultMapWithAIAPIForTest(String url) {
return getDefaultMapWithAIAPIForTest(url, "https://www.facebook.com");
}
private String getDefaultMapWithAIAPIForTest(String url, String wireMockReplace) {
return url.replace(wireMockReplace, wireMock.baseUrl());
}
@Test
public void testAddMissingElement() {
Way way1 = TestUtils.newWay("", new Node(new LatLon(-5.7117803, 34.5011898)),
......@@ -77,4 +112,13 @@ public class GetDataRunnableTest {
assertEquals(1, ds.getWays().parallelStream().filter(way -> !way.isDeleted()).count());
}
@Test
public void testRegressionTicket46() {
DataSet ds = new DataSet();
new GetDataRunnable(Arrays.asList(new BBox(-5.7400005, 34.4524384, -5.6686014, 34.5513153)), ds,
null).fork().join();
assertNotNull(ds);
assertFalse(ds.isEmpty());
assertFalse(ds.allNonDeletedPrimitives().isEmpty());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment