1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.upload;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
---|
7 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
8 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
9 |
|
---|
10 | import java.util.Arrays;
|
---|
11 | import java.util.Collection;
|
---|
12 |
|
---|
13 | import org.junit.jupiter.api.Test;
|
---|
14 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
15 | import org.openstreetmap.josm.command.PseudoCommand;
|
---|
16 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
17 | import org.openstreetmap.josm.data.APIDataSet;
|
---|
18 | import org.openstreetmap.josm.data.UndoRedoHandler;
|
---|
19 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
20 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
21 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
22 | import org.openstreetmap.josm.data.osm.Way;
|
---|
23 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
24 |
|
---|
25 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Unit tests for class {@link FixDataHook}.
|
---|
29 | */
|
---|
30 | class FixDataHookTest {
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Setup test.
|
---|
34 | */
|
---|
35 | @RegisterExtension
|
---|
36 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
37 | public JOSMTestRules test = new JOSMTestRules().main();
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Test of {@link FixDataHook#checkUpload} method.
|
---|
41 | */
|
---|
42 | @Test
|
---|
43 | void testCheckUpload() {
|
---|
44 | // Empty data set
|
---|
45 | UndoRedoHandler.getInstance().clean();
|
---|
46 | new FixDataHook().checkUpload(new APIDataSet());
|
---|
47 | assertTrue(UndoRedoHandler.getInstance().getUndoCommands().isEmpty());
|
---|
48 |
|
---|
49 | // Complete data set (except empty node which cannot be tested anymore)
|
---|
50 | Way emptyWay = new Way();
|
---|
51 | Relation emptyRelation = new Relation();
|
---|
52 | Way w1 = new Way();
|
---|
53 | w1.put("color", "test");
|
---|
54 | Way w2 = new Way();
|
---|
55 | w2.put("highway", "ford");
|
---|
56 | Way w3 = new Way();
|
---|
57 | w3.put("oneway", "false");
|
---|
58 | Way w4 = new Way();
|
---|
59 | w4.put("oneway", "0");
|
---|
60 | Way w5 = new Way();
|
---|
61 | w5.put("oneway", "true");
|
---|
62 | Way w6 = new Way();
|
---|
63 | w6.put("oneway", "1");
|
---|
64 | Way w7 = new Way();
|
---|
65 | w7.put("highway", "stile");
|
---|
66 | Relation r1 = new Relation();
|
---|
67 | r1.put("type", "multipolygon");
|
---|
68 | r1.put("boundary", "administrative");
|
---|
69 | Relation r2 = new Relation();
|
---|
70 | r2.put("foo", "space_end ");
|
---|
71 | r2.put("bar", " space_begin ");
|
---|
72 | r2.put("baz", " space_both ");
|
---|
73 | r2.put(" space_begin", "test");
|
---|
74 | r2.put("space_end ", "test");
|
---|
75 | r2.put(" space_both ", "test");
|
---|
76 | APIDataSet ads = new APIDataSet();
|
---|
77 | ads.init(new DataSet(emptyWay, emptyRelation, w1, w2, w3, w4, w5, w6, w7, r1, r2));
|
---|
78 |
|
---|
79 | assertEquals(0, UndoRedoHandler.getInstance().getUndoCommands().size());
|
---|
80 | new FixDataHook().checkUpload(ads);
|
---|
81 | assertEquals(1, UndoRedoHandler.getInstance().getUndoCommands().size());
|
---|
82 |
|
---|
83 | SequenceCommand seq = (SequenceCommand) UndoRedoHandler.getInstance().getUndoCommands().iterator().next();
|
---|
84 | Collection<? extends OsmPrimitive> prims = seq.getParticipatingPrimitives();
|
---|
85 | assertNotNull(prims);
|
---|
86 | assertEquals(9, prims.size());
|
---|
87 | for (OsmPrimitive o : Arrays.asList(w1, w2, w3, w4, w5, w6, w7, r1, r2)) {
|
---|
88 | assertTrue(prims.contains(o), o.toString());
|
---|
89 | }
|
---|
90 | Collection<PseudoCommand> cmds = seq.getChildren();
|
---|
91 | assertNotNull(cmds);
|
---|
92 | assertEquals(9, cmds.size());
|
---|
93 |
|
---|
94 | assertTrue(seq.executeCommand());
|
---|
95 |
|
---|
96 | assertFalse(w1.hasKey("color"));
|
---|
97 | assertTrue(w1.hasKey("colour"));
|
---|
98 |
|
---|
99 | assertFalse(w2.hasKey("highway"));
|
---|
100 | assertTrue(w2.hasKey("ford"));
|
---|
101 |
|
---|
102 | assertNotEquals("false", w3.get("oneway"));
|
---|
103 | assertEquals("no", w3.get("oneway"));
|
---|
104 |
|
---|
105 | assertNotEquals("0", w4.get("oneway"));
|
---|
106 | assertEquals("no", w4.get("oneway"));
|
---|
107 |
|
---|
108 | assertNotEquals("true", w5.get("oneway"));
|
---|
109 | assertEquals("yes", w5.get("oneway"));
|
---|
110 |
|
---|
111 | assertNotEquals("1", w6.get("oneway"));
|
---|
112 | assertEquals("yes", w6.get("oneway"));
|
---|
113 |
|
---|
114 | assertFalse(w7.hasKey("highway"));
|
---|
115 | assertTrue(w7.hasKey("barrier"));
|
---|
116 |
|
---|
117 | assertNotEquals("multipolygon", r1.get("type"));
|
---|
118 | assertEquals("boundary", r1.get("type"));
|
---|
119 |
|
---|
120 | assertEquals("space_end", r2.get("foo"));
|
---|
121 | assertEquals("space_begin", r2.get("bar"));
|
---|
122 | assertEquals("space_both", r2.get("baz"));
|
---|
123 | assertFalse(r2.hasKey(" space_begin"));
|
---|
124 | assertFalse(r2.hasKey("space_end "));
|
---|
125 | assertFalse(r2.hasKey(" space_both "));
|
---|
126 | assertTrue(r2.hasKey("space_begin"));
|
---|
127 | assertTrue(r2.hasKey("space_end"));
|
---|
128 | assertTrue(r2.hasKey("space_both"));
|
---|
129 | }
|
---|
130 | }
|
---|