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.tiger.faces;
19  
20  import java.io.File;
21  import java.util.ArrayList;
22  import java.util.LinkedList;
23  import java.util.List;
24  import java.util.Vector;
25  import javax.servlet.ServletContextEvent;
26  import junit.framework.Test;
27  import junit.framework.TestSuite;
28  import org.apache.shale.test.base.AbstractJsfTestCase;
29  import org.apache.shale.tiger.config.TestBean4;
30  import org.apache.shale.tiger.view.faces.LifecycleListener2;
31  import org.apache.shale.view.faces.LifecycleListener;
32  
33  /***
34   * <p>Test case for <code>org.apache.shale.tiger.faces.VariableResolverImpl</code>
35   * when processing resource <code>/WEB-INF/test-config-4.xml</code>.</p>
36   */
37  public class VariableResolverImpl4TestCase extends AbstractJsfTestCase {
38      
39  
40      // ------------------------------------------------------------ Constructors
41  
42  
43      // Construct a new instance of this test case
44      public VariableResolverImpl4TestCase(String name) {
45          super(name);
46      }
47      
48  
49      // ---------------------------------------------------- Overall Test Methods
50  
51  
52      // Set up instance variables required by this test case.
53      protected void setUp() throws Exception {
54  
55          // Set up mock web application environment
56          super.setUp();
57          servletContext.addInitParameter("javax.faces.CONFIG_FILES",
58                                          "/WEB-INF/test-config-4.xml");
59          File root = new File(System.getProperty("basedir") + "/target/test-webapp");
60          servletContext.setDocumentRoot(root);
61  
62          // Process our configuration information
63          listener = new LifecycleListener2();
64          listener.contextInitialized(new ServletContextEvent(servletContext));
65  
66          // Create resolver instance to be tested
67          // (Force NPEs on delegation use cases by default)
68          resolver = new VariableResolverImpl(null);
69  
70      }
71  
72      // Return the tests included in this test case.
73      public static Test suite() {
74          return new TestSuite(VariableResolverImpl4TestCase.class);
75      }
76  
77  
78      // Tear down instance variables required by this test case
79      protected void tearDown() throws Exception {
80  
81          // Release tested instances
82          resolver = null;
83  
84          // Finalize our context listener
85          listener.contextDestroyed(new ServletContextEvent(servletContext));
86          listener = null;
87  
88          // Tear down the mock web application environment
89          super.tearDown();
90  
91      }
92  
93  
94      // ------------------------------------------------------ Instance Variables
95  
96  
97      // LifecycleListener instance to be tested
98      LifecycleListener listener = null;
99  
100     // VariableResolverImpl instance to be tested
101     VariableResolverImpl resolver = null;
102 
103 
104     // ------------------------------------------------------------ Test Methods
105 
106 
107     // Test creating bean "explicitIntegerList"
108     public void testExplicitIntegerList() {
109 
110         Object instance = resolver.resolveVariable(facesContext, "explicitIntegerList");
111         assertNotNull(instance);
112         assertTrue(instance instanceof Vector);
113         List list = (List) instance;
114         assertEquals(4, list.size());
115 
116         assertEquals(new Integer(123), list.get(0));
117         assertEquals(new Integer(234), list.get(1));
118         assertNull(list.get(2));
119         assertEquals(new Integer(345), list.get(3));
120 
121     }
122 
123 
124     // Test creating bean "explicitStringList"
125     public void testExplicitStringList() {
126 
127         Object instance = resolver.resolveVariable(facesContext, "explicitStringList");
128         assertNotNull(instance);
129         assertTrue(instance instanceof LinkedList);
130         List list = (List) instance;
131         assertEquals(5, list.size());
132 
133         assertEquals("foo", list.get(0));
134         assertEquals("bar", list.get(1));
135         assertNull(list.get(2));
136         assertEquals("baz", list.get(3));
137         assertEquals("bop", list.get(4));
138 
139     }
140 
141 
142     // Test creating bean "implicitStringList"
143     public void testImplicitStringList() {
144 
145         Object instance = resolver.resolveVariable(facesContext, "implicitStringList");
146         assertNotNull(instance);
147         assertTrue(instance instanceof ArrayList);
148         List list = (List) instance;
149         assertEquals(5, list.size());
150 
151         assertEquals("bop", list.get(0));
152         assertNull(list.get(1));
153         assertEquals("baz", list.get(2));
154         assertEquals("bar", list.get(3));
155         assertEquals("foo", list.get(4));
156 
157     }
158 
159 
160     // Test creating bean "listPropertiesBean"
161     public void testListPropertiesBean() {
162 
163         Object instance = resolver.resolveVariable(facesContext, "listPropertiesBean");
164         assertNotNull(instance);
165         assertTrue(instance instanceof TestBean4);
166         TestBean4 bean = (TestBean4) instance;
167 
168         List emptyList = bean.getEmptyList();
169         assertNotNull(emptyList);
170         assertTrue(emptyList instanceof ArrayList);
171         assertEquals(5, emptyList.size());
172 
173         List fullList = bean.getFullList();
174         assertNotNull(fullList);
175         assertTrue(fullList instanceof Vector);
176         assertEquals(7, fullList.size());
177 
178     }
179 
180 
181 }