1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.io.InputStream;
|
---|
8 | import java.util.Collection;
|
---|
9 |
|
---|
10 | import org.junit.Rule;
|
---|
11 | import org.junit.Test;
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.TestUtils;
|
---|
14 | import org.openstreetmap.josm.actions.search.SearchAction;
|
---|
15 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
19 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
20 | import org.openstreetmap.josm.io.IllegalDataException;
|
---|
21 | import org.openstreetmap.josm.io.OsmReader;
|
---|
22 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
23 | import org.openstreetmap.josm.tools.Utils;
|
---|
24 |
|
---|
25 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Unit tests of {@link JoinAreasAction} class.
|
---|
29 | */
|
---|
30 | public class JoinAreasActionTest {
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Setup test.
|
---|
34 | */
|
---|
35 | @Rule
|
---|
36 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
37 | public JOSMTestRules test = new JOSMTestRules().commands();
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Non-regression test for bug #10511.
|
---|
41 | * @throws IOException if any I/O error occurs
|
---|
42 | * @throws IllegalDataException if OSM parsing fails
|
---|
43 | */
|
---|
44 | @Test
|
---|
45 | public void testTicket10511() throws IOException, IllegalDataException {
|
---|
46 | try (InputStream is = TestUtils.getRegressionDataStream(10511, "10511_mini.osm")) {
|
---|
47 | DataSet ds = OsmReader.parseDataSet(is, null);
|
---|
48 | Layer layer = new OsmDataLayer(ds, null, null);
|
---|
49 | Main.getLayerManager().addLayer(layer);
|
---|
50 | // FIXME enable this test after we fix the bug. Test disabled for now
|
---|
51 | // try {
|
---|
52 | // new JoinAreasAction().join(ds.getWays());
|
---|
53 | // } finally {
|
---|
54 | // Ensure we clean the place before leaving, even if test fails.
|
---|
55 | Main.getLayerManager().removeLayer(layer);
|
---|
56 | // }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Non-regression test for bug #11992.
|
---|
62 | * @throws IOException if any I/O error occurs
|
---|
63 | * @throws IllegalDataException if OSM parsing fails
|
---|
64 | */
|
---|
65 | @Test
|
---|
66 | public void testTicket11992() throws IOException, IllegalDataException {
|
---|
67 | try (InputStream is = TestUtils.getRegressionDataStream(11992, "shapes.osm")) {
|
---|
68 | DataSet ds = OsmReader.parseDataSet(is, null);
|
---|
69 | assertEquals(10, ds.getWays().size());
|
---|
70 | Layer layer = new OsmDataLayer(ds, null, null);
|
---|
71 | Main.getLayerManager().addLayer(layer);
|
---|
72 | for (String ref : new String[]{"A", "B", "C", "D", "E"}) {
|
---|
73 | System.out.print("Joining ways " + ref);
|
---|
74 | Collection<OsmPrimitive> found = SearchAction.searchAndReturn("type:way ref="+ref, SearchAction.SearchMode.replace);
|
---|
75 | assertEquals(2, found.size());
|
---|
76 |
|
---|
77 | Main.main.menu.joinAreas.join(Utils.filteredCollection(found, Way.class));
|
---|
78 |
|
---|
79 | Collection<OsmPrimitive> found2 = SearchAction.searchAndReturn("type:way ref="+ref, SearchAction.SearchMode.replace);
|
---|
80 | assertEquals(1, found2.size());
|
---|
81 | System.out.println(" ==> OK");
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|