View Javadoc

1   /*
2    * $Id: TreeTest.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.dojo.views.jsp.ui;
23  
24  
25  import com.opensymphony.xwork2.Action;
26  import com.opensymphony.xwork2.ActionSupport;
27  
28  /***
29   * Test case for Tree component.
30   */
31  public class TreeTest extends AbstractUITagTest{
32  
33      public void testStaticTree() throws Exception {
34          // Root
35          TreeTag tag = new TreeTag();
36          tag.setShowRootGrid("false");
37          tag.setShowGrid("false");
38          tag.setTemplateCssPath("/struts/tree.css");
39          tag.setPageContext(pageContext);
40          tag.setId("rootId");
41          tag.setLabel("Root");
42          tag.doStartTag();
43  
44              // Child 1
45              TreeNodeTag nodeTag1 = new TreeNodeTag();
46              nodeTag1.setTheme("ajax");
47              nodeTag1.setPageContext(pageContext);
48              nodeTag1.setId("child1");
49              nodeTag1.setLabel("Child 1");
50              nodeTag1.doStartTag();
51              nodeTag1.doEndTag();
52  
53              // Child 2
54              TreeNodeTag nodeTag2 = new TreeNodeTag();
55              nodeTag2.setTheme("ajax");
56              nodeTag2.setPageContext(pageContext);
57              nodeTag2.setId("child2");
58              nodeTag2.setLabel("Child 2");
59              nodeTag2.doStartTag();
60  
61                  // Grand Child 1
62                  TreeNodeTag gNodeTag1 = new TreeNodeTag();
63                  gNodeTag1.setTheme("ajax");
64                  gNodeTag1.setPageContext(pageContext);
65                  gNodeTag1.setId("gChild1");
66                  gNodeTag1.setLabel("Grand Child 1");
67                  gNodeTag1.doStartTag();
68                  gNodeTag1.doEndTag();
69  
70                  // Grand Child 2
71                  TreeNodeTag gNodeTag2 = new TreeNodeTag();
72                  gNodeTag2.setTheme("ajax");
73                  gNodeTag2.setPageContext(pageContext);
74                  gNodeTag2.setId("gChild2");
75                  gNodeTag2.setLabel("Grand Child 2");
76                  gNodeTag2.doStartTag();
77                  gNodeTag2.doEndTag();
78  
79                  // Grand Child 3
80                  TreeNodeTag gNodeTag3= new TreeNodeTag();
81                  gNodeTag3.setTheme("ajax");
82                  gNodeTag3.setPageContext(pageContext);
83                  gNodeTag3.setId("gChild3");
84                  gNodeTag3.setLabel("Grand Child 3");
85                  gNodeTag3.doStartTag();
86                  gNodeTag3.doEndTag();
87  
88              nodeTag2.doEndTag();
89  
90  
91              // Child 3
92              TreeNodeTag nodeTag3 = new TreeNodeTag();
93              nodeTag3.setTheme("ajax");
94              nodeTag3.setPageContext(pageContext);
95              nodeTag3.setId("child3");
96              nodeTag3.setLabel("Child 4");
97              nodeTag3.doStartTag();
98              nodeTag3.doEndTag();
99  
100         tag.doEndTag();
101 
102         //System.out.println(writer.toString());
103         verify(TreeTest.class.getResource("tree-1.txt"));
104     }
105 
106 
107 
108     public void testDynamicTree() throws Exception {
109 
110         TreeTag tag = new TreeTag();
111         tag.setPageContext(pageContext);
112         tag.setTheme("ajax");
113         tag.setId("myTree");
114         tag.setRootNode("%{myTreeRoot}");
115         tag.setNodeIdProperty("id");
116         tag.setNodeTitleProperty("name");
117         tag.setChildCollectionProperty("children");
118         tag.doStartTag();
119         tag.doEndTag();
120 
121         //System.out.println(writer.toString());
122         verify(TreeTest.class.getResource("tree-2.txt"));
123     }
124 
125 
126     public Action getAction() {
127         return new InternalActionSupport();
128     }
129 
130     public static class InternalActionSupport extends ActionSupport {
131         public Category getMyTreeRoot() {
132             return Category.getById(1);
133         }
134     }
135 }