ProgressBarDemoTest.java revision 13978:1993af50385d
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 com.sun.swingset3.demos.progressbar.ProgressBarDemo; 25import static com.sun.swingset3.demos.progressbar.ProgressBarDemo.*; 26import java.awt.Component; 27import static org.testng.AssertJUnit.*; 28import org.testng.annotations.Test; 29import org.netbeans.jemmy.ClassReference; 30import org.netbeans.jemmy.ComponentChooser; 31import org.netbeans.jemmy.operators.JButtonOperator; 32import org.netbeans.jemmy.operators.JFrameOperator; 33import org.netbeans.jemmy.operators.JProgressBarOperator; 34import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; 35 36/* 37 * @test 38 * @key headful 39 * @summary Verifies SwingSet3 ProgressBarDemo page by pressing start and stop 40 * buttons and checking the progress bar and the buttons state. 41 * 42 * @library /sanity/client/lib/jemmy/src 43 * @library /sanity/client/lib/Jemmy2Ext/src 44 * @library /sanity/client/lib/SwingSet3/src 45 * @build org.jemmy2ext.JemmyExt 46 * @build com.sun.swingset3.demos.progressbar.ProgressBarDemo 47 * @run testng ProgressBarDemoTest 48 */ 49public class ProgressBarDemoTest { 50 51 @Test 52 public void test() throws Exception { 53 captureDebugInfoOnFail(() -> { 54 new ClassReference(ProgressBarDemo.class.getCanonicalName()).startApplication(); 55 56 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); 57 58 JButtonOperator startButton = new JButtonOperator(frame, START_BUTTON); 59 JButtonOperator stopButton = new JButtonOperator(frame, STOP_BUTTON); 60 JProgressBarOperator jpbo = new JProgressBarOperator(frame); 61 62 // Check that progress completes and corect enable/disable of start/stop buttons 63 checkCompleteProgress(frame, startButton, stopButton, jpbo); 64 65 // Check progess bar progression and start/stop button disabled/enabled states 66 checkStartStop(frame, startButton, stopButton, jpbo); 67 }); 68 } 69 70 // Check that progress completes and corect enable/disable of start/stop buttons 71 public void checkStartStop(JFrameOperator frame, JButtonOperator startButton, JButtonOperator stopButton, JProgressBarOperator progressBar) throws Exception { 72 int initialProgress = progressBar.getValue(); 73 System.out.println("initialProgress = " + initialProgress); 74 int maximum = progressBar.getMaximum(); 75 76 startButton.pushNoBlock(); 77 78 progressBar.waitState(new ComponentChooser() { 79 80 @Override 81 public boolean checkComponent(Component comp) { 82 int value = progressBar.getValue(); 83 System.out.println("checkComponent1 value = " + value); 84 return value < maximum; 85 } 86 87 @Override 88 public String getDescription() { 89 return "Progress < maximum (" + maximum + ")"; 90 } 91 }); 92 93 stopButton.waitComponentEnabled(); 94 95 progressBar.waitState(new ComponentChooser() { 96 97 @Override 98 public boolean checkComponent(Component comp) { 99 int value = progressBar.getValue(); 100 System.out.println("checkComponent2 value = " + value); 101 return value > 0; 102 } 103 104 @Override 105 public String getDescription() { 106 return "Progress > 0"; 107 } 108 }); 109 110 int progress = progressBar.getValue(); 111 System.out.println("progress = " + progress); 112 113 //Check that progress par has progressed and Start Button Disabled 114 assertTrue("Progress Bar Progressing (progress > 0, actual value: " + progress + ")", progress > 0); 115 assertFalse("Start Button Disabled", startButton.isEnabled()); 116 assertTrue("Stop Button Enabled", stopButton.isEnabled()); 117 118 //Wait a liitle bit longer then Press stop get progress 119 progressBar.waitState(new ComponentChooser() { 120 121 @Override 122 public boolean checkComponent(Component comp) { 123 return progressBar.getValue() > progress; 124 } 125 126 @Override 127 public String getDescription() { 128 return "Progress > " + progress; 129 } 130 }); 131 132 stopButton.pushNoBlock(); 133 134 startButton.waitComponentEnabled(); 135 136 int interimProgress = progressBar.getValue(); 137 138 // Check that progress par has Stopped and Start Button Disabled 139 assertTrue("Progress Bar Stopped " 140 + "(interimProgress, actual value: " + interimProgress + " " 141 + "> progress, actual value: " + progress + ")", 142 interimProgress > progress); 143 assertTrue("Start Button Enabled", startButton.isEnabled()); 144 assertFalse("Stop Button Disabled", stopButton.isEnabled()); 145 } 146 147 // Check progess bar progression and start/stop button disabled/enabled states 148 public void checkCompleteProgress(JFrameOperator frame, JButtonOperator startButton, JButtonOperator stopButton, JProgressBarOperator progressBar) throws Exception { 149 startButton.pushNoBlock(); 150 151 progressBar.waitValue(progressBar.getMaximum()); 152 153 startButton.waitComponentEnabled(); 154 155 assertEquals("Complete Progress", progressBar.getMaximum(), progressBar.getValue()); 156 assertTrue("Start Button Enabled", startButton.isEnabled()); 157 assertFalse("Stop Button Disabled", stopButton.isEnabled()); 158 } 159 160} 161