Changeset 16641 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2020-06-14T19:35:04+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/OsmReaderTest.java
r15470 r16641 23 23 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 24 24 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 import org.openstreetmap.josm.io.OsmReader.Options; 25 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 26 27 … … 83 84 try (InputStream in = new ByteArrayInputStream( 84 85 ("<?xml version='1.0' encoding='UTF-8'?>" + osm).getBytes(StandardCharsets.UTF_8))) { 85 assertTrue(OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE, parseUnknownAttributes).allPrimitives()86 assertTrue(OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE, Options.CONVERT_UNKNOWN_TO_TAGS).allPrimitives() 86 87 .isEmpty()); 88 } 89 testUnknown(osm, parseUnknownAttributes, true); 90 testUnknown(osm, parseUnknownAttributes, true); 91 } 92 93 private static void testUnknown(String osm, boolean parseUnknownAttributes, boolean keepOriginalId) 94 throws Exception { 95 try (InputStream in = new ByteArrayInputStream( 96 ("<?xml version='1.0' encoding='UTF-8'?>" + osm).getBytes(StandardCharsets.UTF_8))) { 97 assertTrue(OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE, Options.CONVERT_UNKNOWN_TO_TAGS, Options.SAVE_ORIGINAL_ID) 98 .allPrimitives().isEmpty()); 87 99 } 88 100 } … … 141 153 * Test valid data. 142 154 * @param osm OSM data without XML prefix 143 * @param parseUnknownAttributes if true, attempt to parse unknown xml attributes155 * @param options The options to use to parse the data 144 156 * @return parsed data set 145 157 * @throws Exception if any error occurs 146 158 */ 147 private static DataSet testValidData(String osm, boolean parseUnknownAttributes) throws Exception {148 try (InputStream in = new ByteArrayInputStream( 149 ("<?xml version='1.0' encoding='UTF-8'?>" + osm).getBytes(StandardCharsets.UTF_8))) { 150 return OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE, parseUnknownAttributes);159 private static DataSet testValidData(String osm, Options... options) throws Exception { 160 try (InputStream in = new ByteArrayInputStream( 161 ("<?xml version='1.0' encoding='UTF-8'?>" + osm).getBytes(StandardCharsets.UTF_8))) { 162 return OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE, options); 151 163 } 152 164 } … … 183 195 try (InputStream in = new ByteArrayInputStream( 184 196 ("<?xml version='1.0' encoding='UTF-8'?>" + osm).getBytes(StandardCharsets.UTF_8))) { 185 OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE, parseUnknownAttributes);197 OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE, Options.CONVERT_UNKNOWN_TO_TAGS); 186 198 fail("should throw exception"); 187 199 } catch (IllegalDataException e) { … … 325 337 String gdprChangeset = "<osm version='0.6'><node id='1' version='1' changeset='0'/></osm>"; 326 338 testValidData(gdprChangeset); 327 testValidData(gdprChangeset, true); 328 testValidData(gdprChangeset, false); 339 testValidData(gdprChangeset, Options.CONVERT_UNKNOWN_TO_TAGS); 340 testValidData(gdprChangeset, (Options) null); 341 testValidData(gdprChangeset, Options.SAVE_ORIGINAL_ID); 342 testValidData(gdprChangeset, Options.values()); 329 343 } 330 344 … … 406 420 "<remark>runtime error: Query ran out of memory in \"query\" at line 5.</remark>\r\n" + 407 421 "</osm>"; 408 for (DataSet ds : Arrays.asList(testValidData(query), testValidData(query, true), testValidData(query, false))) { 422 for (DataSet ds : Arrays.asList(testValidData(query), testValidData(query, Options.CONVERT_UNKNOWN_TO_TAGS), testValidData(query, (Options) null), 423 testValidData(query, Options.SAVE_ORIGINAL_ID), testValidData(query, Options.values()))) { 409 424 assertEquals("runtime error: Query ran out of memory in \"query\" at line 5.", ds.getRemark()); 410 425 } … … 421 436 DataSet ds = testValidData(testData); 422 437 assertEquals(0, ds.getNodes().iterator().next().getKeys().size()); 423 424 ds = testValidData(testData, true); 438 assertEquals(1, ds.getNodes().iterator().next().getUniqueId()); 439 440 ds = testValidData(testData, Options.CONVERT_UNKNOWN_TO_TAGS); 425 441 Node firstNode = ds.getNodes().iterator().next(); 426 442 assertEquals(1, firstNode.getKeys().size()); 427 443 assertEquals("randomvalue", firstNode.get("randomkey")); 428 429 ds = testValidData(testData, false); 444 assertEquals(1, ds.getNodes().iterator().next().getUniqueId()); 445 446 447 ds = testValidData(testData, (Options) null); 430 448 assertEquals(0, ds.getNodes().iterator().next().getKeys().size()); 449 assertEquals(1, ds.getNodes().iterator().next().getUniqueId()); 431 450 } 432 451 }
Note:
See TracChangeset
for help on using the changeset viewer.