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. 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 package org.netbeans.jemmy.operators; 25 26 import static org.testng.Assert.fail; 27 28 import javax.swing.JDesktopPane; 29 import javax.swing.JFrame; 30 import javax.swing.JInternalFrame; 31 import javax.swing.event.InternalFrameEvent; 32 import javax.swing.event.InternalFrameListener; 33 34 import org.netbeans.jemmy.TimeoutExpiredException; 35 import org.testng.annotations.AfterClass; 36 import org.testng.annotations.BeforeClass; 37 import org.testng.annotations.Test; 38 39 public class JInternalFrameOperatorCloseTest { 40 41 private JFrameOperator frameOper; 42 43 private JInternalFrameOperator internalFrameOper; 44 45 @BeforeClass 46 protected void setUp() throws Exception { 47 JFrame frame = new JFrame(); 48 JDesktopPane desktop = new JDesktopPane(); 49 frame.setContentPane(desktop); 50 JInternalFrame internalFrame = new JInternalFrame("JInternalFrameOperatorTest", true, true, true, true); 51 internalFrame.setName("JInternalFrameOperatorTest"); 52 internalFrame.setSize(200, 200); 53 internalFrame.setVisible(true); 54 desktop.add(internalFrame); 55 frame.setSize(400,400); 56 frame.setLocationRelativeTo(null); 57 frame.setVisible(true); 58 frameOper = new JFrameOperator(); 59 internalFrameOper = new JInternalFrameOperator(frameOper); 60 internalFrameOper.setVerification(true); 61 } 62 63 @AfterClass 64 protected void tearDown() throws Exception { 65 frameOper.setVisible(false); 66 frameOper.dispose(); 67 } 68 69 @Test 70 public void testClose() { 71 72 InternalFrameListener listener = new InternalFrameListener() { 73 74 @Override 75 public void internalFrameOpened(InternalFrameEvent e) { 76 } 77 78 @Override 79 public void internalFrameIconified(InternalFrameEvent e) { 80 } 81 82 @Override 83 public void internalFrameDeiconified(InternalFrameEvent e) { 84 } 85 86 @Override 87 public void internalFrameDeactivated(InternalFrameEvent e) { 88 } 89 90 @Override 91 public void internalFrameClosing(InternalFrameEvent e) { 92 try { 93 this.wait(80000); 94 } catch (InterruptedException e1) { 95 e1.printStackTrace(); 96 } 97 } 98 99 @Override 100 public void internalFrameClosed(InternalFrameEvent e) { 101 } 102 103 @Override 104 public void internalFrameActivated(InternalFrameEvent e) { 105 } 106 }; 107 108 // Making not to close the fame for 1 minute and expecting TimeoutExpiredException 109 // from waitClosed() 110 try { 111 internalFrameOper.addInternalFrameListener(listener); 112 internalFrameOper.close(); 113 fail(); 114 } catch (TimeoutExpiredException e) { 115 } finally { 116 internalFrameOper.removeInternalFrameListener(listener); 117 } 118 119 // Really closing the frame 120 internalFrameOper.close(); 121 } 122 123 }