test/jdk/sanity/client/SwingSet/src/TreeDemoTest.java
author herrick
Mon, 14 Oct 2019 14:36:45 -0400
branchJDK-8200758-branch
changeset 58584 910b14f4fe3a
parent 52128 1e0cdaf980f3
permissions -rw-r--r--
8232042: [macos] Installation fails if application name contains spaces Submitted-by: almatvee Reviewed-by: aherrick, asemenyuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     1
/*
51921
372cbac1a862 8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents: 47216
diff changeset
     2
 * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     4
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     8
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    13
 * accompanied this code).
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    14
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    18
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    21
 * questions.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    22
 */
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    23
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    24
import com.sun.swingset3.demos.tree.TreeDemo;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    25
import static com.sun.swingset3.demos.tree.TreeDemo.DEMO_TITLE;
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    26
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    27
import java.awt.Component;
51921
372cbac1a862 8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents: 47216
diff changeset
    28
import javax.swing.UIManager;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    29
import javax.swing.tree.TreePath;
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    30
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    31
import org.jtregext.GuiTestListener;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    32
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    33
import org.netbeans.jemmy.ClassReference;
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    34
import org.netbeans.jemmy.ComponentChooser;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    35
import org.netbeans.jemmy.operators.JFrameOperator;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    36
import org.netbeans.jemmy.operators.JTreeOperator;
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    37
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    38
import org.testng.annotations.Listeners;
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    39
import org.testng.annotations.Test;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    40
import static org.testng.AssertJUnit.*;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    41
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    42
/*
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    43
 * @test
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    44
 * @key headful
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    45
 * @summary Verifies SwingSet3 TreeDemo by expanding all collapsed nodes in the
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    46
 *          tree and then collapsing all the expanded nodes in the tree. It
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    47
 *          verifies the number of nodes expanded, number of nodes collapsed and
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    48
 *          number of rows in the tree in the begininng, after expanding and
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    49
 *          after collapsing the nodes. It also checks that the tree grows
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    50
 *          vertically (as ScrollPane allows it).
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    51
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    52
 * @library /sanity/client/lib/jemmy/src
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    53
 * @library /sanity/client/lib/Extensions/src
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    54
 * @library /sanity/client/lib/SwingSet3/src
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    55
 * @modules java.desktop
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    56
 *          java.logging
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    57
 * @build org.jemmy2ext.JemmyExt
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    58
 * @build com.sun.swingset3.demos.tree.TreeDemo
52128
1e0cdaf980f3 8211139: Increase timeout value in all tests under jdk/sanity/client/SwingSet/src
akolarkunnu
parents: 51921
diff changeset
    59
 * @run testng/timeout=600 TreeDemoTest
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    60
 */
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    61
@Listeners(GuiTestListener.class)
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    62
public class TreeDemoTest {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    63
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    64
    private static final int NODES_TO_EXPAND = 75;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    65
    private static final int NODES_TOTAL = 616;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    66
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    67
    private void waitRowCount(JTreeOperator tree, int count) {
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    68
        tree.waitState(new ComponentChooser() {
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    69
            public boolean checkComponent(Component comp) {
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    70
                return tree.getRowCount() == count;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    71
            }
51921
372cbac1a862 8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents: 47216
diff changeset
    72
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    73
            public String getDescription() {
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    74
                return "A tree to have " + count + " rows";
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    75
            }
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    76
        });
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    77
    }
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    78
51921
372cbac1a862 8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents: 47216
diff changeset
    79
    @Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
372cbac1a862 8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents: 47216
diff changeset
    80
    public void test(String lookAndFeel) throws Exception {
372cbac1a862 8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents: 47216
diff changeset
    81
        UIManager.setLookAndFeel(lookAndFeel);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    82
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    83
        new ClassReference(TreeDemo.class.getCanonicalName()).startApplication();
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    84
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    85
        JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    86
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    87
        JTreeOperator tree = new JTreeOperator(frame);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    88
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    89
        assertEquals("Initial number of rows in the tree", 4, tree.getRowCount());
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    90
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    91
        int initialTreeHeight = tree.getHeight();
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    92
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    93
        // expand all nodes
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    94
        int expandsCount = 0;
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    95
        for (int i = 0; i < tree.getRowCount(); i++) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    96
            TreePath tp = tree.getPathForRow(i);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    97
            if (tree.getChildCount(tp) > 0 && !tree.isExpanded(tp)) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    98
                tree.expandRow(i);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    99
                expandsCount++;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   100
            }
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   101
        }
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   102
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
   103
        assertEquals("Number of rows expanded", NODES_TO_EXPAND, expandsCount);
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
   104
        waitRowCount(tree, NODES_TOTAL);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   105
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   106
        int expandedTreeHeight = tree.getHeight();
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   107
        assertTrue("Expanded tree height has increased, current "
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   108
                + expandedTreeHeight + " > initial " + initialTreeHeight,
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   109
                expandedTreeHeight > initialTreeHeight);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   110
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   111
        // collapse all nodes
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   112
        int collapsesCount = 0;
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   113
        for (int i = tree.getRowCount() - 1; i >= 0; i--) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   114
            TreePath tp = tree.getPathForRow(i);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   115
            if (tree.getChildCount(tp) > 0 && tree.isExpanded(tp)) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   116
                tree.collapseRow(i);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   117
                collapsesCount++;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   118
            }
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   119
        }
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   120
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
   121
        assertEquals("Number of rows collapsed", NODES_TO_EXPAND + 1, collapsesCount);
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
   122
        waitRowCount(tree, 1);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   123
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   124
        int collapsedTreeHeight = tree.getHeight();
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   125
        assertTrue("Collpased tree height is not longer than initial, "
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   126
                + "current " + collapsedTreeHeight + " <= initial "
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   127
                + initialTreeHeight,
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   128
                collapsedTreeHeight <= initialTreeHeight);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   129
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   130
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   131
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   132
}