Path: blob/master/test/jdk/sanity/client/SwingSet/src/ProgressBarDemoTest.java
41153 views
/*1* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import org.jtregext.GuiTestListener;24import com.sun.swingset3.demos.progressbar.ProgressBarDemo;25import static com.sun.swingset3.demos.progressbar.ProgressBarDemo.*;26import java.awt.Component;27import javax.swing.UIManager;28import static org.testng.AssertJUnit.*;29import org.testng.annotations.Test;30import org.netbeans.jemmy.ClassReference;31import org.netbeans.jemmy.ComponentChooser;32import org.netbeans.jemmy.Timeouts;33import org.netbeans.jemmy.operators.JButtonOperator;34import org.netbeans.jemmy.operators.JFrameOperator;35import org.netbeans.jemmy.operators.JProgressBarOperator;36import org.testng.annotations.Listeners;3738/*39* @test40* @key headful41* @summary Verifies SwingSet3 ProgressBarDemo page by pressing start and stop42* buttons and checking the progress bar and the buttons state.43*44* @library /sanity/client/lib/jemmy/src45* @library /sanity/client/lib/Extensions/src46* @library /sanity/client/lib/SwingSet3/src47* @modules java.desktop48* java.logging49* @build org.jemmy2ext.JemmyExt50* @build com.sun.swingset3.demos.progressbar.ProgressBarDemo51* @run testng/timeout=1200 ProgressBarDemoTest52*/53@Listeners(GuiTestListener.class)54public class ProgressBarDemoTest {5556private final static long PROGRESS_BAR_TIMEOUT = 180000;5758@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)59public void test(String lookAndFeel) throws Exception {60UIManager.setLookAndFeel(lookAndFeel);61new ClassReference(ProgressBarDemo.class.getCanonicalName()).startApplication();6263JFrameOperator frame = new JFrameOperator(DEMO_TITLE);6465JButtonOperator startButton = new JButtonOperator(frame, START_BUTTON);66JButtonOperator stopButton = new JButtonOperator(frame, STOP_BUTTON);67JProgressBarOperator jpbo = new JProgressBarOperator(frame);6869// Check that progress completes and corect enable/disable of start/stop buttons70checkCompleteProgress(frame, startButton, stopButton, jpbo);7172// Check progess bar progression and start/stop button disabled/enabled states73checkStartStop(frame, startButton, stopButton, jpbo);74}7576// Check that progress completes and corect enable/disable of start/stop buttons77public void checkStartStop(JFrameOperator frame, JButtonOperator startButton, JButtonOperator stopButton, JProgressBarOperator progressBar) throws Exception {78int initialProgress = progressBar.getValue();79System.out.println("initialProgress = " + initialProgress);80int maximum = progressBar.getMaximum();8182startButton.pushNoBlock();8384progressBar.waitState(new ComponentChooser() {8586@Override87public boolean checkComponent(Component comp) {88int value = progressBar.getValue();89return value < maximum;90}9192@Override93public String getDescription() {94return "Progress < maximum (" + maximum + ")";95}96});9798stopButton.waitComponentEnabled();99100progressBar.waitState(new ComponentChooser() {101102@Override103public boolean checkComponent(Component comp) {104int value = progressBar.getValue();105return value > 0;106}107108@Override109public String getDescription() {110return "Progress > 0";111}112});113114int progress = progressBar.getValue();115System.out.println("progress = " + progress);116117//Check that progress par has progressed and Start Button Disabled118assertTrue("Progress Bar Progressing (progress > 0, actual value: " + progress + ")", progress > 0);119assertFalse("Start Button Disabled", startButton.isEnabled());120assertTrue("Stop Button Enabled", stopButton.isEnabled());121122//Wait a liitle bit longer then Press stop get progress123progressBar.waitState(new ComponentChooser() {124125@Override126public boolean checkComponent(Component comp) {127return progressBar.getValue() > progress;128}129130@Override131public String getDescription() {132return "Progress > " + progress;133}134});135136stopButton.pushNoBlock();137138startButton.waitComponentEnabled();139140int interimProgress = progressBar.getValue();141142// Check that progress par has Stopped and Start Button Disabled143assertTrue("Progress Bar Stopped "144+ "(interimProgress, actual value: " + interimProgress + " "145+ "> progress, actual value: " + progress + ")",146interimProgress > progress);147assertTrue("Start Button Enabled", startButton.isEnabled());148assertFalse("Stop Button Disabled", stopButton.isEnabled());149}150151// Check progess bar progression and start/stop button disabled/enabled states152public void checkCompleteProgress(JFrameOperator frame, JButtonOperator startButton, JButtonOperator stopButton, JProgressBarOperator progressBar) throws Exception {153Timeouts timeouts = progressBar.getTimeouts();154long defaultTimeout = timeouts.getTimeout("ComponentOperator.WaitStateTimeout");155startButton.pushNoBlock();156157// Set progress bar timeout as 3 minutes as it take long time to reach maximum158timeouts.setTimeout("ComponentOperator.WaitStateTimeout", PROGRESS_BAR_TIMEOUT);159progressBar.waitValue(progressBar.getMaximum());160// Reset timeout to default timeout value161timeouts.setTimeout("ComponentOperator.WaitStateTimeout", defaultTimeout);162163startButton.waitComponentEnabled();164165assertEquals("Complete Progress", progressBar.getMaximum(), progressBar.getValue());166assertTrue("Start Button Enabled", startButton.isEnabled());167assertFalse("Stop Button Disabled", stopButton.isEnabled());168}169170}171172173