KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > utils > UrlUtilsTest


1 package com.tonbeller.wcf.utils;
2
3 import junit.framework.TestCase;
4
5 /**
6  */

7 public class UrlUtilsTest extends TestCase {
8
9   public void testForceExtension() {
10     //.setForceExtension(".faces");
11

12     assertEquals("/a/b.faces", UrlUtils.forceExtension("/a/b.jsp", ".faces"));
13     assertEquals("/a/b.faces?a=b&c=d", UrlUtils.forceExtension("/a/b.jsp?a=b&c=d", ".faces"));
14     assertEquals("/a/b/c", UrlUtils.forceExtension("/a/b/c", ".faces"));
15     assertEquals(null, UrlUtils.forceExtension(null, ".faces"));
16     assertEquals("", UrlUtils.forceExtension("", ".faces"));
17   }
18
19   public void testUrlPatternMatch() {
20     assertTrue(UrlUtils.matchPattern("/a/b.jsp", "*.jsp"));
21     assertTrue(UrlUtils.matchPattern("b.jsp", "*.jsp"));
22     assertFalse(UrlUtils.matchPattern("b.jsq", "*.jsp"));
23     assertFalse(UrlUtils.matchPattern("/", "*.jsp"));
24
25     assertTrue(UrlUtils.matchPattern("/", "/"));
26     assertTrue(UrlUtils.matchPattern("/", "/*"));
27     assertFalse(UrlUtils.matchPattern("/a/b.jsp", "/"));
28     assertTrue(UrlUtils.matchPattern("/a/b.jsp", "/*"));
29
30     assertTrue(UrlUtils.matchPattern("/", "/*"));
31     assertTrue(UrlUtils.matchPattern("/a/b.jsp", "/*"));
32
33     assertFalse(UrlUtils.matchPattern("/", "/a/b/*"));
34     assertFalse(UrlUtils.matchPattern("/a", "/a/b/*"));
35     assertFalse(UrlUtils.matchPattern("/a/", "/a/b/*"));
36     assertFalse(UrlUtils.matchPattern("/a/c", "/a/b/*"));
37     assertFalse(UrlUtils.matchPattern("/a/bc", "/a/b/*"));
38     assertFalse(UrlUtils.matchPattern("/a/b.jsp", "/a/b/*"));
39     assertTrue(UrlUtils.matchPattern("/a/b", "/a/b/*"));
40     assertTrue(UrlUtils.matchPattern("/a/b/", "/a/b/*"));
41     assertTrue(UrlUtils.matchPattern("/a/b/c", "/a/b/*"));
42
43     assertFalse(UrlUtils.matchPattern("/", "/a/*"));
44     assertTrue(UrlUtils.matchPattern("/a/b.jsp", "/a/*"));
45     assertFalse(UrlUtils.matchPattern("/b/a.jsp", "/a/*"));
46
47   }
48
49 }
50
Popular Tags