Changeset 14040 in josm for trunk/test/unit/org
- Timestamp:
- 2018-07-21T00:36:46+02:00 (6 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/io
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/ChangesetQueryUrlParserTest.java
r14039 r14040 14 14 import org.openstreetmap.josm.io.ChangesetQuery.ChangesetQueryUrlException; 15 15 import org.openstreetmap.josm.io.ChangesetQuery.ChangesetQueryUrlParser; 16 import org.openstreetmap.josm.tools.Logging; 16 17 17 18 /** … … 45 46 fail("should throw exception"); 46 47 } catch (ChangesetQueryUrlException e) { 47 // OK48 Logging.trace(e); 48 49 } 49 50 } -
trunk/test/unit/org/openstreetmap/josm/io/ParseWithChangesetReaderTest.java
r14035 r14040 2 2 package org.openstreetmap.josm.io; 3 3 4 import static groovy.test.GroovyAssert.shouldFail 5 import static org.junit.Assert.* 6 7 import java.nio.charset.StandardCharsets 8 9 import org.junit.Test 10 import org.openstreetmap.josm.data.osm.DataSet 11 import org.openstreetmap.josm.data.osm.Node 12 import org.openstreetmap.josm.data.osm.OsmPrimitiveType 13 14 class ParseWithChangesetReaderTest { 15 16 private DataSet getDataSet(String doc) { 17 InputStream is = new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8)) 18 DataSet ds = new OsmReader().parseDataSet(is, null) 19 is.close() 20 return ds 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.fail; 7 8 import java.io.ByteArrayInputStream; 9 import java.io.IOException; 10 import java.io.InputStream; 11 import java.nio.charset.StandardCharsets; 12 13 import org.junit.Rule; 14 import org.junit.Test; 15 import org.openstreetmap.josm.data.osm.DataSet; 16 import org.openstreetmap.josm.data.osm.Node; 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 19 import org.openstreetmap.josm.testutils.JOSMTestRules; 20 import org.openstreetmap.josm.tools.Logging; 21 22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 23 24 /** 25 * Additional unit tests for {@link OsmReader}. 26 */ 27 public class ParseWithChangesetReaderTest { 28 29 /** 30 * Setup rule 31 */ 32 @Rule 33 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 34 public JOSMTestRules test = new JOSMTestRules(); 35 36 private static DataSet getDataSet(String doc) throws IOException, IllegalDataException { 37 try (InputStream is = new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8))) { 38 return OsmReader.parseDataSet(is, null); 39 } 40 } 41 42 private static void shouldFail(String doc) throws IOException { 43 try { 44 getDataSet(doc); 45 fail("should throw exception"); 46 } catch (IllegalDataException e) { 47 Logging.trace(e); 48 } 21 49 } 22 50 23 51 /** 24 52 * A new node with a changeset id. Ignore it. 25 * /26 @Test27 public void test_1() {28 String doc = """\29 <osm version="0.6">30 <node id="-1" lat="0.0" lon="0.0" changeset="1">31 <tag k="external-id" v="-1"/>32 </node>33 </osm>34 """35 36 DataSet ds = getDataSet(doc) 37 Node n = ds. nodes.find {it.get("external-id") == "-1"}38 assert n != null39 assert n.changesetId == 053 * @throws Exception never 54 */ 55 @Test 56 public void test_1() throws Exception { 57 String doc = 58 "<osm version=\"0.6\">\n" + 59 "<node id=\"-1\" lat=\"0.0\" lon=\"0.0\" changeset=\"1\">\n" + 60 " <tag k=\"external-id\" v=\"-1\"/>\n" + 61 "</node>\n" + 62 "</osm>"; 63 64 DataSet ds = getDataSet(doc); 65 Node n = ds.getNodes().stream().filter(x -> "-1".equals(x.get("external-id"))).findFirst().get(); 66 assertNotNull(n); 67 assertEquals(0, n.getChangesetId()); 40 68 } 41 69 42 70 /** 43 71 * A new node with an invalid changeset id. Ignore it. 44 * /45 @Test46 public void test_11() {47 String doc = """\48 <osm version="0.6">49 <node id="-1" lat="0.0" lon="0.0" changeset="0">50 <tag k="external-id" v="-1"/>51 </node>52 </osm>53 " ""54 55 DataSet ds = getDataSet(doc) 56 Node n = ds. nodes.find {it.get("external-id") == "-1"}57 assert n != null58 assert n.changesetId == 072 * @throws Exception never 73 */ 74 @Test 75 public void test_11() throws Exception { 76 String doc = 77 "<osm version=\"0.6\">\n" + 78 "<node id=\"-1\" lat=\"0.0\" lon=\"0.0\" changeset=\"0\">\n" + 79 " <tag k=\"external-id\" v=\"-1\"/>\n" + 80 "</node>\n" + 81 "</osm>"; 82 83 DataSet ds = getDataSet(doc); 84 Node n = ds.getNodes().stream().filter(x -> "-1".equals(x.get("external-id"))).findFirst().get(); 85 assertNotNull(n); 86 assertEquals(0, n.getChangesetId()); 59 87 } 60 88 61 89 /** 62 90 * A new node with an invalid changeset id. Ignore it. 63 * /64 @Test65 public void test_12() {66 String doc = """\67 <osm version="0.6">68 <node id="-1" lat="0.0" lon="0.0" changeset="-1">69 <tag k="external-id" v="-1"/>70 </node>71 </osm>72 " ""73 74 DataSet ds = getDataSet(doc) 75 Node n = ds. nodes.find {it.get("external-id") == "-1"}76 assert n != null77 assert n.changesetId == 091 * @throws Exception never 92 */ 93 @Test 94 public void test_12() throws Exception { 95 String doc = 96 "<osm version=\"0.6\">\n" + 97 "<node id=\"-1\" lat=\"0.0\" lon=\"0.0\" changeset=\"-1\">\n" + 98 " <tag k=\"external-id\" v=\"-1\"/>\n" + 99 "</node>\n" + 100 "</osm>"; 101 102 DataSet ds = getDataSet(doc); 103 Node n = ds.getNodes().stream().filter(x -> "-1".equals(x.get("external-id"))).findFirst().get(); 104 assertNotNull(n); 105 assertEquals(0, n.getChangesetId()); 78 106 } 79 107 80 108 /** 81 109 * A new node with an invalid changeset id. Ignore it. 82 * /83 @Test84 public void test_13() {85 String doc = """\86 <osm version="0.6">87 <node id="-1" lat="0.0" lon="0.0" changeset="aaa">88 <tag k="external-id" v="-1"/>89 </node>90 </osm>91 " ""92 93 DataSet ds = getDataSet(doc) 94 Node n = ds. nodes.find {it.get("external-id") == "-1"}95 assert n != null96 assert n.changesetId == 0110 * @throws Exception never 111 */ 112 @Test 113 public void test_13() throws Exception { 114 String doc = 115 "<osm version=\"0.6\">\n" + 116 "<node id=\"-1\" lat=\"0.0\" lon=\"0.0\" changeset=\"aaa\">\n" + 117 " <tag k=\"external-id\" v=\"-1\"/>\n" + 118 "</node>\n" + 119 "</osm>"; 120 121 DataSet ds = getDataSet(doc); 122 Node n = ds.getNodes().stream().filter(x -> "-1".equals(x.get("external-id"))).findFirst().get(); 123 assertNotNull(n); 124 assertEquals(0, n.getChangesetId()); 97 125 } 98 126 … … 100 128 * A new node with a missing changeset id. That's fine. The changeset id 101 129 * is reset to 0. 102 * /103 @Test104 public void test_14() {105 String doc = """\106 <osm version="0.6">107 <node id="-1" lat="0.0" lon="0.0" >108 <tag k="external-id" v="-1"/>109 </node>110 </osm>111 " ""112 113 DataSet ds = getDataSet(doc) 114 Node n = ds. nodes.find {it.get("external-id") == "-1"}115 assert n != null116 assert n.changesetId == 0130 * @throws Exception never 131 */ 132 @Test 133 public void test_14() throws Exception { 134 String doc = 135 "<osm version=\"0.6\">\n" + 136 "<node id=\"-1\" lat=\"0.0\" lon=\"0.0\" >\n" + 137 " <tag k=\"external-id\" v=\"-1\"/>\n" + 138 "</node>\n" + 139 "</osm>"; 140 141 DataSet ds = getDataSet(doc); 142 Node n = ds.getNodes().stream().filter(x -> "-1".equals(x.get("external-id"))).findFirst().get(); 143 assertNotNull(n); 144 assertEquals(0, n.getChangesetId()); 117 145 } 118 146 … … 121 149 * An existing node with a missing changeset id. That's fine. The changeset id 122 150 * is reset to 0. 123 * /124 @Test125 public void test_2() {126 String doc = """\127 <osm version="0.6">128 <node id="1" lat="0.0" lon="0.0" version="1"/>129 </osm>130 " ""131 132 DataSet ds = getDataSet(doc) 133 Node n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE)134 assert n != null135 assert n.uniqueId == 1136 assert n.changesetId == 0151 * @throws Exception never 152 */ 153 @Test 154 public void test_2() throws Exception { 155 String doc = 156 "<osm version=\"0.6\">\n" + 157 "<node id=\"1\" lat=\"0.0\" lon=\"0.0\" version=\"1\"/>\n" + 158 "</osm>"; 159 160 DataSet ds = getDataSet(doc); 161 OsmPrimitive n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE); 162 assertNotNull(n); 163 assertEquals(1, n.getUniqueId()); 164 assertEquals(0, n.getChangesetId()); 137 165 } 138 166 … … 140 168 * An existing node with a valid changeset id id. That's fine. The changeset id 141 169 * is applied. 142 * /143 @Test144 public void test_3() {145 String doc = """\146 <osm version="0.6">147 <node id="1" lat="0.0" lon="0.0" version="1" changeset="4"/>148 </osm>149 " ""150 151 DataSet ds = getDataSet(doc) 152 Node n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE)153 assert n != null154 assert n.uniqueId == 1155 assert n.changesetId == 4170 * @throws Exception never 171 */ 172 @Test 173 public void test_3() throws Exception { 174 String doc = 175 "<osm version=\"0.6\">\n" + 176 "<node id=\"1\" lat=\"0.0\" lon=\"0.0\" version=\"1\" changeset=\"4\"/>\n" + 177 "</osm>"; 178 179 DataSet ds = getDataSet(doc); 180 OsmPrimitive n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE); 181 assertNotNull(n); 182 assertEquals(1, n.getUniqueId()); 183 assertEquals(4, n.getChangesetId()); 156 184 } 157 185 … … 159 187 * An existing node with an invalid changeset id. That's a problem. An exception 160 188 * is thrown. 161 */ 162 @Test 163 public void test_4() { 164 String doc = """\ 165 <osm version="0.6"> 166 <node id="1" lat="0.0" lon="0.0" version="1" changeset="-1"/> 167 </osm> 168 """ 169 170 shouldFail(IllegalDataException) { 171 DataSet ds = getDataSet(doc) 172 } 173 } 189 * @throws IOException never 190 */ 191 @Test 192 public void test_4() throws IOException { 193 String doc = 194 "<osm version=\"0.6\">\n" + 195 "<node id=\"1\" lat=\"0.0\" lon=\"0.0\" version=\"1\" changeset=\"-1\"/>\n" + 196 "</osm>"; 197 198 shouldFail(doc); 199 } 200 174 201 /** 175 202 * An existing node with an invalid changeset id. That's a problem. An exception 176 203 * is thrown. 177 */ 178 @Test 179 public void test_5() { 180 String doc = """\ 181 <osm version="0.6"> 182 <node id="1" lat="0.0" lon="0.0" version="1" changeset="0"/> 183 </osm> 184 """ 185 186 shouldFail(IllegalDataException) { 187 DataSet ds = getDataSet(doc) 188 } 189 } 204 * @throws IOException never 205 */ 206 @Test 207 public void test_5() throws IOException { 208 String doc = 209 "<osm version=\"0.6\">\n" + 210 "<node id=\"1\" lat=\"0.0\" lon=\"0.0\" version=\"1\" changeset=\"1.0\"/>\n" + 211 "</osm>"; 212 213 shouldFail(doc); 214 } 215 190 216 /** 191 217 * An existing node with an invalid changeset id. That's a problem. An exception 192 218 * is thrown. 193 */ 194 @Test 195 public void test_6() { 196 String doc = """\ 197 <osm version="0.6"> 198 <node id="1" lat="0.0" lon="0.0" version="1" changeset="abc"/> 199 </osm> 200 """ 201 202 shouldFail(IllegalDataException) { 203 DataSet ds = getDataSet(doc) 204 } 219 * @throws IOException never 220 */ 221 @Test 222 public void test_6() throws IOException { 223 String doc = 224 "<osm version=\"0.6\">\n" + 225 "<node id=\"1\" lat=\"0.0\" lon=\"0.0\" version=\"1\" changeset=\"abc\"/>\n" + 226 "</osm>"; 227 228 shouldFail(doc); 205 229 } 206 230 }
Note:
See TracChangeset
for help on using the changeset viewer.