ScrollPaneDemoTest.java revision 14305:566a5f5a9a5a
1/*
2 * Copyright (c) 2010, 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
24import org.jtregext.GuiTestListener;
25import com.sun.swingset3.demos.scrollpane.ScrollPaneDemo;
26import static com.sun.swingset3.demos.scrollpane.ScrollPaneDemo.DEMO_TITLE;
27import static org.testng.AssertJUnit.*;
28import org.testng.annotations.Test;
29import org.netbeans.jemmy.ClassReference;
30import org.netbeans.jemmy.operators.JFrameOperator;
31import org.netbeans.jemmy.operators.JScrollPaneOperator;
32import org.testng.annotations.Listeners;
33
34/*
35 * @test
36 * @key headful
37 * @summary Verifies SwingSet3 ScrollPaneDemo by scrolling to bottom, to top,
38 *          to left and to right and checking scroll bar values.
39 *
40 * @library /sanity/client/lib/jemmy/src
41 * @library /sanity/client/lib/Extensions/src
42 * @library /sanity/client/lib/SwingSet3/src
43 * @build org.jemmy2ext.JemmyExt
44 * @build com.sun.swingset3.demos.scrollpane.ScrollPaneDemo
45 * @run testng ScrollPaneDemoTest
46 */
47@Listeners(GuiTestListener.class)
48public class ScrollPaneDemoTest {
49
50    @Test
51    public void test() throws Exception {
52
53        new ClassReference(ScrollPaneDemo.class.getName()).startApplication();
54
55        JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
56        JScrollPaneOperator jspo = new JScrollPaneOperator(frame);
57
58        // Set initial scrollbar positions
59        int initialVerticalValue = jspo.getVerticalScrollBar().getValue();
60        int initialHorizontalValue = jspo.getHorizontalScrollBar().getValue();
61
62        System.out.println("Initial Vertical Value = " + jspo.getVerticalScrollBar().getValue());
63        System.out.println("Initial HoriZontal Value = " + jspo.getHorizontalScrollBar().getValue());
64
65        // Check scroll to Bottom
66        {
67            jspo.scrollToBottom();
68            int currentValue = jspo.getVerticalScrollBar().getValue();
69            System.out.println("Final Value = " + currentValue);
70            assertTrue("Scroll to Bottom of Pane "
71                    + "(initialVerticalValue, actual value: " + initialVerticalValue + " "
72                    + "< currentValue, actual value = " + currentValue + ")",
73                    initialVerticalValue < currentValue);
74        }
75
76        // Check scroll to Top
77        {
78            jspo.scrollToTop();
79            int currentValue = jspo.getVerticalScrollBar().getValue();
80            System.out.println("Top Scroll Final Value = " + currentValue);
81            assertTrue("Scroll to Top of Pane "
82                    + "(initialVerticalValue, actual value: " + initialVerticalValue + " "
83                    + "> currentValue, actual value = " + currentValue + ")",
84                    initialVerticalValue > currentValue);
85        }
86
87        // Check scroll to Left
88        {
89            jspo.scrollToLeft();
90            int currentValue = jspo.getHorizontalScrollBar().getValue();
91            System.out.println("Scroll to Left Final Value = " + currentValue);
92            assertTrue("Scroll to Left of Pane "
93                    + "(initialHorizontalValue, actual value: " + initialHorizontalValue + " "
94                    + "> currentValue, actual value = " + currentValue + ")",
95                    initialHorizontalValue > currentValue);
96        }
97
98        // Check scroll to Right
99        {
100            jspo.scrollToRight();
101            int currentValue = jspo.getHorizontalScrollBar().getValue();
102            System.out.println("Scroll to Right Final Value = " + currentValue);
103            assertTrue("Scroll to Right of Pane "
104                    + "(initialHorizontalValue, actual value: " + initialHorizontalValue + " "
105                    + "< currentValue, actual value = " + currentValue + ")",
106                    initialHorizontalValue < currentValue);
107        }
108    }
109
110}
111