1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.trinidad.component;
20
21 import javax.faces.context.FacesContext;
22
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25 import junit.textui.TestRunner;
26
27 import org.apache.myfaces.trinidad.component.UIComponentTestCase;
28 import org.apache.myfaces.trinidad.component.UIXTableTest.DoNotCallBinding;
29
30 /**
31 * Unit tests for UIXTree
32 *
33 */
34 public class UIXTreeTest extends UIComponentTestCase
35 {
36 /**
37 * @param testName the unit test name
38 */
39 public UIXTreeTest(
40 String testName)
41 {
42 super(testName);
43 }
44
45 @Override
46 protected void setUp() throws Exception
47 {
48 super.setUp();
49 }
50
51 @Override
52 protected void tearDown() throws Exception
53 {
54 super.tearDown();
55 }
56
57 public static Test suite()
58 {
59 return new TestSuite(UIXTreeTest.class);
60 }
61
62
63 /**
64 * make sure that the model is not executed at invalid or unnecessary times.
65 * valueBindings cannot be called during restoreState.
66 * Also table model must not be executed if rendered="false".
67 * However, saveState is called even if rendered="false" on a component.
68 * Therefore, saveState should not call getValue() on the table.
69 */
70 public void testSaveRestoreStateGetValue()
71 {
72 // make sure that getValue() is not called during restoreState:
73 DoNotCallBinding doNotCall = new DoNotCallBinding();
74 doNotCall.doNotCall = true;
75 final Object state;
76 {
77 UIXTree tree = _createTree();
78 tree.setValueBinding("value", doNotCall);
79 state = tree.processSaveState(facesContext);
80 }
81
82 UIXTree tree = _createTree();
83 // this value binding should be restored during processRestoreState;
84 // however, set it anyway just to catch any getValue() calls prior to
85 // that.
86 tree.setValueBinding("value", doNotCall);
87 tree.processRestoreState(facesContext, state);
88
89 assertTrue(tree.getValueBinding("value") instanceof DoNotCallBinding);
90
91 }
92
93 @Override
94 public void setCurrentContext(FacesContext fc)
95 {
96 // prevent removal of facesContext before we are done testing:
97 if (fc != null)
98 super.setCurrentContext(fc);
99 }
100
101
102 public static void main(String[] args)
103 {
104 TestRunner.run(UIXTreeTest.class);
105 }
106
107 @Override
108 protected boolean isRendererUsed()
109 {
110 // we use our own MockRenderer; not the one created by our super class:
111 return false;
112 }
113
114 private UIXTree _createTree()
115 {
116 UIXTree tree = new UIXTree();
117 return tree;
118 }
119
120 }