1 /* 2 * Copyright (c) 2018, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package org.netbeans.jemmy.operators; 27 28 import static org.testng.Assert.fail; 29 30 import javax.swing.JDesktopPane; 31 import javax.swing.JFrame; 32 import javax.swing.JInternalFrame; 33 import javax.swing.UIManager; 34 import javax.swing.event.InternalFrameEvent; 35 import javax.swing.event.InternalFrameListener; 36 37 import org.netbeans.jemmy.JemmyProperties; 38 import org.netbeans.jemmy.LookAndFeelProvider; 39 import org.netbeans.jemmy.TimeoutExpiredException; 40 import org.testng.annotations.AfterMethod; 41 import org.testng.annotations.Test; 42 43 public class JInternalFrameOperatorCloseTest { 44 45 private JFrameOperator frameOper; 46 47 private JInternalFrameOperator internalFrameOper; 48 49 private void setUp() throws Exception { 50 JFrame frame = new JFrame(); 51 JDesktopPane desktop = new JDesktopPane(); 52 frame.setContentPane(desktop); 53 JemmyProperties.setCurrentDispatchingModel( 54 JemmyProperties.getCurrentDispatchingModel()); 55 JInternalFrame internalFrame = new JInternalFrame("JInternalFrameOperatorTest", true, true, true, true); 56 internalFrame.setName("JInternalFrameOperatorTest"); 57 internalFrame.setSize(200, 200); 58 internalFrame.setVisible(true); 59 desktop.add(internalFrame); 60 frame.setSize(400,400); 61 frame.setLocationRelativeTo(null); 62 frame.setVisible(true); 63 frameOper = new JFrameOperator(); 64 internalFrameOper = new JInternalFrameOperator(frameOper); 65 internalFrameOper.setVerification(true); 66 } 67 68 @AfterMethod 69 protected void tearDown() throws Exception { 70 frameOper.setVisible(false); 71 frameOper.dispose(); 72 } 73 74 @Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class) 75 public void testClose(String lookAndFeel) throws Exception { 76 UIManager.setLookAndFeel(lookAndFeel); 77 setUp(); 78 InternalFrameListener listener = new InternalFrameListener() { 79 80 @Override 81 public void internalFrameOpened(InternalFrameEvent e) { 82 } 83 84 @Override 85 public void internalFrameIconified(InternalFrameEvent e) { 86 } 87 88 @Override 89 public void internalFrameDeiconified(InternalFrameEvent e) { 90 } 91 92 @Override 93 public void internalFrameDeactivated(InternalFrameEvent e) { 94 } 95 96 @Override 97 public void internalFrameClosing(InternalFrameEvent e) { 98 try { 99 this.wait(80000); 100 } catch (InterruptedException e1) { 101 e1.printStackTrace(); 102 } 103 } 104 105 @Override 106 public void internalFrameClosed(InternalFrameEvent e) { 107 } 108 109 @Override 110 public void internalFrameActivated(InternalFrameEvent e) { 111 } 112 }; 113 114 // Making not to close the fame for 1 minute and expecting TimeoutExpiredException 115 // from waitClosed() 116 try { 117 internalFrameOper.addInternalFrameListener(listener); 118 internalFrameOper.close(); 119 fail(); 120 } catch (TimeoutExpiredException e) { 121 } finally { 122 internalFrameOper.removeInternalFrameListener(listener); 123 } 124 125 // Really closing the frame 126 internalFrameOper.close(); 127 } 128 129 }