001: package com.opensymphony.webwork.views.jsp.ui;
002:
003: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
004: import com.opensymphony.webwork.views.jsp.ui.TreeNodeTag;
005: import com.opensymphony.webwork.views.jsp.ui.TreeTag;
006:
007: import com.opensymphony.xwork.Action;
008: import com.opensymphony.xwork.ActionSupport;
009:
010: /**
011: * Test case for Tree component.
012: */
013: public class TreeTest extends AbstractUITagTest {
014:
015: public void testStaticTree() throws Exception {
016: // Root
017: TreeTag tag = new TreeTag();
018: tag.setShowRootGrid("false");
019: tag.setShowGrid("false");
020: tag.setTemplateCssPath("/struts/tree.css");
021: tag.setTheme("ajax");
022: tag.setPageContext(pageContext);
023: tag.setId("rootId");
024: tag.setLabel("Root");
025: tag.doStartTag();
026:
027: // Child 1
028: TreeNodeTag nodeTag1 = new TreeNodeTag();
029: nodeTag1.setTheme("ajax");
030: nodeTag1.setPageContext(pageContext);
031: nodeTag1.setId("child1");
032: nodeTag1.setLabel("Child 1");
033: nodeTag1.doStartTag();
034: nodeTag1.doEndTag();
035:
036: // Child 2
037: TreeNodeTag nodeTag2 = new TreeNodeTag();
038: nodeTag2.setTheme("ajax");
039: nodeTag2.setPageContext(pageContext);
040: nodeTag2.setId("child2");
041: nodeTag2.setLabel("Child 2");
042: nodeTag2.doStartTag();
043:
044: // Grand Child 1
045: TreeNodeTag gNodeTag1 = new TreeNodeTag();
046: gNodeTag1.setTheme("ajax");
047: gNodeTag1.setPageContext(pageContext);
048: gNodeTag1.setId("gChild1");
049: gNodeTag1.setLabel("Grand Child 1");
050: gNodeTag1.doStartTag();
051: gNodeTag1.doEndTag();
052:
053: // Grand Child 2
054: TreeNodeTag gNodeTag2 = new TreeNodeTag();
055: gNodeTag2.setTheme("ajax");
056: gNodeTag2.setPageContext(pageContext);
057: gNodeTag2.setId("gChild2");
058: gNodeTag2.setLabel("Grand Child 2");
059: gNodeTag2.doStartTag();
060: gNodeTag2.doEndTag();
061:
062: // Grand Child 3
063: TreeNodeTag gNodeTag3 = new TreeNodeTag();
064: gNodeTag3.setTheme("ajax");
065: gNodeTag3.setPageContext(pageContext);
066: gNodeTag3.setId("gChild3");
067: gNodeTag3.setLabel("Grand Child 3");
068: gNodeTag3.doStartTag();
069: gNodeTag3.doEndTag();
070:
071: nodeTag2.doEndTag();
072:
073: // Child 3
074: TreeNodeTag nodeTag3 = new TreeNodeTag();
075: nodeTag3.setTheme("ajax");
076: nodeTag3.setPageContext(pageContext);
077: nodeTag3.setId("child3");
078: nodeTag3.setLabel("Child 4");
079: nodeTag3.doStartTag();
080: nodeTag3.doEndTag();
081:
082: tag.doEndTag();
083:
084: //System.out.println(writer.toString());
085: verify(TreeTest.class.getResource("tree-1.txt"));
086: }
087:
088: public void testDynamicTree() throws Exception {
089:
090: TreeTag tag = new TreeTag();
091: tag.setPageContext(pageContext);
092: tag.setTheme("ajax");
093: tag.setId("myTree");
094: tag.setRootNode("%{myTreeRoot}");
095: tag.setNodeIdProperty("id");
096: tag.setNodeTitleProperty("name");
097: tag.setChildCollectionProperty("children");
098: tag.doStartTag();
099: tag.doEndTag();
100:
101: //System.out.println(writer.toString());
102: verify(TreeTest.class.getResource("tree-2.txt"));
103: }
104:
105: public Action getAction() {
106: return new InternalActionSupport();
107: }
108:
109: public static class InternalActionSupport extends ActionSupport {
110: public Category getMyTreeRoot() {
111: return Category.getById(1);
112: }
113: }
114: }
|