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;
19  
20  import javax.servlet.ServletContextAttributeListener;
21  
22  import junit.framework.Test;
23  import junit.framework.TestSuite;
24  
25  import org.apache.shale.test.base.AbstractJsfTestCase;
26  import org.apache.shale.view.faces.LifecycleListener;
27  
28  /***
29   * <p>Test case for <code>org.apache.shale.view.AbstractApplicationBean</code>.</p>
30   */
31  public class AbstractApplicationBeanTestCase extends AbstractJsfTestCase {
32      
33      
34      // ------------------------------------------------------------ Constructors
35  
36  
37      // Construct a new instance of this test case.
38      public AbstractApplicationBeanTestCase(String name) {
39          super(name);
40      }
41  
42  
43      // ---------------------------------------------------- Overall Test Methods
44  
45  
46      // Set up instance variables required by this test case.
47      protected void setUp() throws Exception {
48  
49          super.setUp();
50          listener = new ApplicationAttributeListener();
51          servletContext.addAttributeListener(listener);
52          servletContext.addAttributeListener(new LifecycleListener());
53  
54      }
55  
56  
57      // Return the tests included in this test case.
58      public static Test suite() {
59  
60          return (new TestSuite(AbstractApplicationBeanTestCase.class));
61  
62      }
63  
64  
65      // Tear down instance variables required by this test case.
66      protected void tearDown() throws Exception {
67  
68          listener = null;
69          ApplicationAttributeListener.clear();
70          ConcreteApplicationBean.clear();
71          super.tearDown();
72  
73      }
74  
75  
76      // ------------------------------------------------------ Instance Variables
77  
78  
79      ServletContextAttributeListener listener = null;
80  
81  
82      // ------------------------------------------------------------ Test Methods
83  
84  
85  
86      // Test a prisine instance
87      public void testPristine() {
88  
89          assertEquals("", ApplicationAttributeListener.record());
90  
91      }
92  
93  
94      // Test processing an attribute
95      public void testProcess() {
96  
97          assertEquals("", ApplicationAttributeListener.record());
98          ConcreteApplicationBean bean = new ConcreteApplicationBean();
99          assertEquals("", ConcreteApplicationBean.record());
100 
101         servletContext.setAttribute("bean", bean);
102         assertEquals("attributeAdded(bean,ConcreteApplicationBean)//",
103                      ApplicationAttributeListener.record());
104         assertEquals("init()//",
105                      ConcreteApplicationBean.record());
106 
107         servletContext.setAttribute("bean", bean);
108         assertEquals("attributeAdded(bean,ConcreteApplicationBean)//" +
109                      "attributeReplaced(bean,ConcreteApplicationBean)//",
110                      ApplicationAttributeListener.record());
111         assertEquals("init()//destroy()//init()//",
112                      ConcreteApplicationBean.record());
113 
114         servletContext.removeAttribute("bean");
115         assertEquals("attributeAdded(bean,ConcreteApplicationBean)//" +
116                      "attributeReplaced(bean,ConcreteApplicationBean)//" +
117                      "attributeRemoved(bean,ConcreteApplicationBean)//",
118                      ApplicationAttributeListener.record());
119         assertEquals("init()//destroy()//init()//destroy()//",
120                      ConcreteApplicationBean.record());
121 
122     }
123 
124 
125 }