TabbedPaneDemoTest.java revision 14305:566a5f5a9a5a
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 24import org.jtregext.GuiTestListener; 25import com.sun.swingset3.demos.tabbedpane.TabbedPaneDemo; 26import static com.sun.swingset3.demos.tabbedpane.TabbedPaneDemo.*; 27import static org.jemmy2ext.JemmyExt.getLabeledContainerOperator; 28import static org.testng.AssertJUnit.*; 29import org.testng.annotations.Test; 30import org.netbeans.jemmy.ClassReference; 31import org.netbeans.jemmy.operators.ContainerOperator; 32import org.netbeans.jemmy.operators.JFrameOperator; 33import org.netbeans.jemmy.operators.JRadioButtonOperator; 34import org.netbeans.jemmy.operators.JTabbedPaneOperator; 35import org.testng.annotations.Listeners; 36 37/* 38 * @test 39 * @key headful 40 * @summary Verifies SwingSet3 TabbedPaneDemo by iterating through tab placement 41 * positions, opening each tab and verifying the the tab gets selected. 42 * 43 * @library /sanity/client/lib/jemmy/src 44 * @library /sanity/client/lib/Extensions/src 45 * @library /sanity/client/lib/SwingSet3/src 46 * @build org.jemmy2ext.JemmyExt 47 * @build com.sun.swingset3.demos.tabbedpane.TabbedPaneDemo 48 * @run testng TabbedPaneDemoTest 49 */ 50@Listeners(GuiTestListener.class) 51public class TabbedPaneDemoTest { 52 53 @Test 54 public void test() throws Exception { 55 new ClassReference(TabbedPaneDemo.class.getCanonicalName()).startApplication(); 56 57 JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); 58 59 for (String tp : new String[]{TOP, LEFT, BOTTOM, RIGHT}) { 60 testTabs(mainFrame, tp); 61 } 62 } 63 64 public void testTabs(JFrameOperator mainFrame, String tabPlacement) throws Exception { 65 ContainerOperator<?> rbCont = getLabeledContainerOperator(mainFrame, TAB_PLACEMENT); 66 new JRadioButtonOperator(rbCont, tabPlacement).doClick(); 67 68 final String[] tabTitles = new String[]{CAMILLE, MIRANDA, EWAN, BOUNCE}; 69 for (int i = 0; i < tabTitles.length; i++) { 70 String pageTitle = tabTitles[i]; 71 JTabbedPaneOperator tabOperator = new JTabbedPaneOperator(mainFrame); 72 tabOperator.selectPage(pageTitle); 73 74 assertEquals("Selected tab is selected", i, tabOperator.getSelectedIndex()); 75 } 76 } 77 78} 79