1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 |
|
---|
5 | import java.util.Calendar;
|
---|
6 | import java.util.GregorianCalendar;
|
---|
7 | import java.util.TimeZone;
|
---|
8 |
|
---|
9 | import org.junit.Test
|
---|
10 | import org.openstreetmap.josm.io.ChangesetQuery.ChangesetQueryUrlException;
|
---|
11 | import org.openstreetmap.josm.io.ChangesetQuery.ChangesetQueryUrlParser;
|
---|
12 |
|
---|
13 |
|
---|
14 | import static org.junit.Assert.*;
|
---|
15 |
|
---|
16 | class ChangesetQueryUrlParserTest {
|
---|
17 | final shouldFail = new GroovyTestCase().&shouldFail
|
---|
18 |
|
---|
19 | @Test
|
---|
20 | public void test_constructor() {
|
---|
21 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
22 | }
|
---|
23 |
|
---|
24 | @Test
|
---|
25 | public void test_parse_basic() {
|
---|
26 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
27 |
|
---|
28 | // OK
|
---|
29 | parser.parse ""
|
---|
30 |
|
---|
31 | // should be OK
|
---|
32 | ChangesetQuery q = parser.parse(null)
|
---|
33 | assert q != null
|
---|
34 |
|
---|
35 | // should be OK
|
---|
36 | q = parser.parse("")
|
---|
37 | assert q != null
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Test
|
---|
41 | public void test_uid() {
|
---|
42 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
43 | def ChangesetQuery q
|
---|
44 |
|
---|
45 | // OK
|
---|
46 | q = parser.parse("uid=1234")
|
---|
47 | assert q != null
|
---|
48 |
|
---|
49 | shouldFail(ChangesetQueryUrlException) {
|
---|
50 | q = parser.parse("uid=0")
|
---|
51 | }
|
---|
52 |
|
---|
53 | shouldFail(ChangesetQueryUrlException) {
|
---|
54 | q = parser.parse("uid=-1")
|
---|
55 | }
|
---|
56 |
|
---|
57 | shouldFail(ChangesetQueryUrlException) {
|
---|
58 | q = parser.parse("uid=abc")
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Test
|
---|
63 | public void test_display_name() {
|
---|
64 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
65 | def ChangesetQuery q
|
---|
66 |
|
---|
67 | // OK
|
---|
68 | q = parser.parse("display_name=abcd")
|
---|
69 | assert q != null
|
---|
70 | assert q.@userName == "abcd"
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | @Test
|
---|
75 | public void test_open() {
|
---|
76 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
77 | def ChangesetQuery q
|
---|
78 |
|
---|
79 | // OK
|
---|
80 | q = parser.parse("open=true")
|
---|
81 | assert q != null
|
---|
82 | assert q.@open == true
|
---|
83 |
|
---|
84 | // OK
|
---|
85 | q = parser.parse("open=false")
|
---|
86 | assert q != null
|
---|
87 | assert q.@open == false
|
---|
88 |
|
---|
89 | // illegal value for open
|
---|
90 | shouldFail(ChangesetQueryUrlException) {
|
---|
91 | q = parser.parse("open=abcd")
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | @Test
|
---|
96 | public void test_closed() {
|
---|
97 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
98 | def ChangesetQuery q
|
---|
99 |
|
---|
100 | // OK
|
---|
101 | q = parser.parse("closed=true")
|
---|
102 | assert q != null
|
---|
103 | assert q.@closed == true
|
---|
104 |
|
---|
105 | // OK
|
---|
106 | q = parser.parse("closed=false")
|
---|
107 | assert q != null
|
---|
108 | assert q.@closed == false
|
---|
109 |
|
---|
110 | // illegal value for open
|
---|
111 | shouldFail(ChangesetQueryUrlException) {
|
---|
112 | q = parser.parse("closed=abcd")
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | @Test
|
---|
118 | public void test_uid_and_display_name() {
|
---|
119 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
120 | def ChangesetQuery q
|
---|
121 |
|
---|
122 | // we can't have both an uid and a display name
|
---|
123 | shouldFail(ChangesetQueryUrlException) {
|
---|
124 | q = parser.parse("uid=1&display_name=abcd")
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | @Test
|
---|
129 | public void test_time() {
|
---|
130 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
131 | def ChangesetQuery q
|
---|
132 |
|
---|
133 | // OK
|
---|
134 | q = parser.parse("time=2009-12-25T10:00:00Z")
|
---|
135 | assert q != null
|
---|
136 | assert q.@closedAfter != null
|
---|
137 | Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT+0"));
|
---|
138 | cal.setTime(q.@closedAfter);
|
---|
139 | assert cal.get(Calendar.YEAR) == 2009
|
---|
140 | assert cal.get(Calendar.MONTH) == 11 // calendar is 0-based
|
---|
141 | assert cal.get(Calendar.DAY_OF_MONTH) == 25
|
---|
142 | assert cal.get(Calendar.HOUR_OF_DAY) == 10
|
---|
143 | assert cal.get(Calendar.MINUTE) == 0
|
---|
144 | assert cal.get(Calendar.SECOND) == 0
|
---|
145 |
|
---|
146 | // OK
|
---|
147 | q = parser.parse("time=2009-12-25T10:00:00Z,2009-11-25T10:00:00Z")
|
---|
148 | assert q!= null
|
---|
149 | assert q.@closedAfter != null
|
---|
150 | assert q.@createdBefore != null
|
---|
151 |
|
---|
152 | // should fail
|
---|
153 | shouldFail(ChangesetQueryUrlException) {
|
---|
154 | q = parser.parse("time=asdf")
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | @Test
|
---|
159 | public void test_bbox() {
|
---|
160 | ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
|
---|
161 | def ChangesetQuery q
|
---|
162 |
|
---|
163 | // OK
|
---|
164 | q = parser.parse("bbox=-1,-1,1,1")
|
---|
165 | assert q != null
|
---|
166 | assert q.@bounds != null
|
---|
167 |
|
---|
168 | // should fail
|
---|
169 | shouldFail(ChangesetQueryUrlException) {
|
---|
170 | q = parser.parse("bbox=-91,-1,1,1")
|
---|
171 | }
|
---|
172 |
|
---|
173 | // should fail
|
---|
174 | shouldFail(ChangesetQueryUrlException) {
|
---|
175 | q = parser.parse("bbox=-1,-181,1,1")
|
---|
176 | }
|
---|
177 |
|
---|
178 | // should fail
|
---|
179 | shouldFail(ChangesetQueryUrlException) {
|
---|
180 | q = parser.parse("bbox=-1,-1,91,1")
|
---|
181 | }
|
---|
182 | // should fail
|
---|
183 | shouldFail(ChangesetQueryUrlException) {
|
---|
184 | q = parser.parse("bbox=-1,-1,1,181")
|
---|
185 | }
|
---|
186 | // should fail
|
---|
187 | shouldFail(ChangesetQueryUrlException) {
|
---|
188 | q = parser.parse("bbox=-1,-1,1")
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|