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