< prev index next >

test/sanity/client/SwingSet/src/TreeDemoTest.java

Print this page




   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import org.jtregext.GuiTestListener;
  25 import com.sun.swingset3.demos.tree.TreeDemo;
  26 import static com.sun.swingset3.demos.tree.TreeDemo.DEMO_TITLE;


  27 import javax.swing.tree.TreePath;
  28 import static org.testng.AssertJUnit.*;
  29 import org.testng.annotations.Test;

  30 import org.netbeans.jemmy.ClassReference;

  31 import org.netbeans.jemmy.operators.JFrameOperator;
  32 import org.netbeans.jemmy.operators.JTreeOperator;

  33 import org.testng.annotations.Listeners;


  34 
  35 /*
  36  * @test
  37  * @key headful
  38  * @summary Verifies SwingSet3 TreeDemo by expanding all collapsed nodes in the
  39  *          tree and then collapsing all the expanded nodes in the tree. It
  40  *          verifies the number of nodes expanded, number of nodes collapsed and
  41  *          number of rows in the tree in the begininng, after expanding and
  42  *          after collapsing the nodes. It also checks that the tree grows
  43  *          vertically (as ScrollPane allows it).
  44  *
  45  * @library /sanity/client/lib/jemmy/src
  46  * @library /sanity/client/lib/Extensions/src
  47  * @library /sanity/client/lib/SwingSet3/src

  48  * @build org.jemmy2ext.JemmyExt
  49  * @build com.sun.swingset3.demos.tree.TreeDemo
  50  * @run testng TreeDemoTest
  51  */
  52 @Listeners(GuiTestListener.class)
  53 public class TreeDemoTest {
  54 














  55     @Test
  56     public void test() throws Exception {
  57 
  58         new ClassReference(TreeDemo.class.getCanonicalName()).startApplication();
  59 
  60         JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
  61 
  62         JTreeOperator tree = new JTreeOperator(frame);
  63 
  64         assertEquals("Initial number of rows in the tree", 4, tree.getRowCount());
  65 
  66         int initialTreeHeight = tree.getHeight();
  67 
  68         // expand all nodes
  69         int expandsCount = 0;
  70         for (int i = 0; i < tree.getRowCount(); i++) {
  71             TreePath tp = tree.getPathForRow(i);
  72             if (tree.getChildCount(tp) > 0 && !tree.isExpanded(tp)) {
  73                 tree.expandRow(i);
  74                 expandsCount++;
  75             }
  76         }
  77 
  78         assertEquals("Number of rows expanded", 75, expandsCount);
  79         assertEquals("Number of rows in the tree after expanding all of them",
  80                 616, tree.getRowCount());
  81 
  82         int expandedTreeHeight = tree.getHeight();
  83         assertTrue("Expanded tree height has increased, current "
  84                 + expandedTreeHeight + " > initial " + initialTreeHeight,
  85                 expandedTreeHeight > initialTreeHeight);
  86 
  87         // collapse all nodes
  88         int collapsesCount = 0;
  89         for (int i = tree.getRowCount() - 1; i >= 0; i--) {
  90             TreePath tp = tree.getPathForRow(i);
  91             if (tree.getChildCount(tp) > 0 && tree.isExpanded(tp)) {
  92                 tree.collapseRow(i);
  93                 collapsesCount++;
  94             }
  95         }
  96 
  97         assertEquals("Number of rows collapsed", 76, collapsesCount);
  98         assertEquals("Number of rows in the tree after collapsing all of them",
  99                 1, tree.getRowCount());
 100 
 101         int collapsedTreeHeight = tree.getHeight();
 102         assertTrue("Collpased tree height is not longer than initial, "
 103                 + "current " + collapsedTreeHeight + " <= initial "
 104                 + initialTreeHeight,
 105                 collapsedTreeHeight <= initialTreeHeight);
 106 
 107     }
 108 
 109 }


   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 

  24 import com.sun.swingset3.demos.tree.TreeDemo;
  25 import static com.sun.swingset3.demos.tree.TreeDemo.DEMO_TITLE;
  26 
  27 import java.awt.Component;
  28 import javax.swing.tree.TreePath;
  29 
  30 import org.jtregext.GuiTestListener;
  31 
  32 import org.netbeans.jemmy.ClassReference;
  33 import org.netbeans.jemmy.ComponentChooser;
  34 import org.netbeans.jemmy.operators.JFrameOperator;
  35 import org.netbeans.jemmy.operators.JTreeOperator;
  36 
  37 import org.testng.annotations.Listeners;
  38 import org.testng.annotations.Test;
  39 import static org.testng.AssertJUnit.*;
  40 
  41 /*
  42  * @test
  43  * @key headful
  44  * @summary Verifies SwingSet3 TreeDemo by expanding all collapsed nodes in the
  45  *          tree and then collapsing all the expanded nodes in the tree. It
  46  *          verifies the number of nodes expanded, number of nodes collapsed and
  47  *          number of rows in the tree in the begininng, after expanding and
  48  *          after collapsing the nodes. It also checks that the tree grows
  49  *          vertically (as ScrollPane allows it).
  50  *
  51  * @library /sanity/client/lib/jemmy/src
  52  * @library /sanity/client/lib/Extensions/src
  53  * @library /sanity/client/lib/SwingSet3/src
  54  * @modules java.desktop
  55  * @build org.jemmy2ext.JemmyExt
  56  * @build com.sun.swingset3.demos.tree.TreeDemo
  57  * @run testng TreeDemoTest
  58  */
  59 @Listeners(GuiTestListener.class)
  60 public class TreeDemoTest {
  61 
  62     private static final int NODES_TO_EXPAND = 75;
  63     private static final int NODES_TOTAL = 616;
  64 
  65     private void waitRowCount(JTreeOperator tree, int count) {
  66         tree.waitState(new ComponentChooser() {
  67             public boolean checkComponent(Component comp) {
  68                 return tree.getRowCount() == count;
  69             }
  70             public String getDescription() {
  71                 return "All nodes to be expanded in the tree";
  72             }
  73         });
  74     }
  75 
  76     @Test
  77     public void test() throws Exception {
  78 
  79         new ClassReference(TreeDemo.class.getCanonicalName()).startApplication();
  80 
  81         JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
  82 
  83         JTreeOperator tree = new JTreeOperator(frame);
  84 
  85         assertEquals("Initial number of rows in the tree", 4, tree.getRowCount());
  86 
  87         int initialTreeHeight = tree.getHeight();
  88 
  89         // expand all nodes
  90         int expandsCount = 0;
  91         for (int i = 0; i < tree.getRowCount(); i++) {
  92             TreePath tp = tree.getPathForRow(i);
  93             if (tree.getChildCount(tp) > 0 && !tree.isExpanded(tp)) {
  94                 tree.expandRow(i);
  95                 expandsCount++;
  96             }
  97         }
  98 
  99         assertEquals("Number of rows expanded", NODES_TO_EXPAND, expandsCount);
 100         waitRowCount(tree, NODES_TOTAL);

 101 
 102         int expandedTreeHeight = tree.getHeight();
 103         assertTrue("Expanded tree height has increased, current "
 104                 + expandedTreeHeight + " > initial " + initialTreeHeight,
 105                 expandedTreeHeight > initialTreeHeight);
 106 
 107         // collapse all nodes
 108         int collapsesCount = 0;
 109         for (int i = tree.getRowCount() - 1; i >= 0; i--) {
 110             TreePath tp = tree.getPathForRow(i);
 111             if (tree.getChildCount(tp) > 0 && tree.isExpanded(tp)) {
 112                 tree.collapseRow(i);
 113                 collapsesCount++;
 114             }
 115         }
 116 
 117         assertEquals("Number of rows collapsed", NODES_TO_EXPAND + 1, collapsesCount);
 118         waitRowCount(tree, 1);

 119 
 120         int collapsedTreeHeight = tree.getHeight();
 121         assertTrue("Collpased tree height is not longer than initial, "
 122                 + "current " + collapsedTreeHeight + " <= initial "
 123                 + initialTreeHeight,
 124                 collapsedTreeHeight <= initialTreeHeight);
 125 
 126     }
 127 
 128 }
< prev index next >