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.ServletRequestAttributeListener;
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.AbstractRequestBean</code>.</p>
30   */
31  public class AbstractRequestBeanTestCase extends AbstractJsfTestCase {
32      
33      
34      // ------------------------------------------------------------ Constructors
35  
36  
37      // Construct a new instance of this test case.
38      public AbstractRequestBeanTestCase(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 RequestAttributeListener();
51          request.addAttributeListener(listener);
52          request.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(AbstractRequestBeanTestCase.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          RequestAttributeListener.clear();
70          ConcreteRequestBean.clear();
71          super.tearDown();
72  
73      }
74  
75  
76      // ------------------------------------------------------ Instance Variables
77  
78  
79      ServletRequestAttributeListener listener = null;
80  
81  
82      // ------------------------------------------------------------ Test Methods
83  
84  
85  
86      // Test a prisine instance
87      public void testPristine() {
88  
89          assertEquals("", RequestAttributeListener.record());
90  
91      }
92  
93  
94      // Test processing an attribute
95      public void testProcess() {
96  
97          assertEquals("", RequestAttributeListener.record());
98          ConcreteRequestBean bean = new ConcreteRequestBean();
99          assertEquals("", ConcreteRequestBean.record());
100 
101         request.setAttribute("bean", bean);
102         assertEquals("attributeAdded(bean,ConcreteRequestBean)//",
103                      RequestAttributeListener.record());
104         assertEquals("init()//",
105                      ConcreteRequestBean.record());
106 
107         request.setAttribute("bean", bean);
108         assertEquals("attributeAdded(bean,ConcreteRequestBean)//" +
109                      "attributeReplaced(bean,ConcreteRequestBean)//",
110                      RequestAttributeListener.record());
111         assertEquals("init()//destroy()//init()//",
112                      ConcreteRequestBean.record());
113 
114         request.removeAttribute("bean");
115         assertEquals("attributeAdded(bean,ConcreteRequestBean)//" +
116                      "attributeReplaced(bean,ConcreteRequestBean)//" +
117                      "attributeRemoved(bean,ConcreteRequestBean)//",
118                      RequestAttributeListener.record());
119         assertEquals("init()//destroy()//init()//destroy()//",
120                      ConcreteRequestBean.record());
121 
122     }
123 
124 
125 }