2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
35
36
37
38 public AbstractApplicationBeanTestCase(String name) {
39 super(name);
40 }
41
42
43
44
45
46
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
58 public static Test suite() {
59
60 return (new TestSuite(AbstractApplicationBeanTestCase.class));
61
62 }
63
64
65
66 protected void tearDown() throws Exception {
67
68 listener = null;
69 ApplicationAttributeListener.clear();
70 ConcreteApplicationBean.clear();
71 super.tearDown();
72
73 }
74
75
76
77
78
79 ServletContextAttributeListener listener = null;
80
81
82
83
84
85
86
87 public void testPristine() {
88
89 assertEquals("", ApplicationAttributeListener.record());
90
91 }
92
93
94
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 }