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