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