1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
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
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
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
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
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
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
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
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 }