Changeset 7163 in josm for trunk/test
 Timestamp:
 20140522T01:17:51+02:00 (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/functional/org/openstreetmap/josm/io/OsmServerBackreferenceReaderTest.java
r7150 r7163 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 5 6 import static org.junit.Assert.assertNotNull; 7 import static org.junit.Assert.assertTrue; 6 8 import static org.junit.Assert.fail; 7 9 … … 29 31 import org.openstreetmap.josm.data.osm.DataSet; 30 32 import org.openstreetmap.josm.data.osm.Node; 33 import org.openstreetmap.josm.data.osm.OsmPrimitive; 31 34 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 32 35 import org.openstreetmap.josm.data.osm.Relation; … … 202 205 203 206 @Test 204 public void testBackref renceForNode() throws OsmTransferException {207 public void testBackreferenceForNode() throws OsmTransferException { 205 208 Node n = lookupNode(ds, 0); 206 209 assertNotNull(n); … … 212 215 DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE); 213 216 printNumberOfPrimitives(referers); 214 assertEquals(10, referers.getNodes().size()); 215 assertEquals(1, referers.getWays().size()); 216 assertEquals(0, referers.getRelations().size()); 217 218 Set<Long> expectedNodeIds = new HashSet<>(); 219 Set<Long> expectedWayIds = new HashSet<>(); 220 Set<Long> expectedRelationIds = new HashSet<>(); 221 222 for (OsmPrimitive ref : n.getReferrers()) { 223 if (ref instanceof Way) { 224 expectedWayIds.add(ref.getId()); 225 expectedNodeIds.addAll(getNodeIdsInWay((Way) ref)); 226 } else if (ref instanceof Relation) { 227 expectedRelationIds.add(ref.getId()); 228 expectedWayIds.addAll(getWayIdsInRelation((Relation) ref, false)); 229 expectedNodeIds.addAll(getNodeIdsInRelation((Relation) ref, false)); 230 } 231 } 232 233 assertEquals(expectedNodeIds.size(), referers.getNodes().size()); 234 assertEquals(expectedWayIds.size(), referers.getWays().size()); 235 assertEquals(expectedRelationIds.size(), referers.getRelations().size()); 236 237 for (Node node : referers.getNodes()) { 238 assertTrue(expectedNodeIds.contains(node.getId())); 239 assertFalse(node.isIncomplete()); 240 } 241 217 242 for (Way way : referers.getWays()) { 218 assertEquals(w.getId(), way.getId()); 219 assertEquals(false, way.isIncomplete()); 243 assertTrue(expectedWayIds.contains(way.getId())); 244 assertEquals(n.getReferrers().contains(way), !way.isIncomplete()); 245 } 246 247 for (Relation relation : referers.getRelations()) { 248 assertTrue(expectedRelationIds.contains(relation.getId())); 249 assertFalse(relation.isIncomplete()); 220 250 } 221 251 } … … 228 258 229 259 @Test 230 public void testBackref renceForNode_Full() throws OsmTransferException {260 public void testBackreferenceForNode_Full() throws OsmTransferException { 231 261 Node n = lookupNode(ds, 0); 232 262 assertNotNull(n); 233 Way w = lookupWay(ds, 0);234 assertNotNull(w);235 263 236 264 OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(n); … … 238 266 DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE); 239 267 printNumberOfPrimitives(referers); 240 assertEquals(10, referers.getNodes().size()); 241 assertEquals(1, referers.getWays().size()); 242 assertEquals(0, referers.getRelations().size()); 268 269 Set<Long> expectedNodeIds = new HashSet<>(); 270 Set<Long> expectedWayIds = new HashSet<>(); 271 Set<Long> expectedRelationIds = new HashSet<>(); 272 for (OsmPrimitive ref : n.getReferrers()) { 273 if (ref instanceof Way) { 274 expectedWayIds.add(ref.getId()); 275 expectedNodeIds.addAll(getNodeIdsInWay((Way) ref)); 276 } else if (ref instanceof Relation) { 277 expectedRelationIds.add(ref.getId()); 278 expectedWayIds.addAll(getWayIdsInRelation((Relation) ref, true)); 279 expectedNodeIds.addAll(getNodeIdsInRelation((Relation) ref, true)); 280 } 281 } 282 283 assertEquals(expectedNodeIds.size(), referers.getNodes().size()); 284 assertEquals(expectedWayIds.size(), referers.getWays().size()); 285 assertEquals(expectedRelationIds.size(), referers.getRelations().size()); 286 287 for (Node node : referers.getNodes()) { 288 assertTrue(expectedNodeIds.contains(node.getId())); 289 assertFalse(node.isIncomplete()); 290 } 291 243 292 for (Way way : referers.getWays()) { 244 assertEquals(w.getId(), way.getId()); 245 assertEquals(false, way.isIncomplete()); 246 assertEquals(10, w.getNodesCount()); 293 assertTrue(expectedWayIds.contains(way.getId())); 294 assertFalse(way.isIncomplete()); 295 } 296 297 for (Relation relation : referers.getRelations()) { 298 assertTrue(expectedRelationIds.contains(relation.getId())); 299 assertFalse(relation.isIncomplete()); 247 300 } 248 301 } 249 302 250 303 @Test 251 public void testBackref renceForWay() throws OsmTransferException {304 public void testBackreferenceForWay() throws OsmTransferException { 252 305 Way w = lookupWay(ds, 1); 253 306 assertNotNull(w); … … 259 312 DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE); 260 313 printNumberOfPrimitives(referers); 261 assertEquals(0, referers.getNodes().size()); // no nodes loaded 262 assertEquals(6, referers.getWays().size()); // 6 ways referred by two relations 314 315 Set<Long> expectedNodeIds = new HashSet<>(); 316 Set<Long> expectedWayIds = new HashSet<>(); 317 Set<Long> expectedRelationIds = new HashSet<>(); 318 319 for (OsmPrimitive ref : w.getReferrers()) { 320 if (ref instanceof Relation) { 321 expectedRelationIds.add(ref.getId()); 322 expectedWayIds.addAll(getWayIdsInRelation((Relation) ref, false)); 323 expectedNodeIds.addAll(getNodeIdsInRelation((Relation) ref, false)); 324 } 325 } 326 327 assertEquals(expectedNodeIds.size(), referers.getNodes().size()); 328 assertEquals(expectedWayIds.size(), referers.getWays().size()); 329 assertEquals(expectedRelationIds.size(), referers.getRelations().size()); 330 263 331 for (Way w1 : referers.getWays()) { 264 assert Equals(true,w1.isIncomplete());332 assertTrue(w1.isIncomplete()); 265 333 } 266 334 assertEquals(2, referers.getRelations().size()); // two relations referring to w … … 268 336 Relation r = lookupRelation(referers, 0); 269 337 assertNotNull(r); 270 assert Equals(false,r.isIncomplete());338 assertFalse(r.isIncomplete()); 271 339 r = lookupRelation(referers, 1); 272 assert Equals(false,r.isIncomplete());340 assertFalse(r.isIncomplete()); 273 341 } 274 342 275 343 @Test 276 public void testBackref renceForWay_Full() throws OsmTransferException {344 public void testBackreferenceForWay_Full() throws OsmTransferException { 277 345 Way w = lookupWay(ds, 1); 278 346 assertNotNull(w); … … 285 353 assertEquals(6, referers.getWays().size()); // 6 ways referred by two relations 286 354 for (Way w1 : referers.getWays()) { 287 assert Equals(false,w1.isIncomplete());355 assertFalse(w1.isIncomplete()); 288 356 } 289 357 assertEquals(2, referers.getRelations().size()); // two relations referring to … … 297 365 assertEquals(expectedNodeIds.size(), referers.getNodes().size()); 298 366 for (Node n : referers.getNodes()) { 299 assert Equals(true,expectedNodeIds.contains(n.getId()));367 assertTrue(expectedNodeIds.contains(n.getId())); 300 368 } 301 369 302 370 Relation r = lookupRelation(referers, 0); 303 371 assertNotNull(r); 304 assert Equals(false,r.isIncomplete());372 assertFalse(r.isIncomplete()); 305 373 r = lookupRelation(referers, 1); 306 assert Equals(false,r.isIncomplete());374 assertFalse(r.isIncomplete()); 307 375 } 308 376 309 377 @Test 310 public void testBackref renceForRelation() throws OsmTransferException {378 public void testBackreferenceForRelation() throws OsmTransferException { 311 379 Relation r = lookupRelation(ds, 1); 312 380 assertNotNull(r); … … 321 389 322 390 Set<Long> referringRelationsIds = new HashSet<>(); 323 r= lookupRelation(referers, 6);324 assertNotNull(r );325 assert Equals(false, r.isIncomplete());326 referringRelationsIds.add(r .getId());327 r= lookupRelation(referers, 7);328 assertNotNull(r );329 assert Equals(false, r.isIncomplete());330 referringRelationsIds.add(r .getId());331 r= lookupRelation(referers, 8);332 assertNotNull(r );333 assert Equals(false, r.isIncomplete());334 referringRelationsIds.add(r .getId());335 r= lookupRelation(referers, 9);336 assertNotNull(r );337 assert Equals(false, r.isIncomplete());338 referringRelationsIds.add(r .getId());391 Relation r6 = lookupRelation(referers, 6); 392 assertNotNull(r6); 393 assertFalse(r6.isIncomplete()); 394 referringRelationsIds.add(r6.getId()); 395 Relation r7 = lookupRelation(referers, 7); 396 assertNotNull(r7); 397 assertFalse(r7.isIncomplete()); 398 referringRelationsIds.add(r7.getId()); 399 Relation r8 = lookupRelation(referers, 8); 400 assertNotNull(r8); 401 assertFalse(r8.isIncomplete()); 402 referringRelationsIds.add(r8.getId()); 403 Relation r9 = lookupRelation(referers, 9); 404 assertNotNull(r9); 405 assertFalse(r9.isIncomplete()); 406 referringRelationsIds.add(r9.getId()); 339 407 340 408 for (Relation r1 : referers.getRelations()) { 341 409 if (!referringRelationsIds.contains(r1.getId())) { 342 assert Equals(true,r1.isIncomplete());410 assertTrue(r1.isIncomplete()); 343 411 } 344 412 } … … 371 439 assertEquals(expectedWayIds.size(), referers.getWays().size()); 372 440 for (Way w1 : referers.getWays()) { 373 assertEquals(true, expectedWayIds.contains(w1.getId())); 374 assertEquals(true, w1.isIncomplete()); 375 } 376 377 // make sure we didn't read any nodes 378 // 379 assertEquals(0, referers.getNodes().size()); 380 } 381 382 protected Set<Long> getNodeIdsInWay(Way way) { 441 assertTrue(expectedWayIds.contains(w1.getId())); 442 assertTrue(w1.isIncomplete()); 443 } 444 445 // make sure we read all nodes referred to by parent relations. 446 Set<Long> expectedNodeIds = new HashSet<>(); 447 for (OsmPrimitive ref : r.getReferrers()) { 448 if (ref instanceof Relation) { 449 expectedNodeIds.addAll(getNodeIdsInRelation((Relation) ref, false)); 450 } 451 } 452 assertEquals(expectedNodeIds.size(), referers.getNodes().size()); 453 } 454 455 protected static Set<Long> getNodeIdsInWay(Way way) { 383 456 HashSet<Long> ret = new HashSet<>(); 384 457 if (way == null)return ret; … … 389 462 } 390 463 391 protected Set<Long> getNodeIdsInRelation(Relation r) {464 protected static Set<Long> getNodeIdsInRelation(Relation r, boolean children) { 392 465 HashSet<Long> ret = new HashSet<>(); 393 466 if (r == null) return ret; … … 395 468 if (m.isNode()) { 396 469 ret.add(m.getMember().getId()); 397 } else if (m.isWay() ) {470 } else if (m.isWay() && children) { 398 471 ret.addAll(getNodeIdsInWay(m.getWay())); 399 } else if (m.isRelation() ) {400 ret.addAll(getNodeIdsInRelation(m.getRelation() ));472 } else if (m.isRelation() && children) { 473 ret.addAll(getNodeIdsInRelation(m.getRelation(), true)); 401 474 } 402 475 } … … 404 477 } 405 478 479 protected static Set<Long> getWayIdsInRelation(Relation r, boolean children) { 480 HashSet<Long> ret = new HashSet<>(); 481 if (r == null) return ret; 482 for (RelationMember m: r.getMembers()) { 483 if (m.isWay()) { 484 ret.add(m.getMember().getId()); 485 } else if (m.isRelation() && children) { 486 ret.addAll(getWayIdsInRelation(m.getRelation(), true)); 487 } 488 } 489 return ret; 490 } 491 406 492 @Test 407 public void testBackref renceForRelation_Full() throws OsmTransferException {493 public void testBackreferenceForRelation_Full() throws OsmTransferException { 408 494 Relation r = lookupRelation(ds, 1); 409 495 assertNotNull(r); … … 419 505 r = lookupRelation(referers, 6); 420 506 assertNotNull(r); 421 assert Equals(false,r.isIncomplete());507 assertFalse(r.isIncomplete()); 422 508 referringRelationsIds.add(r.getId()); 423 509 r = lookupRelation(referers, 7); 424 510 assertNotNull(r); 425 assert Equals(false,r.isIncomplete());511 assertFalse(r.isIncomplete()); 426 512 referringRelationsIds.add(r.getId()); 427 513 r = lookupRelation(referers, 8); 428 514 assertNotNull(r); 429 assert Equals(false,r.isIncomplete());515 assertFalse(r.isIncomplete()); 430 516 referringRelationsIds.add(r.getId()); 431 517 r = lookupRelation(referers, 9); 432 518 assertNotNull(r); 433 assert Equals(false,r.isIncomplete());519 assertFalse(r.isIncomplete()); 434 520 referringRelationsIds.add(r.getId()); 435 521 … … 437 523 // 438 524 for (Relation r1 : referers.getRelations()) { 439 assert Equals(false,r1.isIncomplete());525 assertFalse(r1.isIncomplete()); 440 526 } 441 527 … … 467 553 Way w = (Way) referers.getPrimitiveById(id, OsmPrimitiveType.WAY); 468 554 assertNotNull(w); 469 assert Equals(false,w.isIncomplete());555 assertFalse(w.isIncomplete()); 470 556 } 471 557 … … 473 559 for (int i = 6; i < 10; i++) { 474 560 Relation r1 = lookupRelation(ds, i); 475 expectedNodeIds.addAll(getNodeIdsInRelation(r1 ));561 expectedNodeIds.addAll(getNodeIdsInRelation(r1, true)); 476 562 } 477 563 478 564 assertEquals(expectedNodeIds.size(), referers.getNodes().size()); 479 565 for (Node n : referers.getNodes()) { 480 assert Equals(true,expectedNodeIds.contains(n.getId()));566 assertTrue(expectedNodeIds.contains(n.getId())); 481 567 } 482 568 }
Note: See TracChangeset
for help on using the changeset viewer.