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.tobago.model;
21  
22  import org.apache.myfaces.tobago.component.UITreeData;
23  import org.junit.Assert;
24  import org.junit.Test;
25  
26  import javax.swing.tree.DefaultMutableTreeNode;
27  
28  /**
29   * @deprecated since 2.0.0
30   */
31  @Deprecated
32  public class MixedTreeModelUnitTest {
33  
34    @Test
35    public void testLifecycleSmall() {
36  
37      MixedTreeModel model = new MixedTreeModel();
38  
39      model.beginBuildNode();
40      model.endBuildNode();
41  
42      model.onEncodeBegin();
43      Assert.assertEquals(new TreePath(0), model.getPath());
44    }
45  
46    @Test
47    public void testLifecycleStatic() {
48  
49      MixedTreeModel model = new MixedTreeModel();
50  
51      model.beginBuildNode();
52      model.beginBuildNode();
53      model.endBuildNode();
54      model.beginBuildNode();
55      model.endBuildNode();
56      model.endBuildNode();
57  
58      model.onEncodeBegin();
59      model.onEncodeBegin();
60      model.onEncodeBegin();
61    }
62  
63    @Test
64    public void testLifecycleFromModel() {
65  
66      MixedTreeModel model = new MixedTreeModel();
67      DefaultMutableTreeNode tree = new DefaultMutableTreeNode("D_0");
68      tree.add(new DefaultMutableTreeNode("D_0_0"));
69      tree.add(new DefaultMutableTreeNode("D_0_1"));
70  
71      UITreeData data = new UITreeData();
72      data.setValue(tree);
73  
74      model.beginBuildNode();
75      model.beginBuildNode();
76      model.endBuildNode();
77      model.beginBuildNode();
78      model.endBuildNode();
79      model.endBuildNode();
80  
81      model.onEncodeBegin();
82      Assert.assertEquals(new TreePath(0), model.getPath());
83      model.onEncodeBegin();
84      Assert.assertEquals(new TreePath(0, 0), model.getPath());
85      model.onEncodeBegin();
86      Assert.assertEquals(new TreePath(0, 1), model.getPath());
87    }
88  
89    /**
90     * * --o Root (0)
91     * *   |
92     * *   +--o Individual Node (0,0)
93     * *   |
94     * *   +--o Data Root Node (0,1)
95     * *      |
96     * *      +--o Data Sub Node 1 (0,1,0)
97     * *      |
98     * *      +--o Data Sub Node 2 (0,1,1)
99     * *         |
100    * *         +--o Data Sub Sub Node 3 (0,1,1,0)
101    */
102   @Test
103   public void testLifecycleMixed() {
104 
105     MixedTreeModel model = new MixedTreeModel();
106 
107     model.beginBuildNode();
108     model.beginBuildNode();
109     model.endBuildNode();
110     model.beginBuildNode();
111     model.beginBuildNode();
112     model.endBuildNode();
113     model.beginBuildNode();
114     model.beginBuildNode();
115     model.endBuildNode();
116     model.endBuildNode();
117     model.endBuildNode();
118     model.beginBuildNode();
119     model.endBuildNode();
120     model.endBuildNode();
121 
122     model.onEncodeBegin(); // root
123     Assert.assertEquals(new TreePath(0), model.getPath());
124     model.onEncodeBegin(); // individual
125     Assert.assertEquals(new TreePath(0, 0), model.getPath());
126     model.onEncodeBegin(); // data root node
127     Assert.assertEquals(new TreePath(0, 1), model.getPath());
128     model.onEncodeBegin(); // data sub node 1
129     Assert.assertEquals(new TreePath(0, 1, 0), model.getPath());
130     model.onEncodeBegin(); // data sub node 2
131     Assert.assertEquals(new TreePath(0, 1, 1), model.getPath());
132     model.onEncodeBegin(); // data sub node 3
133     Assert.assertEquals(new TreePath(0, 1, 1, 0), model.getPath());
134     model.onEncodeBegin();
135     Assert.assertEquals(new TreePath(0, 2), model.getPath());
136   }
137 
138 }