KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > urls > TestServletURL


1 package org.jahia.urls;
2
3 import junit.framework.*;
4
5 public class TestServletURL extends TestCase {
6     private ServletURL servletURL = null;
7
8     protected void setUp() throws Exception JavaDoc {
9         super.setUp();
10         /**@todo verify the constructors*/
11         servletURL = new ServletURL();
12     }
13
14     protected void tearDown() throws Exception JavaDoc {
15         servletURL = null;
16         super.tearDown();
17     }
18
19     public void testMatchesServletPattern() {
20         String JavaDoc pattern = null;
21         String JavaDoc servletPath = null;
22         boolean expectedReturn = false;
23         boolean actualReturn = servletURL.matchesServletPattern(pattern, servletPath);
24         assertEquals("return value", expectedReturn, actualReturn);
25         /**@todo fill in the test code*/
26
27         // now testing the regular cases
28

29         pattern = "/Jahia/*";
30         servletPath = "/Jahia";
31         expectedReturn = true;
32         actualReturn = servletURL.matchesServletPattern(pattern, servletPath);
33         assertEquals("return value", expectedReturn, actualReturn);
34
35         pattern = "*.do";
36         servletPath = "/Jahia.do";
37         expectedReturn = true;
38         actualReturn = servletURL.matchesServletPattern(pattern, servletPath);
39         assertEquals("return value", expectedReturn, actualReturn);
40
41         pattern = "/exact/Mapping";
42         servletPath = "/exact/Mapping";
43         expectedReturn = true;
44         actualReturn = servletURL.matchesServletPattern(pattern, servletPath);
45         assertEquals("return value", expectedReturn, actualReturn);
46
47         pattern = "/";
48         servletPath = "/any/mapping";
49         expectedReturn = true;
50         actualReturn = servletURL.matchesServletPattern(pattern, servletPath);
51         assertEquals("return value", expectedReturn, actualReturn);
52
53         // now let's test cases that shouldn't match.
54
pattern = "/Jahia/*";
55         servletPath = "Jahia";
56         expectedReturn = false;
57         actualReturn = servletURL.matchesServletPattern(pattern, servletPath);
58         assertEquals("return value", expectedReturn, actualReturn);
59
60         pattern = "*.do";
61         servletPath = ".do.test";
62         expectedReturn = false;
63         actualReturn = servletURL.matchesServletPattern(pattern, servletPath);
64         assertEquals("return value", expectedReturn, actualReturn);
65
66         pattern = "/exact/Mapping";
67         servletPath = "/exact/mapping";
68         expectedReturn = false;
69         actualReturn = servletURL.matchesServletPattern(pattern, servletPath);
70         assertEquals("return value", expectedReturn, actualReturn);
71
72     }
73
74 }
75
Popular Tags