Changeset 8510 in josm for trunk/test/unit/org/openstreetmap/josm/io/ChangesetQueryUrlParserTest.groovy
- Timestamp:
- 2015-06-20T23:42:21+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/ChangesetQueryUrlParserTest.groovy
r7938 r8510 2 2 package org.openstreetmap.josm.io; 3 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.*; 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 15 9 16 10 class ChangesetQueryUrlParserTest { 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 @Test 41 42 43 44 45 46 47 48 49 50 q = parser.parse("uid=0") 51 52 53 54 q = parser.parse("uid=-1") 55 56 57 58 q = parser.parse("uid=abc") 59 60 61 62 @Test 63 64 65 66 67 68 69 70 71 72 73 74 @Test 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 // illegal value for open 90 91 q = parser.parse("open=abcd") 92 } 93 94 95 @Test 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 // illegal value for open 111 112 q = parser.parse("closed=abcd") 113 } 114 115 116 117 @Test 118 119 120 121 122 // we can't have both an uid and a display name 123 124 q = parser.parse("uid=1&display_name=abcd") 125 } 126 127 128 @Test 129 130 131 132 133 134 135 136 assert q.@closedAfter != null 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 q = parser.parse("time=asdf") 155 } 156 157 158 @Test 159 160 161 162 163 164 165 166 167 168 169 170 q = parser.parse("bbox=-91,-1,1,1") 171 } 172 173 174 175 q = parser.parse("bbox=-1,-181,1,1") 176 } 177 178 179 180 q = parser.parse("bbox=-1,-1,91,1") 181 } 182 183 184 q = parser.parse("bbox=-1,-1,1,181") 185 } 186 187 188 q = parser.parse("bbox=-1,-1,1") 189 } 190 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 } 191 185 192 186 @Test
Note:
See TracChangeset
for help on using the changeset viewer.