View Javadoc

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  
20  package org.apache.myfaces.custom.tree2;
21  
22  
23  import junit.framework.Test;
24  import junit.framework.TestSuite;
25  
26  import javax.faces.event.ActionEvent;
27  import javax.faces.component.html.HtmlCommandLink;
28  
29  /**
30   * Test case for {@link UITreeData}.
31   */
32  public class UITreeDataTest extends AbstractTreeTestCase
33  {
34      /**
35       * Constructor
36       * @param name String
37       */
38      public UITreeDataTest(String name)
39      {
40          super(name);
41      }
42  
43      /**
44       * See abstract class
45       */
46      protected void setUp() throws Exception
47      {
48          super.setUp();
49      }
50  
51      /**
52       * Tests the selection of a specific node using both server side and client side
53       * toggle options.
54       *
55       * @throws Exception
56       */
57      public void testNodeSelected() throws Exception
58      {
59          tree.setClientSideToggle(false);
60          // tree.getAttributes().put(JSFAttr.CLIENT_SIDE_TOGGLE, Boolean.FALSE);
61  
62          ActionEvent event = new ActionEvent(new HtmlCommandLink());
63  
64          // set the node to be selected
65          tree.setNodeId("0:1:0");
66          tree.setNodeSelected(event);
67  
68          assertTrue("Node 0:1:0 should be selected", tree.isNodeSelected());
69  
70          tree.setClientSideToggle(true);
71          // tree.getAttributes().put(JSFAttr.CLIENT_SIDE_TOGGLE, Boolean.TRUE);
72  
73          // set the node to be selected
74          tree.setNodeId("0:1:0");
75          tree.setNodeSelected(event);
76  
77          assertTrue("Node 0:1:0 should be selected", tree.isNodeSelected());
78      }
79  
80      /**
81       * Tests programatic selection of a node.  (See MYFACES-717)
82       * @throws Exception
83       */
84      public void testProgramaticSelection() throws Exception
85      {
86          TreeModel treeModel = tree.getDataModel();
87          TreeState treeState = treeModel.getTreeState();
88          treeState.setSelected("0:3");
89  
90          treeModel.setTreeState(treeState);
91  
92          tree.setValue(treeModel);
93          tree.setNodeId("0:3");
94          assertTrue("Node 0:3 should be selected", tree.isNodeSelected());
95      }
96  
97      /**
98       * Tests the ability to expand all nodes at once.  (See TOMAHAWK-436)
99       * @throws Exception
100      */
101     public void testExpandAll() throws Exception
102     {
103         tree.expandAll();
104 
105         tree.setNodeId("0");
106         assertTrue("Node O should be expanded", tree.isNodeExpanded());
107 
108         tree.setNodeId("0:0");
109         assertTrue("Node O:0 should be expanded", tree.isNodeExpanded());
110 
111         tree.setNodeId("0:0:0");
112         assertTrue("Node O:0:0 should be expanded", tree.isNodeExpanded());
113 
114         tree.setNodeId("0:0:1");
115         assertTrue("Node O:0:1 should be expanded", tree.isNodeExpanded());
116 
117         tree.setNodeId("0:0:2");
118         assertTrue("Node O:0:2 should be expanded", tree.isNodeExpanded());
119 
120         tree.setNodeId("0:0:2:0");
121         assertTrue("Node O:0:2:0 should be expanded", tree.isNodeExpanded());
122 
123         tree.setNodeId("0:0:2:1");
124         assertTrue("Node O:0:2:1 should be expanded", tree.isNodeExpanded());
125 
126         tree.setNodeId("0:1");
127         assertTrue("Node O:1 should be expanded", tree.isNodeExpanded());
128 
129         tree.setNodeId("0:1:0");
130         assertTrue("Node O:1:0 should be expanded", tree.isNodeExpanded());
131 
132         tree.setNodeId("0:1:1");
133         assertTrue("Node O:1:1 should be expanded", tree.isNodeExpanded());
134 
135         tree.setNodeId("0:2");
136         assertTrue("Node O:2 should be expanded", tree.isNodeExpanded());
137 
138         tree.setNodeId("0:3");
139         assertTrue("Node O:3 should be expanded", tree.isNodeExpanded());
140     }
141 
142     /**
143      * Tests the ability to collapse all nodes at once.  (See TOMAHAWK-27)
144      * @throws Exception
145      */
146     public void testCollapseAll() throws Exception
147     {
148         // expand a few nodes to start off with
149         tree.expandPath(new String[] {"0", "0:0", "0:0:1"});
150         tree.expandPath(new String[] {"0", "0:1", "0:1:0"});
151 
152         tree.collapseAll();
153 
154         tree.setNodeId("0");
155         assertFalse("Node O should not be expanded", tree.isNodeExpanded());
156 
157         tree.setNodeId("0:0");
158         assertFalse("Node O:0 should not be expanded", tree.isNodeExpanded());
159 
160         tree.setNodeId("0:0:1");
161         assertFalse("Node O:0:1 should not be expanded", tree.isNodeExpanded());
162 
163         tree.setNodeId("0:1");
164         assertFalse("Node O:1 should not be expanded", tree.isNodeExpanded());
165 
166         tree.setNodeId("0:1:0");
167         assertFalse("Node O:1:0 should not be expanded", tree.isNodeExpanded());
168     }
169 
170     /**
171      * Its possible that a facet will be empty on the decode if it contained only EL text.
172      * So its wrong to throw an exception when this is the case.  (See TOMAHAWK-510)
173      *
174      * @throws Exception
175      */
176     public void testEmptyFacet() throws Exception
177     {
178         tree.processDecodes(facesContext);
179 
180     }
181 
182     public static Test suite()
183     {
184         return new TestSuite(UITreeDataTest.class);
185     }
186 }