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

Last change on this file since 7938 was 7938, checked in by bastiK, 9 years ago

add more subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 4.2 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 testNormal() {
51 def r = createRelation("type=multipolygon")
52 r.addMember(new RelationMember("outer", new Way()))
53 r.addMember(new RelationMember("inner", new Way()))
54 assert testRelation(r).isEmpty()
55 }
56
57 void testOuter2() {
58 def r = createRelation("type=multipolygon")
59 r.addMember(new RelationMember("outer", new Way()))
60 r.addMember(new RelationMember("outer2", new Way()))
61
62 def errors = testRelation(r)
63 assert errors.size() == 1
64 assert errors.get(0).getDescription() == "Role outer2 unknown in templates outer/inner"
65 }
66
67 void testRestrictionViaMissing() {
68 def r = createRelation("type=restriction")
69 r.addMember(new RelationMember("from", new Way()))
70 r.addMember(new RelationMember("to", new Way()))
71
72 def errors = testRelation(r)
73 assert errors.size() == 1
74 assert errors.get(0).getDescription() == "Role via missing"
75 }
76
77 void testRestrictionViaRelation() {
78 def r = createRelation("type=restriction")
79 r.addMember(new RelationMember("from", new Way()))
80 r.addMember(new RelationMember("to", new Way()))
81 r.addMember(new RelationMember("via", new Relation()))
82
83 def errors = testRelation(r)
84 assert errors.size() == 1
85 assert errors.get(0).getDescription() == "Role member type relation does not match accepted list of node/way in template Turn Restriction"
86 }
87
88 void testRestrictionTwoFrom() {
89 def r = createRelation("type=restriction")
90 r.addMember(new RelationMember("from", new Way()))
91 r.addMember(new RelationMember("from", new Way()))
92 r.addMember(new RelationMember("to", new Way()))
93 r.addMember(new RelationMember("via", new Way()))
94
95 def errors = testRelation(r)
96 assert errors.size() == 1
97 assert errors.get(0).getDescription() == "Number of from roles too high (2)"
98 }
99
100 void testRestrictionEmpty() {
101 def r = createRelation("type=restriction")
102 r.addMember(new RelationMember("from", new Way()))
103 r.addMember(new RelationMember("to", new Way()))
104 r.addMember(new RelationMember("via", new Way()))
105 r.addMember(new RelationMember("", new Way()))
106
107 def errors = testRelation(r)
108 assert errors.size() == 1
109 assert errors.get(0).getDescription().startsWith("Empty role type found when expecting one of")
110 }
111
112 void testPowerMemberExpression() {
113 def r = createRelation("type=route route=power")
114 r.addMember(new RelationMember("", new Way()))
115
116 def errors = testRelation(r)
117 assert errors.size() == 1
118 assert errors.get(0).getDescription() == "Role member does not match expression power in template Power Route"
119 }
120}
Note: See TracBrowser for help on using the repository browser.