|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.test.gui.web.AppletDebug; import java.io.File; import javax.swing.tree.TreePath; import javax.swing.JPopupMenu; import org.netbeans.junit.NbTestSuite; import org.netbeans.junit.NbTestCase; import junit.framework.Test; import junit.framework.TestSuite; import org.netbeans.jellytools.EditorOperator; import org.netbeans.jellytools.EditorWindowOperator; import org.netbeans.jellytools.ExplorerOperator; import org.netbeans.jellytools.JellyTestCase; import org.netbeans.jellytools.MainWindowOperator; import org.netbeans.jellytools.OptionsOperator; import org.netbeans.jellytools.OutputWindowOperator; import org.netbeans.jellytools.TreeTableOperator; import org.netbeans.jellytools.actions.ExecuteAction; import org.netbeans.jellytools.properties.PropertySheetOperator; import org.netbeans.jellytools.properties.PropertySheetTabOperator; import org.netbeans.jellytools.properties.TextFieldProperty; import org.netbeans.jemmy.Waiter; import org.netbeans.jemmy.TimeoutExpiredException; import org.netbeans.jemmy.Waiter; import org.netbeans.jemmy.operators.JPopupMenuOperator; import org.netbeans.jemmy.operators.JTreeOperator; import org.netbeans.web.test.util.Utils; import org.netbeans.test.gui.web.util.AppletResponseWaitable; import org.netbeans.test.gui.web.util.CommonUtils; public class Execute extends JellyTestCase { public static final String delim = "|"; private static String workDir = null; private static String tmpWebModule = null; private static String webModule = null; private static String wmName = "wm"; private static String testWMDir = "debug"; private static String osName = null; private static String netscape6 = "netscape6"; private static String netscape4x = "netscape"; private static ExplorerOperator explorer = null; private static EditorOperator editor = null; public Execute(String testName) { super(testName); } /** Use for execution inside IDE */ public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { workDir = System.getProperty("appletdebug.workdir").replace('/',File.separatorChar); webModule = workDir + File.separatorChar + wmName; workDir = webModule+delim+testWMDir; explorer = ExplorerOperator.invoke(); explorer.selectPageFilesystems(); Utils.handleDialogAfterNewWebModule(); TestSuite suite = new NbTestSuite(Execute.class); System.out.println("Test started"); osName = System.getProperty("os.name"); if(osName.indexOf("Windows")!=-1){ netscape6 = "netscp"; netscape4x = "netscape -browser"; } return suite; } public void testExecuteMenuAppletAppletviewer() { setBrowser("appletviewer"); editor = CommonUtils.openFile(workDir, "simpleApplet"); ExecuteAction executeAction = new ExecuteAction(); (new ExecuteAction()).performMenu(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleApplet"); fail("Timeout while waiting for response from Applet: " + "simpleApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleApplet"); } public void testExecutePopupAppletAppletviewer() { setBrowser("appletviewer"); editor = CommonUtils.openFile(workDir, "simpleApplet"); ExecuteAction executeAction = new ExecuteAction(); (new ExecuteAction()).performPopup(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleApplet"); fail("Timeout while waiting for response from Applet: " + "simpleApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleApplet"); } public void testExecuteShortcutAppletAppletviewer() { setBrowser("appletviewer"); editor = CommonUtils.openFile(workDir, "simpleApplet"); ExecuteAction executeAction = new ExecuteAction(); (new ExecuteAction()).performShortcut(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleApplet"); fail("Timeout while waiting for response from Applet: " + "simpleApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleApplet"); } public void testExecuteAppletNetscape6() { setBrowser(netscape6); editor = CommonUtils.openFile(workDir, "simpleApplet"); ExecuteAction executeAction = new ExecuteAction(); executeAction.perform(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleApplet"); fail("Timeout while waiting for response from Applet: " + "simpleApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleApplet"); } public void testExecuteAppletIE() { if(osName.indexOf("Windows")!=-1){ setBrowser("iexplore"); editor = CommonUtils.openFile(workDir, "simpleApplet"); ExecuteAction executeAction = new ExecuteAction(); executeAction.perform(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleApplet"); fail("Timeout while waiting for response from Applet: " + "simpleApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleApplet"); }else{ fail("Iexplore donot supported under this OS."); } } public void testExecuteAppletNetscape4() { setBrowser(netscape4x); editor = CommonUtils.openFile(workDir, "simpleApplet"); ExecuteAction executeAction = new ExecuteAction(); executeAction.perform(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleApplet"); fail("Timeout while waiting for response from Applet: " + "simpleApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleApplet"); } public void testExecuteJAppletAppletviewer() { setBrowser("appletviewer"); editor = CommonUtils.openFile(workDir, "simpleJApplet"); ExecuteAction executeAction = new ExecuteAction(); executeAction.perform(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleJApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleJApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleJApplet"); fail("Timeout while waiting for response from Applet: " + "simpleJApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleJApplet"); } public void testExecuteJAppletNetscape6() { setBrowser(netscape6); editor = CommonUtils.openFile(workDir, "simpleJApplet"); ExecuteAction executeAction = new ExecuteAction(); executeAction.perform(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleJApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleJApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleJApplet"); fail("Timeout while waiting for response from Applet: " + "simpleJApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleJApplet"); } public void testExecuteJAppletIE() { if(osName.indexOf("Windows")!=-1){ setBrowser("iexplore"); editor = CommonUtils.openFile(workDir, "simpleJApplet"); ExecuteAction executeAction = new ExecuteAction(); executeAction.perform(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleJApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleJApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleJApplet"); fail("Timeout while waiting for response from Applet: " + "simpleJApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleJApplet"); }else{ fail("Iexplore donot supported under this OS."); } } public void testExecuteJAppletNetscape4() { setBrowser(netscape4x); editor = CommonUtils.openFile(workDir, "simpleJApplet"); ExecuteAction executeAction = new ExecuteAction(); executeAction.perform(); AppletResponseWaitable jsrw = new AppletResponseWaitable("simpleJApplet", "", 1234); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (InterruptedException e) { e.printStackTrace(); killExecution("simpleJApplet"); fail("Exception while waiting for response from Applet:" + e + ". Real ID:" + jsrw.getId()); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); killExecution("simpleJApplet"); fail("Timeout while waiting for response from Applet: " + "simpleJApplet" + ". Real ID:" + jsrw.getId()); } killExecution("simpleJApplet"); } public void testExecuteJAppletIncorrect() { setBrowser("appletviewer"); editor = CommonUtils.openFile(workDir, "JappletWithError"); ExecuteAction executeAction = new ExecuteAction(); executeAction.perform(); try { MainWindowOperator.getDefault().waitStatusText("Errors compiling JappletWithError."); (new OutputWindowOperator()).selectCompilerPage(); String output = (new OutputWindowOperator()).getText(); if(output.indexOf("debug/JappletWithError.java [18:1] cannot resolve symbol\nsymbol : method incorrectFunction ()\nlocation: class debug.JappletWithError\n incorrectFunction();\n ^\n1 error\nErrors compiling JappletWithError.")==-1){ fail("No any errors to compilerTab orerror is incorrect. Error:"+output); } }catch(Exception e){ fail("Failed while wait result of compilation."); e.printStackTrace(); } } private void setBrowser(String browser){ OptionsOperator optOper = OptionsOperator.invoke(); TreeTableOperator treetable = optOper.treeTable(); int i = optOper.selectOption("Debugging and Executing|Execution Types|Applet Execution"); PropertySheetOperator properties = new PropertySheetOperator(); PropertySheetTabOperator propertiesSheet = new PropertySheetTabOperator(properties, "Properties"); TextFieldProperty nameProperty = new TextFieldProperty(propertiesSheet, "External Viewer"); nameProperty.setValue(browser+" {URL}"); optOper.close(); } private void killExecution(String fileName) { try{ ExplorerOperator explorer = ExplorerOperator.invoke(); JTreeOperator jTreeOper = explorer.runtimeTab().tree(); TreePath treePath = jTreeOper.findPath("Processes|"+fileName, delim); JPopupMenu popupMenu = jTreeOper.callPopupOnPath(treePath); JPopupMenuOperator popupOper = new JPopupMenuOperator(popupMenu); popupOper.pushMenu("Terminate Process", "|"); }catch(Exception e){ System.out.println("Cannot kill process for "+fileName+"\nException is:"); e.printStackTrace(); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.