|
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-2003 Sun * Microsystems, Inc. All Rights Reserved. */ /* * TestDOActionPopup.java * NetBeans JUnit based test * * Created on April 16, 2002, 4:11 PM */ package org.netbeans.test.gui.jspdo; import junit.framework.*; import org.netbeans.junit.*; import java.io.File; import org.netbeans.jellytools.*; import org.netbeans.jellytools.actions.*; import org.netbeans.jellytools.nodes.*; import org.netbeans.jemmy.operators.*; import org.netbeans.web.test.nodes.*; import org.netbeans.web.test.actions.*; public class TestDOActionPopup extends JellyTestCase { private static String workDir = null; private static ExplorerOperator explorer = null; private static TreeTableOperator treeOper = null; public TestDOActionPopup(String testName) { super(testName); } public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { TestSuite suite = new NbTestSuite(TestDOActionPopup.class); //TestSuite suite = new NbTestSuite(); //suite.addTest(new TestDOActionPopup("testViewServlet")); System.out.println("Test started"); workDir = System.getProperty("scratch.dir").replace('/',File.separatorChar); explorer = ExplorerOperator.invoke(); explorer.selectPageFilesystems(); return suite; } private void delay() { try { Thread.sleep(2000); }catch (Exception e) { } } /*------------------------------------------------------*/ /* Tests for 'Copy' action */ /*------------------------------------------------------*/ // TEST ---- copy JSP from one directory to another // 1-3 public void testCopyJSPFile () { JSPNode nodeF = null; FilesystemNode nodeT = null; JSPNode nodeCheck = null; String nodeFrom = workDir + "|" + "TestCopy1_1"; String nodeTo = workDir + "|" + "TestCopy1_2"; System.out.println("#Test COPY JSP from one directory to another"); try { nodeF = new JSPNode(nodeFrom + "|JSP"); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. try { (new CopyAction()).performPopup(nodeF); nodeT = new FilesystemNode(nodeTo); nodeT.select(); (new PasteCopyAction()).performPopup(nodeT); nodeT.select(); (new PasteCopyAction()).performPopup(nodeT); }catch(Exception e) { fail("Exception while try to copy JSP via Main menu: " + e); } try { nodeCheck = new JSPNode(nodeT, "JSP"); nodeCheck = new JSPNode(nodeT, "JSP_1"); } catch (org.netbeans.jemmy.TimeoutExpiredException timeExc) { fail("Copy for JSP Object failed"); } System.out.println("#Test COPY JSP from one directory to another finished"); System.out.flush(); // PASS } // TEST ---- copy JSP file from directory to filesystem // 4-6 public void testCopyJSPFileToFilesystem () { JSPNode nodeF = null; FilesystemNode nodeT = null; JSPNode nodeCheck = null; String nodeFrom = workDir + "|" + "TestCopy3_1"; String nodeTo = workDir; System.out.println("#Test COPY JSP from the directory to the filesystem"); try { nodeF = new JSPNode(nodeFrom + "|JSP"); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. try { (new CopyAction()).performPopup(nodeF); nodeT = new FilesystemNode(nodeTo); nodeT.select(); (new PasteCopyAction()).performPopup(nodeT); nodeT.select(); (new PasteCopyAction()).performPopup(nodeT); }catch(Exception e) { fail("Exception while try to copy JSP via Main menu: " + e); } try { nodeCheck = new JSPNode(nodeT, "JSP"); nodeCheck = new JSPNode(nodeT, "JSP_1"); } catch (org.netbeans.jemmy.TimeoutExpiredException timeExc) { fail("Copy for JSP Object failed"); } System.out.println("#Test COPY JSP from the directory to the filesystem finished"); System.out.flush(); // PASS } // TEST ---- copy JSP file to the same directory // 7-9 public void testCopyJSPFileToTheSameNode () { JSPNode nodeF = null; FilesystemNode nodeT = null; JSPNode nodeCheck = null; String node = workDir + "|" + "TestCopy2_1"; System.out.println("#Test COPY JSP to the same node"); try { nodeT = new FilesystemNode(node); nodeF = new JSPNode(nodeT, "JSP"); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. try { nodeF.select(); (new CopyAction()).performPopup(nodeF); nodeT.select(); (new PasteCopyAction()).performPopup(nodeT); nodeT.select(); (new PasteCopyAction()).performPopup(nodeT); }catch(Exception e) { fail("Exception while try to copy JSP via Main menu: " + e); } try { nodeCheck = new JSPNode(nodeT, "JSP_1"); nodeCheck = new JSPNode(nodeT, "JSP_2"); } catch (org.netbeans.jemmy.TimeoutExpiredException timeExc) { fail("Copy for JSP Object failed"); } System.out.println("#Test COPY JSP to the same node finished"); System.out.flush(); // PASS } /*------------------------------------------------------*/ /* Tests for 'Link' action */ /*------------------------------------------------------*/ // TEST ---- link JSP from one directory to another // 10-12 public void testLinkJSPFile () { JSPNode nodeF = null; FilesystemNode nodeT = null; JSPNode nodeCheck = null; String nodeFrom = workDir + "|" + "TestLink1_1"; String nodeTo = workDir + "|" + "TestLink1_2"; System.out.println("#Test LINK JSP from one folder to another"); try { nodeF = new JSPNode(nodeFrom + "|JSP"); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. try { (new CopyAction()).performPopup(nodeF); nodeT = new FilesystemNode(nodeTo); nodeT.select(); (new PasteLinkAction()).performPopup(nodeT); nodeT.select(); (new PasteLinkAction()).performPopup(nodeT); }catch(Exception e) { fail("Exception while try to copy JSP via Main menu: " + e); } try { nodeCheck = new JSPNode(nodeT, "JSP"); nodeCheck = new JSPNode(nodeT, "JSP_1"); } catch (org.netbeans.jemmy.TimeoutExpiredException timeExc) { fail("Link for JSP Object failed"); } System.out.println("#Test LINK JSP from one folder to another finished"); System.out.flush(); // PASS } /*------------------------------------------------------*/ /* Tests for 'Move' action */ /*------------------------------------------------------*/ // TEST ---- move JSP from one directory to another // 13-14 public void testMoveJSPFile () { JSPNode nodeF = null; FilesystemNode nodeT = null; JSPNode nodeCheck = null; String nodeFrom = workDir + "|" + "TestMove1_1"; String nodeTo = workDir + "|" + "TestMove1_2"; System.out.println("#Test MOVE JSP from one folder to another"); try { nodeF = new JSPNode(nodeFrom + "|JSP"); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. try { (new CutAction()).performPopup(nodeF); nodeT = new FilesystemNode(nodeTo); nodeT.select(); (new PasteAction()).performPopup(nodeT); delay(); }catch(Exception e) { fail("Exception while try to copy JSP via Main menu: " + e); } try { nodeCheck = new JSPNode(nodeT, "JSP"); } catch (org.netbeans.jemmy.TimeoutExpiredException timeExc) { fail("Copy for JSP Object failed"); } try { nodeCheck = new JSPNode(nodeFrom + "|JSP"); fail("Move for JSP Object failed. Source file was not deleted"); } catch(org.netbeans.jemmy.TimeoutExpiredException timeExc) { // We didn't find source file. It's OK. } System.out.println("#Test MOVE JSP from one folder to another finished"); System.out.flush(); // PASS } /*------------------------------------------------------*/ /* Tests for 'Delete' action */ /*------------------------------------------------------*/ // TEST ---- Delete JSP from the directory // 15 public void testDeleteJSPFile () { JSPNode nodeD = null; JSPNode nodeCheck = null; String node = workDir + "|" + "TestDelete1_1" + "|" + "JSP"; System.out.println("#Test Delete JSP from the folder"); try { nodeD = new JSPNode(node); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. try { nodeD.select(); (new DeleteAction()).performPopup(nodeD); }catch(Exception e) { fail("Exception while try to delete JSP via Main menu: " + e); } try { String confirm = Bundle.getString("org.openide.explorer.Bundle","MSG_ConfirmDeleteObjectTitle"); NbDialogOperator nbDialog = new NbDialogOperator(confirm); nbDialog.yes(); } catch (Exception e) { fail("Confirm dialog was not found"); } delay(); try { nodeCheck = new JSPNode(node); fail("Delete for JSP Object failed. Source file was not deleted"); } catch(org.netbeans.jemmy.TimeoutExpiredException timeExc) { // We didn't find source file. It's OK. } System.out.println("#Test Delete JSP from the folder finished"); System.out.flush(); } /*------------------------------------------------------*/ /* Tests for 'Rename' action */ /*------------------------------------------------------*/ // TEST ---- Rename JSP node // 16-17 public void testRenameJSPFile () { JSPNode nodeR = null; JSPNode nodeCheck = null; String node = workDir + "|" + "TestRename1_1"; System.out.println("#Test Rename JSP node"); try { nodeR = new JSPNode(node + "|" + "JSP"); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. try { nodeR.select(); (new RenameAction()).performPopup(nodeR); }catch(Exception e) { fail("Exception while try to delete JSP via Main menu: " + e); } try { String rename = Bundle.getString("org.openide.actions.Bundle","CTL_RenameTitle"); NbDialogOperator nbDialog = new NbDialogOperator(rename); JTextFieldOperator textField = new JTextFieldOperator(nbDialog); textField.setText("JSP_1"); nbDialog.ok(); } catch (Exception e) { fail("Rename dialog was not found"); } try { nodeCheck = new JSPNode(node + "|JSP_1"); } catch (org.netbeans.jemmy.TimeoutExpiredException timeExc) { fail("Rename for JSP Object failed"); } System.out.println("#Test Rename JSP node "); System.out.flush(); } /*------------------------------------------------------*/ /* Tests for 'Open' action */ /*------------------------------------------------------*/ // TEST ---- Open JSP in Editor // 18 public void testOpenJSPFile () { JSPNode nodeO = null; String node = workDir + "|" + "TestOpen1_1"; System.out.println("#Test Open JSP"); try { nodeO = new JSPNode(node + "|" + "JSP"); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. nodeO.select(); new OpenAction().performPopup(nodeO); try { EditorWindowOperator editorWindow = new EditorWindowOperator("JSP"); EditorOperator editor = editorWindow.selectPage("JSP"); editor.closeDiscard(); } catch (Exception e) { fail("Open for JSP node doesn't work"); } System.out.println("#Test Open JSP finished"); System.out.flush(); } /*------------------------------------------------------*/ /* Tests for 'View Servlet' action */ /*------------------------------------------------------*/ // TEST ---- View Servlet for JSP in Editor //19-20 public void testViewServlet () { JSPNode nodeV = null; String[] variants={"Finished JSP."}; String node = workDir + "|" + "TestOpen1_1"; System.out.println("#Test View Servlet JSP"); try { nodeV = new JSPNode(node + "|" + "JSP"); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. nodeV.compile(); MainWindowOperator mainWindow = MainWindowOperator.getDefault(); try { mainWindow.waitStatusText("Finished JSP"); } catch (Exception e) { fail("Unable to compile JSP"); } nodeV.viewServlet(); try { EditorWindowOperator editorWindow = new EditorWindowOperator("Servlet for JSP"); EditorOperator editor = editorWindow.selectPage("Servlet for JSP"); editor.closeDiscard(); } catch (Exception e) { fail("Unable to find a servlet window"); } System.out.println("#Test View Servlet finished"); System.out.flush(); } /*------------------------------------------------------*/ /* Tests for 'Save As Template action' */ /*------------------------------------------------------*/ // TEST ---- Save as template // 21-23 public void testSaveAsTemplate () { FilesystemNode systemNode= null; JSPNode nodeFrom = null; JSPNode nodeCheck = null; String node = workDir + "|" + "TestOpen1_1"; System.out.println("#Test Save as Template"); try { systemNode = new FilesystemNode (node); nodeFrom = new JSPNode( systemNode, "JSP"); } catch (Exception e) { fail("Select for JSP node failed. Please check that all mounts are done properly"); e.printStackTrace(); } // At this moment we're sure that JSP node exist and we can apply copy action to it. String whereTo = Bundle.getString("org.netbeans.modules.web.core.Bundle","Templates/JSP_Servlet"); try { nodeFrom.saveAsTemplate(); SaveAsTemplateOperator saveAsTemplate = new SaveAsTemplateOperator(); saveAsTemplate.selectTemplate(whereTo); saveAsTemplate.ok(); } catch (Exception e) { fail("Unable to call SaveAsTemplate dialog"); } try { NewWizardOperator wizard = NewWizardOperator.invoke(systemNode,whereTo + "|JSP_1"); wizard.finish(); } catch (Exception e) { fail("New wizard dialog was not found"); } try { nodeCheck = new JSPNode(systemNode, "JSP_1"); } catch (Exception e) { fail("New JSP node from template was not created"); } System.out.println("#Test Save as Template"); System.out.flush(); } } |
... 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.