1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidad.component;
20
21 import javax.faces.component.UIComponent;
22 import javax.faces.component.UIViewRoot;
23 import javax.faces.context.FacesContext;
24
25 import junit.framework.Test;
26 import junit.framework.TestSuite;
27 import junit.textui.TestRunner;
28
29 import org.apache.myfaces.trinidad.component.UIComponentTestCase;
30 import org.jmock.Mock;
31
32
33
34
35
36
37 public class UIXSwitcherTest extends UIComponentTestCase
38 {
39
40
41
42
43
44 public UIXSwitcherTest(
45 String testName)
46 {
47 super(testName);
48 }
49
50 @Override
51 protected void setUp() throws Exception
52 {
53 super.setUp();
54 }
55
56 @Override
57 protected void tearDown() throws Exception
58 {
59 super.tearDown();
60 }
61
62 public static Test suite()
63 {
64 return new TestSuite(UIXSwitcherTest.class);
65 }
66
67
68
69
70 public void testInitialAttributeValues()
71 {
72 UIXSwitcher switcher = new UIXSwitcher();
73
74 assertNull(switcher.getFacetName());
75 assertNull(switcher.getDefaultFacet());
76 }
77
78
79
80
81
82
83 public void testAttributeTransparency()
84 {
85 UIXSwitcher component = new UIXSwitcher();
86
87 doTestAttributeTransparency(component, "defaultFacet",
88 "foo", "notFoo");
89 doTestAttributeTransparency(component, "facetName",
90 "bar", "notBar");
91 }
92
93
94
95
96 public void testApplyRequestValues()
97 {
98 UIXSwitcher switcher = new UIXSwitcher();
99 switcher.setFacetName("foo");
100 doTestApplyRequestValues(switcher);
101
102 switcher = new UIXSwitcher();
103 switcher.setFacetName("foo");
104 switcher.setRendered(false);
105 doTestApplyRequestValues(switcher);
106 }
107
108 @SuppressWarnings("unchecked")
109 @Override
110 protected void doTestApplyRequestValues(
111 FacesContext context,
112 UIViewRoot root,
113 UIComponent component)
114 {
115
116 Mock mockUIComponent = createMockUIComponent();
117 UIComponent fooChild = (UIComponent) mockUIComponent.proxy();
118
119
120
121
122 if (component.isRendered()){
123 mockUIComponent.stubs().method("processDecodes").with(eq(facesContext));
124 }
125
126
127 Mock mockBarChild = createMockUIComponent();
128 UIComponent barChild = (UIComponent) mockBarChild.proxy();
129
130 Mock mockOrdinaryChild = createMockUIComponent();
131 UIComponent ordinaryChild = (UIComponent) mockOrdinaryChild.proxy();
132
133
134
135 root.getChildren().add(component);
136 component.getFacets().put("foo", fooChild);
137 component.getFacets().put("bar", barChild);
138 component.getChildren().add(ordinaryChild);
139 root.processDecodes(context);
140
141 mockUIComponent.verify();
142 mockBarChild.verify();
143 mockOrdinaryChild.verify();
144 }
145
146
147
148
149
150 public void testProcessValidations()
151 {
152 UIXSwitcher switcher = new UIXSwitcher();
153 switcher.setFacetName("foo");
154 doTestProcessValidations(switcher);
155 }
156
157 @SuppressWarnings("unchecked")
158 @Override
159 protected void doTestProcessValidations(
160 FacesContext context,
161 UIViewRoot root,
162 UIComponent component)
163 {
164
165 Mock mockUIComponent = createMockUIComponent();
166 UIComponent fooChild = (UIComponent) mockUIComponent.proxy();
167
168
169
170
171 mockUIComponent.expects(once()).method("processValidators");
172
173
174 Mock mockBarChild = createMockUIComponent();
175 UIComponent barChild = (UIComponent) mockBarChild.proxy();
176
177 Mock mockOrdinaryChild = createMockUIComponent();
178 UIComponent ordinaryChild = (UIComponent) mockOrdinaryChild.proxy();
179
180
181
182 root.getChildren().add(component);
183 component.getFacets().put("foo", fooChild);
184 component.getFacets().put("bar", barChild);
185 component.getChildren().add(ordinaryChild);
186 root.processValidators(context);
187
188 mockUIComponent.verify();
189 mockBarChild.verify();
190 mockOrdinaryChild.verify();
191 }
192
193
194
195
196
197
198 public void testUpdateModelValues()
199 {
200 UIXSwitcher switcher = new UIXSwitcher();
201 switcher.setFacetName("foo");
202 doTestUpdateModelValues(switcher);
203 }
204
205
206 @SuppressWarnings("unchecked")
207 @Override
208 protected void doTestUpdateModelValues(
209 FacesContext context,
210 UIViewRoot root,
211 UIComponent component)
212 {
213 Mock mockUIComponent = createMockUIComponent();
214 UIComponent fooChild = (UIComponent) mockUIComponent.proxy();
215
216
217
218 mockUIComponent.expects(once()).method("processUpdates");
219
220
221 Mock mockBarChild = createMockUIComponent();
222 UIComponent barChild = (UIComponent) mockBarChild.proxy();
223
224 Mock mockOrdinaryChild = createMockUIComponent();
225 UIComponent ordinaryChild = (UIComponent) mockOrdinaryChild.proxy();
226
227
228
229 root.getChildren().add(component);
230 component.getFacets().put("foo", fooChild);
231 component.getFacets().put("bar", barChild);
232 component.getChildren().add(ordinaryChild);
233 root.processUpdates(context);
234
235 mockUIComponent.verify();
236 mockBarChild.verify();
237 mockOrdinaryChild.verify();
238 }
239
240 public static void main(String[] args)
241 {
242 TestRunner.run(UIXSwitcherTest.class);
243 }
244
245 @Override
246 protected boolean isRendererUsed()
247 {
248 return false;
249 }
250 }