source: josm/trunk/test/unit/org/openstreetmap/josm/io/ChangesetQueryUrlParserTest.groovy@ 14019

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

update to Groovy 2.5.0 and Eclipse Photon (4.8.0)

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io
3
4import static groovy.test.GroovyAssert.shouldFail
5
6import java.time.OffsetDateTime
7import java.time.ZoneOffset
8
9import org.junit.Test
10import org.openstreetmap.josm.io.ChangesetQuery.ChangesetQueryUrlException
11import org.openstreetmap.josm.io.ChangesetQuery.ChangesetQueryUrlParser
12
13class ChangesetQueryUrlParserTest {
14
15 @Test
16 public void testConstructor() {
17 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
18 }
19
20 @Test
21 public void testParseBasic() {
22 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
23
24 // OK
25 parser.parse ""
26
27 // should be OK
28 ChangesetQuery q = parser.parse(null)
29 assert q != null
30
31 // should be OK
32 q = parser.parse("")
33 assert q != null
34 }
35
36 @Test
37 public void testUid() {
38 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
39 def ChangesetQuery q
40
41 // OK
42 q = parser.parse("uid=1234")
43 assert q != null
44
45 shouldFail(ChangesetQueryUrlException) {
46 q = parser.parse("uid=0")
47 }
48
49 shouldFail(ChangesetQueryUrlException) {
50 q = parser.parse("uid=-1")
51 }
52
53 shouldFail(ChangesetQueryUrlException) {
54 q = parser.parse("uid=abc")
55 }
56 }
57
58 @Test
59 public void testDisplayName() {
60 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
61 def ChangesetQuery q
62
63 // OK
64 q = parser.parse("display_name=abcd")
65 assert q != null
66 assert q.@userName == "abcd"
67 }
68
69 @Test
70 public void testOpen() {
71 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
72 def ChangesetQuery q
73
74 // OK
75 q = parser.parse("open=true")
76 assert q != null
77 assert q.@open == true
78
79 // OK
80 q = parser.parse("open=false")
81 assert q != null
82 assert q.@open == false
83
84 // illegal value for open
85 shouldFail(ChangesetQueryUrlException) {
86 q = parser.parse("open=abcd")
87 }
88 }
89
90 @Test
91 public void testClosed() {
92 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
93 def ChangesetQuery q
94
95 // OK
96 q = parser.parse("closed=true")
97 assert q != null
98 assert q.@closed == true
99
100 // OK
101 q = parser.parse("closed=false")
102 assert q != null
103 assert q.@closed == false
104
105 // illegal value for open
106 shouldFail(ChangesetQueryUrlException) {
107 q = parser.parse("closed=abcd")
108 }
109 }
110
111 @Test
112 public void testUidAndDisplayName() {
113 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
114 def ChangesetQuery q
115
116 // we can't have both an uid and a display name
117 shouldFail(ChangesetQueryUrlException) {
118 q = parser.parse("uid=1&display_name=abcd")
119 }
120 }
121
122 @Test
123 public void testTime() {
124 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
125 def ChangesetQuery q
126
127 // OK
128 q = parser.parse("time=2009-12-25T10:00:00Z")
129 assert q != null
130 assert q.@closedAfter != null
131 def cal = q.@closedAfter.toInstant().atOffset(ZoneOffset.UTC)
132 assert cal == OffsetDateTime.of(2009, 12, 25, 10, 0, 0, 0, ZoneOffset.UTC)
133
134 // OK
135 q = parser.parse("time=2009-12-25T10:00:00Z,2009-11-25T10:00:00Z")
136 assert q!= null
137 assert q.@closedAfter != null
138 assert q.@createdBefore != null
139
140 // should fail
141 shouldFail(ChangesetQueryUrlException) {
142 q = parser.parse("time=asdf")
143 }
144 }
145
146 @Test
147 public void testBbox() {
148 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
149 def ChangesetQuery q
150
151 // OK
152 q = parser.parse("bbox=-1,-1,1,1")
153 assert q != null
154 assert q.@bounds != null
155
156 // should fail
157 shouldFail(ChangesetQueryUrlException) {
158 q = parser.parse("bbox=-91,-1,1,1")
159 }
160
161 // should fail
162 shouldFail(ChangesetQueryUrlException) {
163 q = parser.parse("bbox=-1,-181,1,1")
164 }
165
166 // should fail
167 shouldFail(ChangesetQueryUrlException) {
168 q = parser.parse("bbox=-1,-1,91,1")
169 }
170 // should fail
171 shouldFail(ChangesetQueryUrlException) {
172 q = parser.parse("bbox=-1,-1,1,181")
173 }
174 // should fail
175 shouldFail(ChangesetQueryUrlException) {
176 q = parser.parse("bbox=-1,-1,1")
177 }
178 }
179
180 @Test
181 public void testChangesetIds() {
182 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
183 def ChangesetQuery q
184
185 // OK
186 q = parser.parse("changesets=1,2,3")
187 assert q != null
188 assert q.@changesetIds.containsAll(Arrays.asList(1L, 2L, 3L))
189 assert q.@changesetIds.size() == 3
190
191 // OK
192 q = parser.parse("changesets=1,2,3,4,1")
193 assert q != null
194 assert q.@changesetIds.containsAll(Arrays.asList(1L, 2L, 3L, 4L))
195 assert q.@changesetIds.size() == 4
196
197 // OK
198 q = parser.parse("changesets=")
199 assert q != null
200 assert q.@changesetIds.size() == 0
201
202 // should fail
203 shouldFail(ChangesetQueryUrlException) {
204 q = parser.parse("changesets=foo")
205 }
206 }
207}
Note: See TracBrowser for help on using the repository browser.