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.combobox.ComboBoxDemo;
  26 import static org.testng.AssertJUnit.*;
  27 import org.testng.annotations.Test;
  28 import org.netbeans.jemmy.ClassReference;
  29 import org.netbeans.jemmy.operators.JComboBoxOperator;
  30 import org.netbeans.jemmy.operators.JFrameOperator;
  31 import static com.sun.swingset3.demos.combobox.ComboBoxDemo.*;
  32 import org.testng.annotations.Listeners;
  33 
  34 /*
  35  * @test
  36  * @key headful
  37  * @summary Verifies ComboBoxes on SwingSet2 ComboBoxDemo page by selecting
  38  *          each value of each ComboBox.
  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.combobox.ComboBoxDemo
  45  * @run testng ComboBoxDemoTest
  46  */
  47 @Listeners(GuiTestListener.class)
  48 public class ComboBoxDemoTest {
  49 
  50     private static enum ComboBoxInfo {
  51         PRESETS("Presets:"),
  52         HAIR("Hair:"),
  53         EYES_N_NOSE("Eyes & Nose:"),
  54         MOUTH("Mouth:");
  55 
  56         private final String comboBoxName;
  57 
  58         private ComboBoxInfo(String comboBoxName) {
  59             this.comboBoxName = comboBoxName;
  60         }
  61 
  62     }
  63 
  64     @Test
  65     public void test() throws Exception {
  66 
  67         new ClassReference(ComboBoxDemo.class.getCanonicalName()).startApplication();
  68 
  69         JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
  70         for (ComboBoxInfo comboBoxInfo : ComboBoxInfo.values()) {
  71             comboBoxChecker(frame, comboBoxInfo);
  72         }
  73     }
  74 
  75     private void comboBoxChecker(JFrameOperator jfo, ComboBoxInfo comboBoxInfo) {
  76         JComboBoxOperator jcbo = new JComboBoxOperator(jfo, comboBoxInfo.ordinal());
  77         for (int i = 0; i < jcbo.getItemCount(); i++) {
  78             jcbo.selectItem(i);
  79             assertEquals(comboBoxInfo.comboBoxName + " ComboBox SelectedIndex is correct", i, jcbo.getSelectedIndex());
  80         }
  81     }
  82 
  83 }