1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.*
|
---|
5 |
|
---|
6 | import org.junit.Test
|
---|
7 | import org.openstreetmap.josm.io.ChangesetQuery.ChangesetQueryUrlException
|
---|
8 | import org.openstreetmap.josm.io.ChangesetQuery.ChangesetQueryUrlParser
|
---|
9 |
|
---|
10 | class ChangesetQueryUrlParserTest {
|
---|
11 | final shouldFail = new GroovyTestCase().&shouldFail
|
---|
12 |
|
---|
13 | @Test
|
---|
14 | public void test_constructor() {
|
---|
15 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
16 | }
|
---|
17 |
|
---|
18 | @Test
|
---|
19 | public void test_parse_basic() {
|
---|
20 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
21 |
|
---|
22 | // OK
|
---|
23 | parser.parse ""
|
---|
24 |
|
---|
25 | // should be OK
|
---|
26 | ChangesetQuery q = parser.parse(null)
|
---|
27 | assert q != null
|
---|
28 |
|
---|
29 | // should be OK
|
---|
30 | q = parser.parse("")
|
---|
31 | assert q != null
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Test
|
---|
35 | public void test_uid() {
|
---|
36 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
37 | def ChangesetQuery q
|
---|
38 |
|
---|
39 | // OK
|
---|
40 | q = parser.parse("uid=1234")
|
---|
41 | assert q != null
|
---|
42 |
|
---|
43 | shouldFail(ChangesetQueryUrlException) {
|
---|
44 | q = parser.parse("uid=0")
|
---|
45 | }
|
---|
46 |
|
---|
47 | shouldFail(ChangesetQueryUrlException) {
|
---|
48 | q = parser.parse("uid=-1")
|
---|
49 | }
|
---|
50 |
|
---|
51 | shouldFail(ChangesetQueryUrlException) {
|
---|
52 | q = parser.parse("uid=abc")
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Test
|
---|
57 | public void test_display_name() {
|
---|
58 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
59 | def ChangesetQuery q
|
---|
60 |
|
---|
61 | // OK
|
---|
62 | q = parser.parse("display_name=abcd")
|
---|
63 | assert q != null
|
---|
64 | assert q.@userName == "abcd"
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | @Test
|
---|
69 | public void test_open() {
|
---|
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 test_closed() {
|
---|
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 |
|
---|
111 | @Test
|
---|
112 | public void test_uid_and_display_name() {
|
---|
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 test_time() {
|
---|
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 | Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT+0"));
|
---|
132 | cal.setTime(q.@closedAfter);
|
---|
133 | assert cal.get(Calendar.YEAR) == 2009
|
---|
134 | assert cal.get(Calendar.MONTH) == 11 // calendar is 0-based
|
---|
135 | assert cal.get(Calendar.DAY_OF_MONTH) == 25
|
---|
136 | assert cal.get(Calendar.HOUR_OF_DAY) == 10
|
---|
137 | assert cal.get(Calendar.MINUTE) == 0
|
---|
138 | assert cal.get(Calendar.SECOND) == 0
|
---|
139 |
|
---|
140 | // OK
|
---|
141 | q = parser.parse("time=2009-12-25T10:00:00Z,2009-11-25T10:00:00Z")
|
---|
142 | assert q!= null
|
---|
143 | assert q.@closedAfter != null
|
---|
144 | assert q.@createdBefore != null
|
---|
145 |
|
---|
146 | // should fail
|
---|
147 | shouldFail(ChangesetQueryUrlException) {
|
---|
148 | q = parser.parse("time=asdf")
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | @Test
|
---|
153 | public void test_bbox() {
|
---|
154 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
155 | def ChangesetQuery q
|
---|
156 |
|
---|
157 | // OK
|
---|
158 | q = parser.parse("bbox=-1,-1,1,1")
|
---|
159 | assert q != null
|
---|
160 | assert q.@bounds != null
|
---|
161 |
|
---|
162 | // should fail
|
---|
163 | shouldFail(ChangesetQueryUrlException) {
|
---|
164 | q = parser.parse("bbox=-91,-1,1,1")
|
---|
165 | }
|
---|
166 |
|
---|
167 | // should fail
|
---|
168 | shouldFail(ChangesetQueryUrlException) {
|
---|
169 | q = parser.parse("bbox=-1,-181,1,1")
|
---|
170 | }
|
---|
171 |
|
---|
172 | // should fail
|
---|
173 | shouldFail(ChangesetQueryUrlException) {
|
---|
174 | q = parser.parse("bbox=-1,-1,91,1")
|
---|
175 | }
|
---|
176 | // should fail
|
---|
177 | shouldFail(ChangesetQueryUrlException) {
|
---|
178 | q = parser.parse("bbox=-1,-1,1,181")
|
---|
179 | }
|
---|
180 | // should fail
|
---|
181 | shouldFail(ChangesetQueryUrlException) {
|
---|
182 | q = parser.parse("bbox=-1,-1,1")
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | @Test
|
---|
187 | public void test_changeset_ids() {
|
---|
188 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
189 | def ChangesetQuery q
|
---|
190 |
|
---|
191 | // OK
|
---|
192 | q = parser.parse("changesets=1,2,3")
|
---|
193 | assert q != null
|
---|
194 | assert q.@changesetIds.containsAll(Arrays.asList(1L, 2L, 3L))
|
---|
195 | assert q.@changesetIds.size() == 3
|
---|
196 |
|
---|
197 | // OK
|
---|
198 | q = parser.parse("changesets=1,2,3,4,1")
|
---|
199 | assert q != null
|
---|
200 | assert q.@changesetIds.containsAll(Arrays.asList(1L, 2L, 3L, 4L))
|
---|
201 | assert q.@changesetIds.size() == 4
|
---|
202 |
|
---|
203 | // OK
|
---|
204 | q = parser.parse("changesets=")
|
---|
205 | assert q != null
|
---|
206 | assert q.@changesetIds.size() == 0
|
---|
207 |
|
---|
208 | // should fail
|
---|
209 | shouldFail(ChangesetQueryUrlException) {
|
---|
210 | q = parser.parse("changesets=foo")
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|