jdk/test/sanity/client/SwingSet/src/SpinnerDemoTest.java
author mrkam
Wed, 27 Apr 2016 17:47:17 -0700
changeset 37677 9774eca96b01
parent 36744 a00905527ec2
child 39006 fd8c3312d043
permissions -rw-r--r--
8154381: SwingSet tests are not auto closed in jtreg Reviewed-by: alexsch
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) 2011, 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
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    24
import org.jtregext.GuiTestListener;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    25
import com.sun.swingset3.demos.spinner.SpinnerDemo;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    26
import static com.sun.swingset3.demos.spinner.SpinnerDemo.DEMO_TITLE;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    27
import java.text.DecimalFormat;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    28
import static org.testng.AssertJUnit.*;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    29
import org.testng.annotations.Test;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    30
import org.netbeans.jemmy.ClassReference;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    31
import org.netbeans.jemmy.operators.JFrameOperator;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    32
import org.netbeans.jemmy.operators.JSpinnerOperator;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    33
import org.netbeans.jemmy.operators.JTextFieldOperator;
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    34
import org.testng.annotations.Listeners;
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    35
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    36
/*
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    37
 * @test
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    38
 * @key headful
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    39
 * @summary Verifies SwingSet3 SpinnerDemo by adjusting each spinner value via
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    40
 *          the spinner button and checking text field value.
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
 * @library /sanity/client/lib/jemmy/src
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    43
 * @library /sanity/client/lib/Extensions/src
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    44
 * @library /sanity/client/lib/SwingSet3/src
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    45
 * @build org.jemmy2ext.JemmyExt
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    46
 * @build com.sun.swingset3.demos.spinner.SpinnerDemo
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    47
 * @run testng SpinnerDemoTest
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    48
 */
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    49
@Listeners(GuiTestListener.class)
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    50
public class SpinnerDemoTest {
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
    private static final int SPINNERS_COUNT = 9;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    53
    private static final DecimalFormat decimalFormat = new DecimalFormat();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    54
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    55
    @Test
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    56
    public void test() throws Exception {
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    57
        new ClassReference(SpinnerDemo.class.getCanonicalName()).startApplication();
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    58
37677
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    59
        JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
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
        // Check changing different spinners
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    62
        for (int i = 0; i < SPINNERS_COUNT; i++) {
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    63
            changeValues(frame, i);
9774eca96b01 8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents: 36744
diff changeset
    64
        }
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    65
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    66
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    67
    private void changeValues(JFrameOperator jfo, int spinnerIndex) throws Exception {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    68
        JSpinnerOperator spinner = new JSpinnerOperator(jfo, spinnerIndex);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    69
        JTextFieldOperator jtfo = new JTextFieldOperator(spinner);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    70
        float originalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    71
        float finalFieldValue;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    72
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    73
        // increment by one the value via spinner
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    74
        spinner.getIncreaseOperator().push();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    75
        finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    76
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    77
        // check that the value was increased
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    78
        assertTrue("Increment Spinner " + spinner
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    79
                + " (originalFieldValue, actual value: " + originalFieldValue + " "
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    80
                + "< finalFieldValue, actual value = " + finalFieldValue + ")",
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    81
                originalFieldValue < finalFieldValue);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    82
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    83
        // decrease value via spinner
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    84
        spinner.getDecreaseOperator().push();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    85
        finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    86
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    87
        // check that the value was decrimented
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    88
        assertTrue("Decrement Spinner " + spinner
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    89
                + " (originalFieldValue, actual value: " + originalFieldValue + " "
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    90
                + ">= finalFieldValue, actual value = " + finalFieldValue + ")",
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    91
                originalFieldValue >= finalFieldValue);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    92
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    93
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    94
}