source: josm/trunk/test/unit/org/openstreetmap/josm/data/validation/tests/RelationCheckerTest.groovy@ 7526

Last change on this file since 7526 was 7526, checked in by Don-vip, 10 years ago

see #10398 - fix unit test broken in r7523

File size: 3.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests
3
4import static org.openstreetmap.josm.data.osm.OsmUtils.createPrimitive
5
6import org.openstreetmap.josm.JOSMFixture
7import org.openstreetmap.josm.data.osm.Relation
8import org.openstreetmap.josm.data.osm.RelationMember
9import org.openstreetmap.josm.data.osm.Way
10import org.openstreetmap.josm.data.validation.TestError
11import org.openstreetmap.josm.gui.tagging.TaggingPresets
12
13class RelationCheckerTest extends GroovyTestCase {
14
15 @Override
16 void setUp() {
17 JOSMFixture.createUnitTestFixture().init();
18 getRelationChecker()
19 }
20
21 static def RelationChecker getRelationChecker() {
22 def checker = new RelationChecker()
23 TaggingPresets.readFromPreferences()
24 checker.initialize()
25 return checker
26 }
27
28 static def List<TestError> testRelation(Relation r) {
29 def checker = getRelationChecker()
30 checker.visit(r)
31 return checker.getErrors()
32 }
33
34 static def Relation createRelation(String tags) {
35 return (Relation) createPrimitive("relation "+ tags)
36 }
37
38 void testUnknownType() {
39 def errors = testRelation(createRelation("type=foobar"))
40 assert errors.size() >= 1
41 assert errors.get(0).getMessage() == "Relation type is unknown"
42 }
43
44 void testEmpty() {
45 def errors = testRelation(createRelation("type=multipolygon"))
46 assert errors.size() == 1
47 assert errors.get(0).getMessage() == "Relation is empty"
48 }
49
50 void testOuter2() {
51 def r = createRelation("type=multipolygon")
52 r.addMember(new RelationMember("outer", new Way()))
53 r.addMember(new RelationMember("outer2", new Way()))
54
55 def errors = testRelation(r)
56 assert errors.size() == 1
57 assert errors.get(0).getDescription() == "Role outer2 unknown"
58 }
59
60 void testRestrictionViaMissing() {
61 def r = createRelation("type=restriction")
62 r.addMember(new RelationMember("from", new Way()))
63 r.addMember(new RelationMember("to", new Way()))
64
65 def errors = testRelation(r)
66 assert errors.size() == 1
67 assert errors.get(0).getDescription() == "Role via missing"
68 }
69
70 void testRestrictionViaRelation() {
71 def r = createRelation("type=restriction")
72 r.addMember(new RelationMember("from", new Way()))
73 r.addMember(new RelationMember("to", new Way()))
74 r.addMember(new RelationMember("via", new Relation()))
75
76 def errors = testRelation(r)
77 assert errors.size() == 1
78 assert errors.get(0).getDescription() == "Member for role via of wrong type"
79 }
80
81 void testRestrictionTwoFrom() {
82 def r = createRelation("type=restriction")
83 r.addMember(new RelationMember("from", new Way()))
84 r.addMember(new RelationMember("from", new Way()))
85 r.addMember(new RelationMember("to", new Way()))
86 r.addMember(new RelationMember("via", new Way()))
87
88 def errors = testRelation(r)
89 assert errors.size() == 1
90 assert errors.get(0).getDescription() == "Number of from roles too high (2)"
91 }
92
93 void testRestrictionEmpty() {
94 def r = createRelation("type=restriction")
95 r.addMember(new RelationMember("from", new Way()))
96 r.addMember(new RelationMember("to", new Way()))
97 r.addMember(new RelationMember("via", new Way()))
98 r.addMember(new RelationMember("", new Way()))
99
100 def errors = testRelation(r)
101 assert errors.size() == 1
102 assert errors.get(0).getDescription() == "Empty role found"
103 }
104
105 void testPowerMemberExpression() {
106 def r = createRelation("type=route route=power")
107 r.addMember(new RelationMember("", new Way()))
108
109 def errors = testRelation(r)
110 assert errors.size() == 1
111 assert errors.get(0).getDescription() == "Member for role '<empty>' does not match 'power'"
112 }
113}
Note: See TracBrowser for help on using the repository browser.