< prev index next >

test/sanity/client/SwingSet/src/ListDemoTest.java

Print this page




   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.list.ListDemo;
  26 import static com.sun.swingset3.demos.list.ListDemo.DEMO_TITLE;
  27 import static org.testng.AssertJUnit.*;
  28 import org.testng.annotations.Test;
  29 import static org.jemmy2ext.JemmyExt.getLabeledContainerOperator;

  30 import org.netbeans.jemmy.ClassReference;

  31 import org.netbeans.jemmy.operators.JCheckBoxOperator;
  32 import org.netbeans.jemmy.operators.JFrameOperator;
  33 import org.netbeans.jemmy.operators.JListOperator;





  34 import org.testng.annotations.Listeners;


  35 
  36 /*
  37  * @test
  38  * @key headful
  39  * @summary Verifies SwingSet3 ListDemo page by checking and unchecking all
  40  *          the checkboxes on the page and verifying the number of items in the
  41  *          list.
  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.list.ListDemo
  48  * @run testng ListDemoTest
  49  */
  50 @Listeners(GuiTestListener.class)
  51 public class ListDemoTest {
  52 
  53     private static final int CHECKBOX_COUNT = 50;
  54 











  55     @Test
  56     public void test() throws Exception {
  57 
  58         new ClassReference(ListDemo.class.getCanonicalName()).startApplication();
  59 
  60         JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
  61         JListOperator listOp = new JListOperator(frame);
  62 
  63         // Check *NO* Prefix and Suffixes Marked
  64         for (int i = 0; i < CHECKBOX_COUNT; i++) {
  65             JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
  66             checkBox.changeSelection(false);
  67         }
  68         System.out.println("######## Number of Items = " + listOp.getModel().getSize());
  69         assertEquals("Select None number of items is correct", 0, listOp.getModel().getSize());
  70 
  71         // Check *ALL* Prefix and Suffixes Marked
  72         for (int i = 0; i < CHECKBOX_COUNT; i++) {
  73             JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
  74             checkBox.changeSelection(true);
  75         }
  76         System.out.println("######## Number of Items = " + listOp.getModel().getSize());
  77         assertEquals("Select All number of items is correct", CHECKBOX_COUNT / 2 * CHECKBOX_COUNT / 2, listOp.getModel().getSize());
  78 
  79         // Check *ALL* Prefix and *NO* Suffixes Marked
  80         for (int i = 0; i < CHECKBOX_COUNT; i++) {
  81             JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
  82             if (i < CHECKBOX_COUNT / 2) {
  83                 checkBox.changeSelection(true);
  84             } else {
  85                 checkBox.changeSelection(false);
  86             }
  87         }
  88         System.out.println("######## Number of Items = " + listOp.getModel().getSize());
  89         assertEquals("Select All Prefixes and NO Suffixes number of items is correct", 0, listOp.getModel().getSize());
  90 
  91         // Check *NO* Prefix and *ALL* Suffixes Marked
  92         for (int i = 0; i < CHECKBOX_COUNT; i++) {
  93             JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
  94             if (i < CHECKBOX_COUNT / 2) {
  95                 checkBox.changeSelection(false);
  96             } else {
  97                 checkBox.changeSelection(true);
  98             }
  99         }
 100         System.out.println("######## Number of Items = " + listOp.getModel().getSize());
 101         assertEquals("Select NO Prefixes and All Suffixes number of items is correct", 0, listOp.getModel().getSize());
 102     }
 103 
 104     private JCheckBoxOperator getJCheckBoxOperator(JFrameOperator frame, int index) {
 105 
 106         // We map first half of indexes to the Prefixes panel and the second half
 107         // to the Suffixes panel
 108         String labelText;
 109         int subindex;
 110         if (index < CHECKBOX_COUNT / 2) {
 111             labelText = "Prefixes";
 112             subindex = index;
 113         } else {
 114             labelText = "Suffixes";
 115             subindex = index - CHECKBOX_COUNT / 2;
 116         }
 117 
 118         return new JCheckBoxOperator(getLabeledContainerOperator(frame, labelText), subindex);


 119     }
 120 
 121 }


   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 com.sun.swingset3.demos.list.ListDemo;
  25 import static com.sun.swingset3.demos.list.ListDemo.DEMO_TITLE;
  26 
  27 import java.awt.Component;
  28 import javax.swing.JList;
  29 
  30 import org.netbeans.jemmy.ClassReference;
  31 import org.netbeans.jemmy.ComponentChooser;
  32 import org.netbeans.jemmy.operators.JCheckBoxOperator;
  33 import org.netbeans.jemmy.operators.JFrameOperator;
  34 import org.netbeans.jemmy.operators.JListOperator;
  35 
  36 import static org.jemmy2ext.JemmyExt.*;
  37 
  38 import org.jtregext.GuiTestListener;
  39 
  40 import org.testng.annotations.Listeners;
  41 import org.testng.annotations.Test;
  42 import static org.testng.AssertJUnit.*;
  43 
  44 /*
  45  * @test
  46  * @key headful
  47  * @summary Verifies SwingSet3 ListDemo page by checking and unchecking all
  48  *          the checkboxes on the page and verifying the number of items in the
  49  *          list.
  50  *
  51  * @library /sanity/client/lib/jemmy/src
  52  * @library /sanity/client/lib/Extensions/src
  53  * @library /sanity/client/lib/SwingSet3/src
  54  * @modules java.desktop
  55  *          java.logging
  56  * @build org.jemmy2ext.JemmyExt
  57  * @build com.sun.swingset3.demos.list.ListDemo
  58  * @run testng ListDemoTest
  59  */
  60 @Listeners(GuiTestListener.class)
  61 public class ListDemoTest {
  62 
  63     private static final int CHECKBOX_COUNT = 50;
  64 
  65     private void waitModelSize(JListOperator listOp, int size) {
  66         listOp.waitState(new ComponentChooser() {
  67             public boolean checkComponent(Component comp) {
  68                 return getUIValue(listOp, (JList list) -> list.getModel().getSize()) == size;
  69             }
  70             public String getDescription() {
  71                 return "Model size to be equal to " + size;
  72             }
  73         });
  74     }
  75 
  76     @Test
  77     public void test() throws Exception {
  78 
  79         new ClassReference(ListDemo.class.getCanonicalName()).startApplication();
  80 
  81         JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
  82         JListOperator listOp = new JListOperator(frame);
  83 
  84         // Check *NO* Prefix and Suffixes Marked
  85         for (int i = 0; i < CHECKBOX_COUNT; i++) {
  86             JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
  87             checkBox.changeSelection(false);
  88         }
  89         waitModelSize(listOp, 0);

  90 
  91         // Check *ALL* Prefix and Suffixes Marked
  92         for (int i = 0; i < CHECKBOX_COUNT; i++) {
  93             JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
  94             checkBox.changeSelection(true);
  95         }
  96         waitModelSize(listOp, CHECKBOX_COUNT * CHECKBOX_COUNT / 4);

  97 
  98         // Check *ALL* Prefix and *NO* Suffixes Marked
  99         for (int i = 0; i < CHECKBOX_COUNT; i++) {
 100             JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
 101             if (i < CHECKBOX_COUNT / 2) {
 102                 checkBox.changeSelection(true);
 103             } else {
 104                 checkBox.changeSelection(false);
 105             }
 106         }
 107         waitModelSize(listOp, 0);

 108 
 109         // Check *NO* Prefix and *ALL* Suffixes Marked
 110         for (int i = 0; i < CHECKBOX_COUNT; i++) {
 111             JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
 112             if (i < CHECKBOX_COUNT / 2) {
 113                 checkBox.changeSelection(false);
 114             } else {
 115                 checkBox.changeSelection(true);
 116             }
 117         }
 118         waitModelSize(listOp, 0);

 119     }
 120 
 121     private JCheckBoxOperator getJCheckBoxOperator(JFrameOperator frame, int index) {
 122 
 123         // We map first half of indexes to the Prefixes panel and the second half
 124         // to the Suffixes panel
 125         String labelText;
 126         int subindex;
 127         if (index < CHECKBOX_COUNT / 2) {
 128             labelText = "Prefixes";
 129             subindex = index;
 130         } else {
 131             labelText = "Suffixes";
 132             subindex = index - CHECKBOX_COUNT / 2;
 133         }
 134 
 135         JCheckBoxOperator result = new JCheckBoxOperator(getLabeledContainerOperator(frame, labelText), subindex);
 136         result.setVerification(true);
 137         return result;
 138     }
 139 
 140 }
< prev index next >