View Javadoc

    1   /*
    2    * $Id: TreeTest.java 471756 2006-11-06 15:01:43Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    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          // Root
    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              // Child 1
    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              // Child 2
    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                  // Grand Child 1
    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                  // Grand Child 2
    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                  // Grand Child 3
    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              // Child 3
    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         //System.out.println(writer.toString());
    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         //System.out.println(writer.toString());
    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 }