Alexander Kouznetsov | 0ab1a9c | 2016-03-30 19:05:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 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 | |
Alexander Kouznetsov | 2ef07f5 | 2016-04-27 17:47:17 -0700 | [diff] [blame] | 24 | import org.jtregext.GuiTestListener; |
Alexander Kouznetsov | 0ab1a9c | 2016-03-30 19:05:58 -0700 | [diff] [blame] | 25 | import com.sun.swingset3.demos.spinner.SpinnerDemo; |
| 26 | import static com.sun.swingset3.demos.spinner.SpinnerDemo.DEMO_TITLE; |
| 27 | import java.text.DecimalFormat; |
| 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.JSpinnerOperator; |
| 33 | import org.netbeans.jemmy.operators.JTextFieldOperator; |
Alexander Kouznetsov | 2ef07f5 | 2016-04-27 17:47:17 -0700 | [diff] [blame] | 34 | import org.testng.annotations.Listeners; |
Alexander Kouznetsov | 0ab1a9c | 2016-03-30 19:05:58 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * @test |
| 38 | * @key headful |
| 39 | * @summary Verifies SwingSet3 SpinnerDemo by adjusting each spinner value via |
| 40 | * the spinner button and checking text field value. |
| 41 | * |
| 42 | * @library /sanity/client/lib/jemmy/src |
Alexander Kouznetsov | 2ef07f5 | 2016-04-27 17:47:17 -0700 | [diff] [blame] | 43 | * @library /sanity/client/lib/Extensions/src |
Alexander Kouznetsov | 0ab1a9c | 2016-03-30 19:05:58 -0700 | [diff] [blame] | 44 | * @library /sanity/client/lib/SwingSet3/src |
| 45 | * @build org.jemmy2ext.JemmyExt |
| 46 | * @build com.sun.swingset3.demos.spinner.SpinnerDemo |
| 47 | * @run testng SpinnerDemoTest |
| 48 | */ |
Alexander Kouznetsov | 2ef07f5 | 2016-04-27 17:47:17 -0700 | [diff] [blame] | 49 | @Listeners(GuiTestListener.class) |
Alexander Kouznetsov | 0ab1a9c | 2016-03-30 19:05:58 -0700 | [diff] [blame] | 50 | public class SpinnerDemoTest { |
| 51 | |
| 52 | private static final int SPINNERS_COUNT = 9; |
| 53 | private static final DecimalFormat decimalFormat = new DecimalFormat(); |
| 54 | |
| 55 | @Test |
| 56 | public void test() throws Exception { |
Alexander Kouznetsov | 2ef07f5 | 2016-04-27 17:47:17 -0700 | [diff] [blame] | 57 | new ClassReference(SpinnerDemo.class.getCanonicalName()).startApplication(); |
Alexander Kouznetsov | 0ab1a9c | 2016-03-30 19:05:58 -0700 | [diff] [blame] | 58 | |
Alexander Kouznetsov | 2ef07f5 | 2016-04-27 17:47:17 -0700 | [diff] [blame] | 59 | JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
Alexander Kouznetsov | 0ab1a9c | 2016-03-30 19:05:58 -0700 | [diff] [blame] | 60 | |
Alexander Kouznetsov | 2ef07f5 | 2016-04-27 17:47:17 -0700 | [diff] [blame] | 61 | // Check changing different spinners |
| 62 | for (int i = 0; i < SPINNERS_COUNT; i++) { |
| 63 | changeValues(frame, i); |
| 64 | } |
Alexander Kouznetsov | 0ab1a9c | 2016-03-30 19:05:58 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | private void changeValues(JFrameOperator jfo, int spinnerIndex) throws Exception { |
| 68 | JSpinnerOperator spinner = new JSpinnerOperator(jfo, spinnerIndex); |
| 69 | JTextFieldOperator jtfo = new JTextFieldOperator(spinner); |
| 70 | float originalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue(); |
| 71 | float finalFieldValue; |
| 72 | |
| 73 | // increment by one the value via spinner |
| 74 | spinner.getIncreaseOperator().push(); |
| 75 | finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue(); |
| 76 | |
| 77 | // check that the value was increased |
| 78 | assertTrue("Increment Spinner " + spinner |
| 79 | + " (originalFieldValue, actual value: " + originalFieldValue + " " |
| 80 | + "< finalFieldValue, actual value = " + finalFieldValue + ")", |
| 81 | originalFieldValue < finalFieldValue); |
| 82 | |
| 83 | // decrease value via spinner |
| 84 | spinner.getDecreaseOperator().push(); |
| 85 | finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue(); |
| 86 | |
| 87 | // check that the value was decrimented |
| 88 | assertTrue("Decrement Spinner " + spinner |
| 89 | + " (originalFieldValue, actual value: " + originalFieldValue + " " |
| 90 | + ">= finalFieldValue, actual value = " + finalFieldValue + ")", |
| 91 | originalFieldValue >= finalFieldValue); |
| 92 | } |
| 93 | |
| 94 | } |