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