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.HashMap;
22  import java.util.LinkedHashMap;
23  import java.util.Map;
24  import java.util.TreeMap;
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.TestBean5;
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-5.xml</code>.</p>
36   */
37  public class VariableResolverImpl5TestCase extends AbstractJsfTestCase {
38      
39  
40      // ------------------------------------------------------------ Constructors
41  
42  
43      // Construct a new instance of this test case
44      public VariableResolverImpl5TestCase(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-5.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  
73      // Return the tests included in this test case.
74      public static Test suite() {
75          return new TestSuite(VariableResolverImpl5TestCase.class);
76      }
77  
78  
79      // Tear down instance variables required by this test case
80      protected void tearDown() throws Exception {
81  
82          // Release tested instances
83          resolver = null;
84  
85          // Finalize our context listener
86          listener.contextDestroyed(new ServletContextEvent(servletContext));
87          listener = null;
88  
89          // Tear down the mock web application environment
90          super.tearDown();
91  
92      }
93  
94  
95      // ------------------------------------------------------ Instance Variables
96  
97  
98      // LifecycleListener instance to be tested
99      LifecycleListener listener = null;
100 
101     // VariableResolverImpl instance to be tested
102     VariableResolverImpl resolver = null;
103 
104 
105     // ------------------------------------------------------------ Test Methods
106 
107 
108     // Test creating bean "stringIntegerMap"
109     public void testStringIntegerMap() {
110 
111         Object instance = resolver.resolveVariable(facesContext, "stringIntegerMap");
112         assertNotNull(instance);
113         assertTrue(instance instanceof TreeMap);
114         Map map = (Map) instance;
115         assertEquals(4, map.size());
116 
117         assertEquals(new Integer(123), map.get("First"));
118         assertEquals(new Integer(234), map.get("Second"));
119         assertNull(map.get("Third"));
120         assertEquals(new Integer(345), map.get("Fourth"));
121 
122     }
123 
124 
125     // Test creating bean "listPropertiesBean"
126     public void testMapPropertiesBean() {
127 
128         Object instance = resolver.resolveVariable(facesContext, "mapPropertiesBean");
129         assertNotNull(instance);
130         assertTrue(instance instanceof TestBean5);
131         TestBean5 bean = (TestBean5) instance;
132 
133         Map emptyMap = bean.getEmptyMap();
134         assertNotNull(emptyMap);
135         assertTrue(emptyMap instanceof HashMap);
136         assertEquals(3, emptyMap.size());
137 
138         Map fullMap = bean.getFullMap();
139         assertNotNull(fullMap);
140         assertTrue(fullMap instanceof LinkedHashMap);
141         assertEquals(4, fullMap.size());
142 
143     }
144 
145 }