1
2/*
3 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24import org.jtregext.GuiTestListener;
25import com.sun.swingset3.demos.dialog.DialogDemo;
26import static com.sun.swingset3.demos.dialog.DialogDemo.*;
27import java.awt.Dimension;
28import java.awt.Point;
29import javax.swing.JDialog;
30import static org.testng.AssertJUnit.*;
31import org.testng.annotations.Test;
32import static org.jemmy2ext.JemmyExt.isIconified;
33import static org.jemmy2ext.JemmyExt.ByClassChooser;
34import org.netbeans.jemmy.ClassReference;
35import org.netbeans.jemmy.ComponentChooser;
36import static org.netbeans.jemmy.WindowWaiter.countWindows;
37import org.netbeans.jemmy.operators.JFrameOperator;
38import org.netbeans.jemmy.operators.JDialogOperator;
39import org.netbeans.jemmy.operators.JLabelOperator;
40import org.netbeans.jemmy.operators.JButtonOperator;
41import org.testng.annotations.Listeners;
42
43/*
44 * @test
45 * @key headful
46 * @summary Verifies SwingSet3 DialogDemo by checking that separate JDialog is
47 *          shown, it contains predefined label and no new dialogs are opened
48 *          when the "Show JDialog..." button is clicked.
49 *
50 * @library /sanity/client/lib/jemmy/src
51 * @library /sanity/client/lib/Extensions/src
52 * @library /sanity/client/lib/SwingSet3/src
53 * @modules java.desktop
54 *          java.logging
55 * @build org.jemmy2ext.JemmyExt
56 * @build com.sun.swingset3.demos.dialog.DialogDemo
57 * @run testng DialogDemoTest
58 */
59@Listeners(GuiTestListener.class)
60public class DialogDemoTest {
61
62    private final ComponentChooser jDialogClassChooser = new ByClassChooser(JDialog.class);
63
64    @Test
65    public void test() throws Exception {
66        new ClassReference(DialogDemo.class.getCanonicalName()).startApplication();
67        JFrameOperator mainFrame = new JFrameOperator(DIALOG_DEMO_TITLE);
68        JDialogOperator dialog = new JDialogOperator(DIALOG_TITLE);
69        JButtonOperator showJDialogButton = new JButtonOperator(mainFrame, SHOW_BUTTON_TITLE);
70        initialCheckWithLabel(mainFrame, dialog);
71        checkShowDialogButton(dialog, showJDialogButton);
72        TestHelpers.checkChangeSize(dialog, new Dimension(dialog.getSize().width * 2,
73                dialog.getSize().height * 2));
74        TestHelpers.checkChangeLocation(dialog, new Point(dialog.getLocation().x + 100,
75                dialog.getLocation().y + 100));
76    }
77
78    private void initialCheckWithLabel(JFrameOperator frame, JDialogOperator jdo) {
79        JLabelOperator label = new JLabelOperator(jdo);
80        assertFalse("JFrame is not iconified", isIconified(frame));
81        assertEquals("Only one JDialog is present", 1,
82                countWindows(jDialogClassChooser));
83        assertEquals(LABEL_CONTENT, label.getText());
84    }
85
86    private void checkShowDialogButton(JDialogOperator jdo, JButtonOperator jbo)
87            throws InterruptedException {
88        //Check that the button does not change the number of JDialog
89        jbo.push();
90        Thread.sleep(500);
91        assertEquals("Only one JDialog is present", 1,
92                countWindows(jDialogClassChooser));
93        assertTrue("Check JDialog is visible", jdo.isVisible());
94        jdo.requestClose();
95        jdo.waitClosed();
96        //Check that the button makes the JDialog visible
97        //and that 1 jDialog is present.
98        jbo.push();
99        jdo.waitComponentVisible(true);
100        Thread.sleep(500);
101        assertEquals("Only one JDialog is present", 1,
102                countWindows(jDialogClassChooser));
103    }
104}
105