001: /*
002: * $Id: TreeTest.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import org.apache.struts2.views.jsp.AbstractUITagTest;
024:
025: import com.opensymphony.xwork2.Action;
026: import com.opensymphony.xwork2.ActionSupport;
027:
028: /**
029: * Test case for Tree component.
030: */
031: public class TreeTest extends AbstractUITagTest {
032:
033: public void testStaticTree() throws Exception {
034: // Root
035: TreeTag tag = new TreeTag();
036: tag.setShowRootGrid("false");
037: tag.setShowGrid("false");
038: tag.setTemplateCssPath("/struts/tree.css");
039: tag.setTheme("ajax");
040: tag.setPageContext(pageContext);
041: tag.setId("rootId");
042: tag.setLabel("Root");
043: tag.doStartTag();
044:
045: // Child 1
046: TreeNodeTag nodeTag1 = new TreeNodeTag();
047: nodeTag1.setTheme("ajax");
048: nodeTag1.setPageContext(pageContext);
049: nodeTag1.setId("child1");
050: nodeTag1.setLabel("Child 1");
051: nodeTag1.doStartTag();
052: nodeTag1.doEndTag();
053:
054: // Child 2
055: TreeNodeTag nodeTag2 = new TreeNodeTag();
056: nodeTag2.setTheme("ajax");
057: nodeTag2.setPageContext(pageContext);
058: nodeTag2.setId("child2");
059: nodeTag2.setLabel("Child 2");
060: nodeTag2.doStartTag();
061:
062: // Grand Child 1
063: TreeNodeTag gNodeTag1 = new TreeNodeTag();
064: gNodeTag1.setTheme("ajax");
065: gNodeTag1.setPageContext(pageContext);
066: gNodeTag1.setId("gChild1");
067: gNodeTag1.setLabel("Grand Child 1");
068: gNodeTag1.doStartTag();
069: gNodeTag1.doEndTag();
070:
071: // Grand Child 2
072: TreeNodeTag gNodeTag2 = new TreeNodeTag();
073: gNodeTag2.setTheme("ajax");
074: gNodeTag2.setPageContext(pageContext);
075: gNodeTag2.setId("gChild2");
076: gNodeTag2.setLabel("Grand Child 2");
077: gNodeTag2.doStartTag();
078: gNodeTag2.doEndTag();
079:
080: // Grand Child 3
081: TreeNodeTag gNodeTag3 = new TreeNodeTag();
082: gNodeTag3.setTheme("ajax");
083: gNodeTag3.setPageContext(pageContext);
084: gNodeTag3.setId("gChild3");
085: gNodeTag3.setLabel("Grand Child 3");
086: gNodeTag3.doStartTag();
087: gNodeTag3.doEndTag();
088:
089: nodeTag2.doEndTag();
090:
091: // Child 3
092: TreeNodeTag nodeTag3 = new TreeNodeTag();
093: nodeTag3.setTheme("ajax");
094: nodeTag3.setPageContext(pageContext);
095: nodeTag3.setId("child3");
096: nodeTag3.setLabel("Child 4");
097: nodeTag3.doStartTag();
098: nodeTag3.doEndTag();
099:
100: tag.doEndTag();
101:
102: //System.out.println(writer.toString());
103: verify(TreeTest.class.getResource("tree-1.txt"));
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: //System.out.println(writer.toString());
120: verify(TreeTest.class.getResource("tree-2.txt"));
121: }
122:
123: public Action getAction() {
124: return new InternalActionSupport();
125: }
126:
127: public static class InternalActionSupport extends ActionSupport {
128: public Category getMyTreeRoot() {
129: return Category.getById(1);
130: }
131: }
132: }
|