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