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

Last change on this file since 11035 was 11035, checked in by simon04, 8 years ago

see #13376 - Replace Calendar usages with Java 8 Date API

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