2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

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   */
17  
18  package org.apache.shale.view.impl;
19  
20  import junit.framework.Test;
21  import junit.framework.TestCase;
22  import junit.framework.TestSuite;
23  
24  /***
25   * <p>Test case for <code>DefaultViewControllerMapper</code>.</p>
26   */
27  public class DefaultViewControllerMapperTestCase extends TestCase {
28      
29  
30      // ------------------------------------------------------------ Constructors
31  
32  
33      // Construct a new instance of this test case.
34      public DefaultViewControllerMapperTestCase(String name) {
35          super(name);
36      }
37  
38  
39      // ---------------------------------------------------- Overall Test Methods
40  
41  
42      // Set up instance variables required by this test case.
43      protected void setUp() throws Exception {
44  
45          super.setUp();
46  
47          // Set up the instance we will be testing
48          dvcm = new DefaultViewControllerMapper();
49  
50      }
51  
52  
53      // Return the tests included in this test case.
54      public static Test suite() {
55  
56          return (new TestSuite(DefaultViewControllerMapperTestCase.class));
57  
58      }
59  
60  
61      // Tear down instance variables required by this test case.
62      protected void tearDown() throws Exception {
63  
64          dvcm = null;
65          super.tearDown();
66  
67      }
68  
69  
70      // ------------------------------------------------------ Instance Variables
71  
72  
73      // The instance to be tested
74      DefaultViewControllerMapper dvcm = null;
75  
76      // The set of reserved managed bean names that should be treated specially
77      String reserved[] = {
78          "applicationScope", "cookie", "facesContext", "header", "headerValues",
79          "initParam", "param", "paramValues", "requestScope", "sessionScope", "view",
80      };
81  
82      // ------------------------------------------------------------ Test Methods
83  
84  
85      // Test multiple directory level mappings
86      public void testMultiple() {
87  
88          assertEquals("foo$bar", dvcm.mapViewId("/foo/bar.jsp"));
89          assertEquals("foo$bar", dvcm.mapViewId("/foo/bar.xxx"));
90          assertEquals("foo$bar", dvcm.mapViewId("foo/bar.jsp"));
91          assertEquals("foo$bar", dvcm.mapViewId("foo/bar.xxx"));
92  
93      }
94  
95  
96      // Test numeric prefix in logical name
97      public void testNumeric() {
98  
99          // Positive ... should be prefixed
100         assertEquals("_1$a", dvcm.mapViewId("/1/a.jsp"));
101         assertEquals("_1$1$a", dvcm.mapViewId("/1/1/a.jsp"));
102 
103         // Negative ... should not be prefixed
104         assertEquals("a$1$b", dvcm.mapViewId("/a/1/b.jsp"));
105 
106     }
107 
108 
109 
110     // Test a pristine instance
111     public void testPristine() {
112 
113         ;
114 
115     }
116 
117 
118     // Test mapping of reserved managed bean names
119     public void testReserved() {
120 
121         for (int i = 0; i < reserved.length; i++) {
122             assertEquals(reserved[i], 
123                          "_" + reserved[i],
124                          dvcm.mapViewId("/" + reserved[i] + ".jsp"));
125         }
126 
127     }
128 
129 
130     // Test single directory level mappings
131     public void testSingle() {
132 
133         assertEquals("foo", dvcm.mapViewId("/foo.jsp"));
134         assertEquals("foo", dvcm.mapViewId("/foo.xxx"));
135         assertEquals("foo", dvcm.mapViewId("foo.jsp"));
136         assertEquals("foo", dvcm.mapViewId("foo.xxx"));
137 
138     }
139 
140 
141 }