1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.views.jsp.ui;
19
20 import org.apache.struts2.views.jsp.AbstractUITagTest;
21
22 import com.opensymphony.xwork2.Action;
23 import com.opensymphony.xwork2.ActionSupport;
24
25 /***
26 * Test case for Tree component.
27 */
28 public class TreeTest extends AbstractUITagTest{
29
30 public void testStaticTree() throws Exception {
31
32 TreeTag tag = new TreeTag();
33 tag.setShowRootGrid("false");
34 tag.setShowGrid("false");
35 tag.setTemplateCssPath("/struts/tree.css");
36 tag.setTheme("ajax");
37 tag.setPageContext(pageContext);
38 tag.setId("rootId");
39 tag.setLabel("Root");
40 tag.doStartTag();
41
42
43 TreeNodeTag nodeTag1 = new TreeNodeTag();
44 nodeTag1.setTheme("ajax");
45 nodeTag1.setPageContext(pageContext);
46 nodeTag1.setId("child1");
47 nodeTag1.setLabel("Child 1");
48 nodeTag1.doStartTag();
49 nodeTag1.doEndTag();
50
51
52 TreeNodeTag nodeTag2 = new TreeNodeTag();
53 nodeTag2.setTheme("ajax");
54 nodeTag2.setPageContext(pageContext);
55 nodeTag2.setId("child2");
56 nodeTag2.setLabel("Child 2");
57 nodeTag2.doStartTag();
58
59
60 TreeNodeTag gNodeTag1 = new TreeNodeTag();
61 gNodeTag1.setTheme("ajax");
62 gNodeTag1.setPageContext(pageContext);
63 gNodeTag1.setId("gChild1");
64 gNodeTag1.setLabel("Grand Child 1");
65 gNodeTag1.doStartTag();
66 gNodeTag1.doEndTag();
67
68
69 TreeNodeTag gNodeTag2 = new TreeNodeTag();
70 gNodeTag2.setTheme("ajax");
71 gNodeTag2.setPageContext(pageContext);
72 gNodeTag2.setId("gChild2");
73 gNodeTag2.setLabel("Grand Child 2");
74 gNodeTag2.doStartTag();
75 gNodeTag2.doEndTag();
76
77
78 TreeNodeTag gNodeTag3= new TreeNodeTag();
79 gNodeTag3.setTheme("ajax");
80 gNodeTag3.setPageContext(pageContext);
81 gNodeTag3.setId("gChild3");
82 gNodeTag3.setLabel("Grand Child 3");
83 gNodeTag3.doStartTag();
84 gNodeTag3.doEndTag();
85
86 nodeTag2.doEndTag();
87
88
89
90 TreeNodeTag nodeTag3 = new TreeNodeTag();
91 nodeTag3.setTheme("ajax");
92 nodeTag3.setPageContext(pageContext);
93 nodeTag3.setId("child3");
94 nodeTag3.setLabel("Child 4");
95 nodeTag3.doStartTag();
96 nodeTag3.doEndTag();
97
98 tag.doEndTag();
99
100
101 verify(TreeTest.class.getResource("tree-1.txt"));
102 }
103
104
105
106 public void testDynamicTree() throws Exception {
107
108 TreeTag tag = new TreeTag();
109 tag.setPageContext(pageContext);
110 tag.setTheme("ajax");
111 tag.setId("myTree");
112 tag.setRootNode("%{myTreeRoot}");
113 tag.setNodeIdProperty("id");
114 tag.setNodeTitleProperty("name");
115 tag.setChildCollectionProperty("children");
116 tag.doStartTag();
117 tag.doEndTag();
118
119
120 verify(TreeTest.class.getResource("tree-2.txt"));
121 }
122
123
124 public Action getAction() {
125 return new InternalActionSupport();
126 }
127
128 public static class InternalActionSupport extends ActionSupport {
129 public Category getMyTreeRoot() {
130 return Category.getById(1);
131 }
132 }
133 }