source: josm/trunk/test/unit/org/openstreetmap/josm/data/validation/routines/UrlValidatorTest.java@ 9967

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

cleanup unit tests

  • Property svn:eol-style set to native
File size: 28.6 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.openstreetmap.josm.data.validation.routines;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertFalse;
21import static org.junit.Assert.assertTrue;
22
23import org.junit.Before;
24import org.junit.Test;
25
26/**
27 * Performs Validation Test for url validations.
28 *
29 * @version $Revision: 1715076 $
30 */
31public class UrlValidatorTest {
32
33 private final boolean printStatus = false;
34 private final boolean printIndex = false; //print index that indicates current scheme,host,port,path, query test were using.
35
36 /**
37 * Setup
38 */
39 @Before
40 public void setUp() {
41 for (int index = 0; index < testPartsIndex.length - 1; index++) {
42 testPartsIndex[index] = 0;
43 }
44 }
45
46 /**
47 * Test is valid
48 */
49 @Test
50 public void testIsValid() {
51 testIsValid(testUrlParts, UrlValidator.ALLOW_ALL_SCHEMES);
52 setUp();
53 long options =
54 UrlValidator.ALLOW_2_SLASHES
55 + UrlValidator.ALLOW_ALL_SCHEMES
56 + UrlValidator.NO_FRAGMENTS;
57
58 testIsValid(testUrlPartsOptions, options);
59 }
60
61 /**
62 * Test is valid scheme
63 */
64 @Test
65 public void testIsValidScheme() {
66 if (printStatus) {
67 System.out.print("\n testIsValidScheme() ");
68 }
69 //UrlValidator urlVal = new UrlValidator(schemes,false,false,false);
70 UrlValidator urlVal = new UrlValidator(schemes, 0);
71 for (int sIndex = 0; sIndex < testScheme.length; sIndex++) {
72 ResultPair testPair = testScheme[sIndex];
73 boolean result = urlVal.isValidScheme(testPair.item);
74 assertEquals(testPair.item, testPair.valid, result);
75 if (printStatus) {
76 if (result == testPair.valid) {
77 System.out.print('.');
78 } else {
79 System.out.print('X');
80 }
81 }
82 }
83 if (printStatus) {
84 System.out.println();
85 }
86 }
87
88 /**
89 * Create set of tests by taking the testUrlXXX arrays and
90 * running through all possible permutations of their combinations.
91 *
92 * @param testObjects Used to create a url.
93 * @param options options
94 */
95 private void testIsValid(Object[] testObjects, long options) {
96 UrlValidator urlVal = new UrlValidator(null, null, options);
97 assertTrue(urlVal.isValid("http://www.google.com"));
98 assertTrue(urlVal.isValid("http://www.google.com/"));
99 int statusPerLine = 60;
100 int printed = 0;
101 if (printIndex) {
102 statusPerLine = 6;
103 }
104 do {
105 StringBuilder testBuffer = new StringBuilder();
106 boolean expected = true;
107 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) {
108 int index = testPartsIndex[testPartsIndexIndex];
109 ResultPair[] part = (ResultPair[]) testObjects[testPartsIndexIndex];
110 testBuffer.append(part[index].item);
111 expected &= part[index].valid;
112 }
113 String url = testBuffer.toString();
114 boolean result = urlVal.isValid(url);
115 assertEquals(url, expected, result);
116 if (printStatus) {
117 if (printIndex) {
118 System.out.print(testPartsIndextoString());
119 } else {
120 if (result == expected) {
121 System.out.print('.');
122 } else {
123 System.out.print('X');
124 }
125 }
126 printed++;
127 if (printed == statusPerLine) {
128 System.out.println();
129 printed = 0;
130 }
131 }
132 } while (incrementTestPartsIndex(testPartsIndex, testObjects));
133 if (printStatus) {
134 System.out.println();
135 }
136 }
137
138 /**
139 * Non-regression test for VALIDATOR-202
140 */
141 @Test
142 public void testValidator202() {
143 String[] schemes = {"http", "https"};
144 UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS);
145 assertTrue(urlValidator.isValid(
146 "http://l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.org"));
147 }
148
149 /**
150 * Non-regression test for VALIDATOR-204
151 */
152 @Test
153 public void testValidator204() {
154 String[] schemes = {"http", "https"};
155 UrlValidator urlValidator = new UrlValidator(schemes);
156 assertTrue(urlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5"));
157 }
158
159 /**
160 * Non-regression test for VALIDATOR-218
161 */
162 @Test
163 public void testValidator218() {
164 UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES);
165 assertTrue("parentheses should be valid in URLs",
166 validator.isValid("http://somewhere.com/pathxyz/file(1).html"));
167 }
168
169 /**
170 * Non-regression test for VALIDATOR-235
171 */
172 @Test
173 public void testValidator235() {
174 String version = System.getProperty("java.version");
175 if (version.compareTo("1.6") < 0) {
176 System.out.println("Cannot run Unicode IDN tests");
177 return; // Cannot run the test
178 }
179 UrlValidator validator = new UrlValidator();
180 assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("http://xn--d1abbgf6aiiy.xn--p1ai"));
181 assertTrue("президент.рф should validate", validator.isValid("http://президент.рф"));
182 assertTrue("www.b\u00fccher.ch should validate", validator.isValid("http://www.b\u00fccher.ch"));
183 assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("http://www.\uFFFD.ch"));
184 assertTrue("www.b\u00fccher.ch should validate", validator.isValid("ftp://www.b\u00fccher.ch"));
185 assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("ftp://www.\uFFFD.ch"));
186 }
187
188 /**
189 * Non-regression test for VALIDATOR-248
190 */
191 @Test
192 public void testValidator248() {
193 RegexValidator regex = new RegexValidator(new String[] {"localhost", ".*\\.my-testing"});
194 UrlValidator validator = new UrlValidator(regex, 0);
195
196 assertTrue("localhost URL should validate",
197 validator.isValid("http://localhost/test/index.html"));
198 assertTrue("first.my-testing should validate",
199 validator.isValid("http://first.my-testing/test/index.html"));
200 assertTrue("sup3r.my-testing should validate",
201 validator.isValid("http://sup3r.my-testing/test/index.html"));
202
203 assertFalse("broke.my-test should not validate",
204 validator.isValid("http://broke.my-test/test/index.html"));
205
206 assertTrue("www.apache.org should still validate",
207 validator.isValid("http://www.apache.org/test/index.html"));
208
209 // Now check using options
210 validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
211
212 assertTrue("localhost URL should validate",
213 validator.isValid("http://localhost/test/index.html"));
214
215 assertTrue("machinename URL should validate",
216 validator.isValid("http://machinename/test/index.html"));
217
218 assertTrue("www.apache.org should still validate",
219 validator.isValid("http://www.apache.org/test/index.html"));
220 }
221
222 /**
223 * Non-regression test for VALIDATOR-288
224 */
225 @Test
226 public void testValidator288() {
227 UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
228
229 assertTrue("hostname should validate",
230 validator.isValid("http://hostname"));
231
232 assertTrue("hostname with path should validate",
233 validator.isValid("http://hostname/test/index.html"));
234
235 assertTrue("localhost URL should validate",
236 validator.isValid("http://localhost/test/index.html"));
237
238 assertFalse("first.my-testing should not validate",
239 validator.isValid("http://first.my-testing/test/index.html"));
240
241 assertFalse("broke.hostname should not validate",
242 validator.isValid("http://broke.hostname/test/index.html"));
243
244 assertTrue("www.apache.org should still validate",
245 validator.isValid("http://www.apache.org/test/index.html"));
246
247 // Turn it off, and check
248 validator = new UrlValidator(0);
249
250 assertFalse("hostname should no longer validate",
251 validator.isValid("http://hostname"));
252
253 assertFalse("localhost URL should no longer validate",
254 validator.isValid("http://localhost/test/index.html"));
255
256 assertTrue("www.apache.org should still validate",
257 validator.isValid("http://www.apache.org/test/index.html"));
258 }
259
260 /**
261 * Non-regression test for VALIDATOR-276
262 */
263 @Test
264 public void testValidator276() {
265 // file:// isn't allowed by default
266 UrlValidator validator = new UrlValidator();
267
268 assertTrue("http://apache.org/ should be allowed by default",
269 validator.isValid("http://www.apache.org/test/index.html"));
270
271 assertFalse("file:///c:/ shouldn't be allowed by default",
272 validator.isValid("file:///C:/some.file"));
273
274 assertFalse("file:///c:\\ shouldn't be allowed by default",
275 validator.isValid("file:///C:\\some.file"));
276
277 assertFalse("file:///etc/ shouldn't be allowed by default",
278 validator.isValid("file:///etc/hosts"));
279
280 assertFalse("file://localhost/etc/ shouldn't be allowed by default",
281 validator.isValid("file://localhost/etc/hosts"));
282
283 assertFalse("file://localhost/c:/ shouldn't be allowed by default",
284 validator.isValid("file://localhost/c:/some.file"));
285
286 // Turn it on, and check
287 // Note - we need to enable local urls when working with file:
288 validator = new UrlValidator(new String[] {"http", "file"}, UrlValidator.ALLOW_LOCAL_URLS);
289
290 assertTrue("http://apache.org/ should be allowed by default",
291 validator.isValid("http://www.apache.org/test/index.html"));
292
293 assertTrue("file:///c:/ should now be allowed",
294 validator.isValid("file:///C:/some.file"));
295
296 // Currently, we don't support the c:\ form
297 assertFalse("file:///c:\\ shouldn't be allowed",
298 validator.isValid("file:///C:\\some.file"));
299
300 assertTrue("file:///etc/ should now be allowed",
301 validator.isValid("file:///etc/hosts"));
302
303 assertTrue("file://localhost/etc/ should now be allowed",
304 validator.isValid("file://localhost/etc/hosts"));
305
306 assertTrue("file://localhost/c:/ should now be allowed",
307 validator.isValid("file://localhost/c:/some.file"));
308
309 // These are never valid
310 assertFalse("file://c:/ shouldn't ever be allowed, needs file:///c:/",
311 validator.isValid("file://C:/some.file"));
312
313 assertFalse("file://c:\\ shouldn't ever be allowed, needs file:///c:/",
314 validator.isValid("file://C:\\some.file"));
315 }
316
317 /**
318 * Non-regression test for VALIDATOR-309
319 */
320 @Test
321 public void testValidator309() {
322 UrlValidator urlValidator = new UrlValidator();
323 assertTrue(urlValidator.isValid("http://sample.ondemand.com/"));
324 assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/"));
325 assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/"));
326 urlValidator = new UrlValidator(new String[] {"HTTP", "HTTPS"});
327 assertTrue(urlValidator.isValid("http://sample.ondemand.com/"));
328 assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/"));
329 assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/"));
330 }
331
332 /**
333 * Non-regression test for VALIDATOR-339
334 */
335 @Test
336 public void testValidator339() {
337 UrlValidator urlValidator = new UrlValidator();
338 assertTrue(urlValidator.isValid("http://www.cnn.com/WORLD/?hpt=sitenav")); // without
339 assertTrue(urlValidator.isValid("http://www.cnn.com./WORLD/?hpt=sitenav")); // with
340 assertFalse(urlValidator.isValid("http://www.cnn.com../")); // doubly dotty
341 assertFalse(urlValidator.isValid("http://www.cnn.invalid/"));
342 assertFalse(urlValidator.isValid("http://www.cnn.invalid./")); // check . does not affect invalid domains
343 }
344
345 /**
346 * Non-regression test for VALIDATOR-339 - IDN
347 */
348 @Test
349 public void testValidator339IDN() {
350 UrlValidator urlValidator = new UrlValidator();
351 assertTrue(urlValidator.isValid("http://президент.рф/WORLD/?hpt=sitenav")); // without
352 assertTrue(urlValidator.isValid("http://президент.рф./WORLD/?hpt=sitenav")); // with
353 assertFalse(urlValidator.isValid("http://президент.рф..../")); // very dotty
354 assertFalse(urlValidator.isValid("http://президент.рф.../")); // triply dotty
355 assertFalse(urlValidator.isValid("http://президент.рф../")); // doubly dotty
356 }
357
358 /**
359 * Non-regression test for VALIDATOR-342
360 */
361 @Test
362 public void testValidator342() {
363 UrlValidator urlValidator = new UrlValidator();
364 assertTrue(urlValidator.isValid("http://example.rocks/"));
365 assertTrue(urlValidator.isValid("http://example.rocks"));
366 }
367
368 static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts) {
369 boolean carry = true; //add 1 to lowest order part.
370 boolean maxIndex = true;
371 for (int testPartsIndexIndex = testPartsIndex.length - 1; testPartsIndexIndex >= 0; --testPartsIndexIndex) {
372 int index = testPartsIndex[testPartsIndexIndex];
373 ResultPair[] part = (ResultPair[]) testParts[testPartsIndexIndex];
374 if (carry) {
375 if (index < part.length - 1) {
376 index++;
377 testPartsIndex[testPartsIndexIndex] = index;
378 carry = false;
379 } else {
380 testPartsIndex[testPartsIndexIndex] = 0;
381 carry = true;
382 }
383 }
384 maxIndex &= (index == (part.length - 1));
385 }
386
387 return (!maxIndex);
388 }
389
390 private String testPartsIndextoString() {
391 StringBuilder carryMsg = new StringBuilder("{");
392 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) {
393 carryMsg.append(testPartsIndex[testPartsIndexIndex]);
394 if (testPartsIndexIndex < testPartsIndex.length - 1) {
395 carryMsg.append(',');
396 } else {
397 carryMsg.append('}');
398 }
399 }
400 return carryMsg.toString();
401 }
402
403 /**
404 * Non-regression test for VALIDATOR-290
405 */
406 @Test
407 public void testValidator290() {
408 UrlValidator validator = new UrlValidator();
409 assertTrue(validator.isValid("http://xn--h1acbxfam.idn.icann.org/"));
410// assertTrue(validator.isValid("http://xn--e1afmkfd.xn--80akhbyknj4f"));
411 // Internationalized country code top-level domains
412 assertTrue(validator.isValid("http://test.xn--lgbbat1ad8j")); //Algeria
413 assertTrue(validator.isValid("http://test.xn--fiqs8s")); // China
414 assertTrue(validator.isValid("http://test.xn--fiqz9s")); // China
415 assertTrue(validator.isValid("http://test.xn--wgbh1c")); // Egypt
416 assertTrue(validator.isValid("http://test.xn--j6w193g")); // Hong Kong
417 assertTrue(validator.isValid("http://test.xn--h2brj9c")); // India
418 assertTrue(validator.isValid("http://test.xn--mgbbh1a71e")); // India
419 assertTrue(validator.isValid("http://test.xn--fpcrj9c3d")); // India
420 assertTrue(validator.isValid("http://test.xn--gecrj9c")); // India
421 assertTrue(validator.isValid("http://test.xn--s9brj9c")); // India
422 assertTrue(validator.isValid("http://test.xn--xkc2dl3a5ee0h")); // India
423 assertTrue(validator.isValid("http://test.xn--45brj9c")); // India
424 assertTrue(validator.isValid("http://test.xn--mgba3a4f16a")); // Iran
425 assertTrue(validator.isValid("http://test.xn--mgbayh7gpa")); // Jordan
426 assertTrue(validator.isValid("http://test.xn--mgbc0a9azcg")); // Morocco
427 assertTrue(validator.isValid("http://test.xn--ygbi2ammx")); // Palestinian Territory
428 assertTrue(validator.isValid("http://test.xn--wgbl6a")); // Qatar
429 assertTrue(validator.isValid("http://test.xn--p1ai")); // Russia
430 assertTrue(validator.isValid("http://test.xn--mgberp4a5d4ar")); // Saudi Arabia
431 assertTrue(validator.isValid("http://test.xn--90a3ac")); // Serbia
432 assertTrue(validator.isValid("http://test.xn--yfro4i67o")); // Singapore
433 assertTrue(validator.isValid("http://test.xn--clchc0ea0b2g2a9gcd")); // Singapore
434 assertTrue(validator.isValid("http://test.xn--3e0b707e")); // South Korea
435 assertTrue(validator.isValid("http://test.xn--fzc2c9e2c")); // Sri Lanka
436 assertTrue(validator.isValid("http://test.xn--xkc2al3hye2a")); // Sri Lanka
437 assertTrue(validator.isValid("http://test.xn--ogbpf8fl")); // Syria
438 assertTrue(validator.isValid("http://test.xn--kprw13d")); // Taiwan
439 assertTrue(validator.isValid("http://test.xn--kpry57d")); // Taiwan
440 assertTrue(validator.isValid("http://test.xn--o3cw4h")); // Thailand
441 assertTrue(validator.isValid("http://test.xn--pgbs0dh")); // Tunisia
442 assertTrue(validator.isValid("http://test.xn--mgbaam7a8h")); // United Arab Emirates
443 // Proposed internationalized ccTLDs
444// assertTrue(validator.isValid("http://test.xn--54b7fta0cc")); // Bangladesh
445// assertTrue(validator.isValid("http://test.xn--90ae")); // Bulgaria
446// assertTrue(validator.isValid("http://test.xn--node")); // Georgia
447// assertTrue(validator.isValid("http://test.xn--4dbrk0ce")); // Israel
448// assertTrue(validator.isValid("http://test.xn--mgb9awbf")); // Oman
449// assertTrue(validator.isValid("http://test.xn--j1amh")); // Ukraine
450// assertTrue(validator.isValid("http://test.xn--mgb2ddes")); // Yemen
451 // Test TLDs
452// assertTrue(validator.isValid("http://test.xn--kgbechtv")); // Arabic
453// assertTrue(validator.isValid("http://test.xn--hgbk6aj7f53bba")); // Persian
454// assertTrue(validator.isValid("http://test.xn--0zwm56d")); // Chinese
455// assertTrue(validator.isValid("http://test.xn--g6w251d")); // Chinese
456// assertTrue(validator.isValid("http://test.xn--80akhbyknj4f")); // Russian
457// assertTrue(validator.isValid("http://test.xn--11b5bs3a9aj6g")); // Hindi
458// assertTrue(validator.isValid("http://test.xn--jxalpdlp")); // Greek
459// assertTrue(validator.isValid("http://test.xn--9t4b11yi5a")); // Korean
460// assertTrue(validator.isValid("http://test.xn--deba0ad")); // Yiddish
461// assertTrue(validator.isValid("http://test.xn--zckzah")); // Japanese
462// assertTrue(validator.isValid("http://test.xn--hlcj6aya9esc7a")); // Tamil
463 }
464
465 /**
466 * Non-regression test for VALIDATOR-361
467 */
468 @Test
469 public void testValidator361() {
470 UrlValidator validator = new UrlValidator();
471 assertTrue(validator.isValid("http://hello.tokyo/"));
472 }
473
474 /**
475 * Non-regression test for VALIDATOR-363
476 */
477 @Test
478 public void testValidator363() {
479 UrlValidator urlValidator = new UrlValidator();
480 assertTrue(urlValidator.isValid("http://www.example.org/a/b/hello..world"));
481 assertTrue(urlValidator.isValid("http://www.example.org/a/hello..world"));
482 assertTrue(urlValidator.isValid("http://www.example.org/hello.world/"));
483 assertTrue(urlValidator.isValid("http://www.example.org/hello..world/"));
484 assertTrue(urlValidator.isValid("http://www.example.org/hello.world"));
485 assertTrue(urlValidator.isValid("http://www.example.org/hello..world"));
486 assertTrue(urlValidator.isValid("http://www.example.org/..world"));
487 assertTrue(urlValidator.isValid("http://www.example.org/.../world"));
488 assertFalse(urlValidator.isValid("http://www.example.org/../world"));
489 assertFalse(urlValidator.isValid("http://www.example.org/.."));
490 assertFalse(urlValidator.isValid("http://www.example.org/../"));
491 assertFalse(urlValidator.isValid("http://www.example.org/./.."));
492 assertFalse(urlValidator.isValid("http://www.example.org/././.."));
493 assertTrue(urlValidator.isValid("http://www.example.org/..."));
494 assertTrue(urlValidator.isValid("http://www.example.org/.../"));
495 assertTrue(urlValidator.isValid("http://www.example.org/.../.."));
496 }
497
498 /**
499 * Non-regression test for VALIDATOR-375
500 */
501 @Test
502 public void testValidator375() {
503 UrlValidator validator = new UrlValidator();
504 String url = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html";
505 assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url));
506 url = "http://[::1]:80/index.html";
507 assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url));
508 url = "http://FEDC:BA98:7654:3210:FEDC:BA98:7654:3210:80/index.html";
509 assertFalse("IPv6 address without [] should not validate: " + url, validator.isValid(url));
510 }
511
512 /**
513 * Non-regression test for VALIDATOR-353
514 */
515 @Test
516 public void testValidator353() { // userinfo
517 UrlValidator validator = new UrlValidator();
518 assertTrue(validator.isValid("http://www.apache.org:80/path"));
519 assertTrue(validator.isValid("http://user:pass@www.apache.org:80/path"));
520 assertTrue(validator.isValid("http://user:@www.apache.org:80/path"));
521 assertTrue(validator.isValid("http://us%00er:-._~!$&'()*+,;=@www.apache.org:80/path"));
522 assertFalse(validator.isValid("http://:pass@www.apache.org:80/path"));
523 assertFalse(validator.isValid("http://:@www.apache.org:80/path"));
524 assertFalse(validator.isValid("http://user:pa:ss@www.apache.org/path"));
525 assertFalse(validator.isValid("http://user:pa@ss@www.apache.org/path"));
526 }
527
528 /**
529 * Non-regression test for VALIDATOR-382
530 */
531 @Test
532 public void testValidator382() {
533 UrlValidator validator = new UrlValidator();
534 assertTrue(validator.isValid("ftp://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose"));
535 }
536
537 /**
538 * Non-regression test for VALIDATOR-380
539 */
540 @Test
541 public void testValidator380() {
542 UrlValidator validator = new UrlValidator();
543 assertTrue(validator.isValid("http://www.apache.org:80/path"));
544 assertTrue(validator.isValid("http://www.apache.org:8/path"));
545 assertTrue(validator.isValid("http://www.apache.org:/path"));
546 }
547
548 //-------------------- Test data for creating a composite URL
549 /**
550 * The data given below approximates the 4 parts of a URL
551 * {@code <scheme>://<authority><path>?<query>} except that the port number
552 * is broken out of authority to increase the number of permutations.
553 * A complete URL is composed of a scheme+authority+port+path+query,
554 * all of which must be individually valid for the entire URL to be considered
555 * valid.
556 */
557 ResultPair[] testUrlScheme = {new ResultPair("http://", true),
558 new ResultPair("ftp://", true),
559 new ResultPair("h3t://", true),
560 new ResultPair("3ht://", false),
561 new ResultPair("http:/", false),
562 new ResultPair("http:", false),
563 new ResultPair("http/", false),
564 new ResultPair("://", false),
565 new ResultPair("", true)};
566
567 ResultPair[] testUrlAuthority = {new ResultPair("www.google.com", true),
568 new ResultPair("go.com", true),
569 new ResultPair("go.au", true),
570 new ResultPair("0.0.0.0", true),
571 new ResultPair("255.255.255.255", true),
572 new ResultPair("256.256.256.256", false),
573 new ResultPair("255.com", true),
574 new ResultPair("1.2.3.4.5", false),
575 new ResultPair("1.2.3.4.", false),
576 new ResultPair("1.2.3", false),
577 new ResultPair(".1.2.3.4", false),
578 new ResultPair("go.a", false),
579 new ResultPair("go.a1a", false),
580 new ResultPair("go.cc", true),
581 new ResultPair("go.1aa", false),
582 new ResultPair("aaa.", false),
583 new ResultPair(".aaa", false),
584 new ResultPair("aaa", false),
585 new ResultPair("", false)
586 };
587 ResultPair[] testUrlPort = {new ResultPair(":80", true),
588 new ResultPair(":65535", true),
589 new ResultPair(":0", true),
590 new ResultPair("", true),
591 new ResultPair(":-1", false),
592 new ResultPair(":65636", true),
593 new ResultPair(":65a", false)
594 };
595 ResultPair[] testPath = {new ResultPair("/test1", true),
596 new ResultPair("/t123", true),
597 new ResultPair("/$23", true),
598 new ResultPair("/..", false),
599 new ResultPair("/../", false),
600 new ResultPair("/test1/", true),
601 new ResultPair("", true),
602 new ResultPair("/test1/file", true),
603 new ResultPair("/..//file", false),
604 new ResultPair("/test1//file", false)
605 };
606 //Test allow2slash, noFragment
607 ResultPair[] testUrlPathOptions = {new ResultPair("/test1", true),
608 new ResultPair("/t123", true),
609 new ResultPair("/$23", true),
610 new ResultPair("/..", false),
611 new ResultPair("/../", false),
612 new ResultPair("/test1/", true),
613 new ResultPair("/#", false),
614 new ResultPair("", true),
615 new ResultPair("/test1/file", true),
616 new ResultPair("/t123/file", true),
617 new ResultPair("/$23/file", true),
618 new ResultPair("/../file", false),
619 new ResultPair("/..//file", false),
620 new ResultPair("/test1//file", true),
621 new ResultPair("/#/file", false)
622 };
623
624 ResultPair[] testUrlQuery = {new ResultPair("?action=view", true),
625 new ResultPair("?action=edit&mode=up", true),
626 new ResultPair("", true)
627 };
628
629 Object[] testUrlParts = {testUrlScheme, testUrlAuthority, testUrlPort, testPath, testUrlQuery};
630 Object[] testUrlPartsOptions = {testUrlScheme, testUrlAuthority, testUrlPort, testUrlPathOptions, testUrlQuery};
631 int[] testPartsIndex = {0, 0, 0, 0, 0};
632
633 //---------------- Test data for individual url parts ----------------
634 private final String[] schemes = {"http", "gopher", "g0-To+.",
635 "not_valid" // TODO this will need to be dropped if the ctor validates schemes
636 };
637
638 ResultPair[] testScheme = {new ResultPair("http", true),
639 new ResultPair("ftp", false),
640 new ResultPair("httpd", false),
641 new ResultPair("gopher", true),
642 new ResultPair("g0-to+.", true),
643 new ResultPair("not_valid", false), // underscore not allowed
644 new ResultPair("HtTp", true),
645 new ResultPair("telnet", false)};
646}
Note: See TracBrowser for help on using the repository browser.