jdk/test/sanity/client/SwingSet/src/ListDemoTest.java
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 39006 fd8c3312d043
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
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
/*
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
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.list.ListDemo;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    25
import static com.sun.swingset3.demos.list.ListDemo.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;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    28
import javax.swing.JList;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    29
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    30
import org.netbeans.jemmy.ClassReference;
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    31
import org.netbeans.jemmy.ComponentChooser;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    32
import org.netbeans.jemmy.operators.JCheckBoxOperator;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    33
import org.netbeans.jemmy.operators.JFrameOperator;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    34
import org.netbeans.jemmy.operators.JListOperator;
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    35
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    36
import static org.jemmy2ext.JemmyExt.*;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    37
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    38
import org.jtregext.GuiTestListener;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    39
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    40
import org.testng.annotations.Listeners;
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    41
import org.testng.annotations.Test;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    42
import static org.testng.AssertJUnit.*;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    43
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    44
/*
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    45
 * @test
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    46
 * @key headful
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    47
 * @summary Verifies SwingSet3 ListDemo page by checking and unchecking all
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    48
 *          the checkboxes on the page and verifying the number of items in the
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    49
 *          list.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    50
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    51
 * @library /sanity/client/lib/jemmy/src
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    52
 * @library /sanity/client/lib/Extensions/src
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    53
 * @library /sanity/client/lib/SwingSet3/src
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    54
 * @modules java.desktop
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    55
 *          java.logging
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    56
 * @build org.jemmy2ext.JemmyExt
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    57
 * @build com.sun.swingset3.demos.list.ListDemo
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    58
 * @run testng ListDemoTest
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    59
 */
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    60
@Listeners(GuiTestListener.class)
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    61
public class ListDemoTest {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    62
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    63
    private static final int CHECKBOX_COUNT = 50;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    64
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    65
    private void waitModelSize(JListOperator listOp, int size) {
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    66
        listOp.waitState(new ComponentChooser() {
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    67
            public boolean checkComponent(Component comp) {
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    68
                return getUIValue(listOp, (JList list) -> list.getModel().getSize()) == size;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    69
            }
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    70
            public String getDescription() {
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    71
                return "Model size to be equal to " + size;
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    72
            }
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    73
        });
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    74
    }
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    75
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    76
    @Test
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    77
    public void test() throws Exception {
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    78
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    79
        new ClassReference(ListDemo.class.getCanonicalName()).startApplication();
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    80
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    81
        JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    82
        JListOperator listOp = new JListOperator(frame);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    83
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    84
        // Check *NO* Prefix and Suffixes Marked
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    85
        for (int i = 0; i < CHECKBOX_COUNT; i++) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    86
            JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    87
            checkBox.changeSelection(false);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    88
        }
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    89
        waitModelSize(listOp, 0);
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
        // Check *ALL* Prefix and Suffixes Marked
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    92
        for (int i = 0; i < CHECKBOX_COUNT; i++) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    93
            JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    94
            checkBox.changeSelection(true);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    95
        }
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
    96
        waitModelSize(listOp, CHECKBOX_COUNT * CHECKBOX_COUNT / 4);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    97
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    98
        // Check *ALL* Prefix and *NO* Suffixes Marked
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    99
        for (int i = 0; i < CHECKBOX_COUNT; i++) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   100
            JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   101
            if (i < CHECKBOX_COUNT / 2) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   102
                checkBox.changeSelection(true);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   103
            } else {
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   104
                checkBox.changeSelection(false);
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
        }
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
   107
        waitModelSize(listOp, 0);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   108
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   109
        // Check *NO* Prefix and *ALL* Suffixes Marked
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   110
        for (int i = 0; i < CHECKBOX_COUNT; i++) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   111
            JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   112
            if (i < CHECKBOX_COUNT / 2) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   113
                checkBox.changeSelection(false);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   114
            } else {
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   115
                checkBox.changeSelection(true);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   116
            }
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
   117
        }
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
   118
        waitModelSize(listOp, 0);
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   119
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   120
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   121
    private JCheckBoxOperator getJCheckBoxOperator(JFrameOperator frame, int index) {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   122
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   123
        // We map first half of indexes to the Prefixes panel and the second half
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   124
        // to the Suffixes panel
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   125
        String labelText;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   126
        int subindex;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   127
        if (index < CHECKBOX_COUNT / 2) {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   128
            labelText = "Prefixes";
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   129
            subindex = index;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   130
        } else {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   131
            labelText = "Suffixes";
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   132
            subindex = index - CHECKBOX_COUNT / 2;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   133
        }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   134
39006
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
   135
        JCheckBoxOperator result = new JCheckBoxOperator(getLabeledContainerOperator(frame, labelText), subindex);
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
   136
        result.setVerification(true);
fd8c3312d043 8157339: Further stabilization for the SwingSet client sanity tests
prr
parents: 37677
diff changeset
   137
        return result;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   138
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   139
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   140
}