|
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. */ package org.netbeans.test.gui.web.servletexec.servletdo; import org.netbeans.jellytools.JellyTestCase; import org.netbeans.jellytools.Bundle; import java.awt.event.KeyEvent; import java.io.File; import org.netbeans.test.gui.web.util.CommonUtils; import org.netbeans.jemmy.operators.JTreeOperator; import org.netbeans.jemmy.Timeouts; import org.netbeans.jemmy.TimeoutExpiredException; import org.netbeans.jemmy.operators.JButtonOperator; import org.netbeans.jemmy.EventDispatcher; import org.netbeans.jellytools.NbDialogOperator; import org.netbeans.jellytools.actions.FilesystemsViewAction; import org.netbeans.jellytools.actions.CopyAction; import org.netbeans.jellytools.actions.CutAction; import org.netbeans.jellytools.actions.PasteCopyAction; import org.netbeans.jellytools.actions.PasteAction; import org.netbeans.jellytools.actions.DeleteAction; import org.netbeans.jellytools.nodes.FolderNode; import org.netbeans.web.test.util.Utils; import org.netbeans.web.test.nodes.ServletNode; public class ServletDOActionsViaHotKeys extends JellyTestCase { private static String wmName = "wm2"; private static String webInf = "WEB-INF"; private static String classes = "Classes"; private static String fSep = System.getProperty("file.separator"); private static String iSep = "|"; private static String workDir = null; private static String webModule = null; private static String pkgFrom = null; private static String pkgTo = null; private static boolean first = true; private static String defaultFromPackage = "copyFrom"; private static String defaultToPackage = "copyTo"; private static String copyServlet = "ServletForCopy"; private static String copyServletInSameDir = "ServletForCopyInSameDir"; private static String copyServletToOut = "ServletToCopyOut"; private static String cutServletSameDir = "ServletForCutInSameDir"; private static String cutServletOut = "ServletForCutOut"; private static String cutServlet = "CutServlet"; private static String deleteServlet = "DeleteServlet"; private static String notDeleteServlet = "NotDeleteServlet"; public ServletDOActionsViaHotKeys(String testName) { super(testName); } public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static junit.framework.Test suite() { junit.framework.Test suite = new org.netbeans.junit.NbTestSuite(ServletDOActionsViaHotKeys.class); workDir = System.getProperty("servletexec.workdir").replace('/', fSep.charAt(0)); webModule = workDir + fSep + wmName; pkgFrom = webModule + iSep + webInf + iSep + classes + iSep + defaultFromPackage; pkgTo = webModule + iSep + webInf + iSep + classes + iSep + defaultToPackage; String wmc = System.getProperty("servletexec.mountcount"); int count = 0; if(wmc != null) { count = new Integer(wmc).intValue(); } if(first) { while(count >0) { Utils.handleDialogAfterNewWebModule(); count--; } first = false; } new FilesystemsViewAction().performMenu(); return suite; } public void testCopyServletFile () { ServletNode node1 = null; FolderNode nodeTo = null; try { node1 = new ServletNode(pkgFrom + iSep + copyServlet); nodeTo = new FolderNode(pkgTo); } catch (Exception e) { fail("Please check that all mounts are done properly"); e.printStackTrace(); } copyViaHotKeys(node1); pasteCopyViaHotKeys(nodeTo); isFail(CommonUtils.handleConfirmChangesDialog(true)); pasteCopyViaHotKeys(nodeTo); isFail(CommonUtils.handleConfirmChangesDialog(true)); checkValid(pkgTo + iSep + copyServlet); checkValid(pkgTo + iSep + copyServlet + "_1"); } public void testCopyServletFileToTheSamePackage () { ServletNode node1 = null; FolderNode nodeTo = null; try { node1 = new ServletNode(pkgFrom + iSep + copyServletInSameDir); nodeTo = new FolderNode(pkgFrom); } catch (Exception e) { fail("Please check that all mounts are done properly"); e.printStackTrace(); } copyViaHotKeys(node1); pasteCopyViaHotKeys(nodeTo); isFail(CommonUtils.handleConfirmChangesDialog(true)); pasteCopyViaHotKeys(nodeTo); isFail(CommonUtils.handleConfirmChangesDialog(true)); checkValid(pkgFrom + iSep + copyServletInSameDir + "_1"); checkValid(pkgFrom + iSep + copyServletInSameDir + "_2"); } public void testCopyServletFileToFilesystem () { ServletNode node1 = null; FolderNode nodeTo = null; String tempDir = System.getProperty("nbjunit.workdir") + "/testCSFTF_hc"; CommonUtils.mountLocalDirectory(tempDir); try { node1 = new ServletNode(pkgFrom + iSep + copyServletToOut); nodeTo = new FolderNode(tempDir); }catch (Exception e) { fail("Please check that all mounts are done properly"); e.printStackTrace(); } copyViaHotKeys(node1); pasteCopyViaHotKeys(nodeTo); isFail(CommonUtils.handleConfirmChangesDialog(false)); pasteCopyViaHotKeys(nodeTo); isFail(CommonUtils.handleConfirmChangesDialog(false)); checkValid(tempDir + iSep + copyServletToOut); checkValid(tempDir + iSep + copyServletToOut + "_1"); } public void testDeleteServletYes () { ServletNode node1 = null; FolderNode nodeTo = null; try { node1 = new ServletNode(pkgFrom + iSep + deleteServlet); }catch (Exception e) { fail("Please check that all mounts are done properly"); e.printStackTrace(); } deleteViaHotKeys(node1); NbDialogOperator dialog = new NbDialogOperator("Confirm Object Deletion");// NOI18N dialog.yes(); isFail(CommonUtils.handleConfirmChangesDialog(true)); //if (CommonUtils.isExplorerItemExist(pkgFrom + iSep + deleteServlet)) { // fail("Servlet exist after deletion"); // } } public void testDeleteServletNo () { ServletNode node1 = null; FolderNode nodeTo = null; try { node1 = new ServletNode(pkgFrom + iSep + deleteServlet); }catch (Exception e) { fail("Please check that all mounts are done properly"); e.printStackTrace(); } deleteViaHotKeys(node1); NbDialogOperator dialog = new NbDialogOperator("Confirm Object Deletion");// NOI18N dialog.no(); isFail(CommonUtils.handleConfirmChangesDialog(false)); if (!CommonUtils.isExplorerItemExist(pkgFrom + iSep + deleteServlet)) { fail("Servlet was deleted"); } } public void testCutServletFile () { ServletNode node1 = null; FolderNode nodeTo = null; try { node1 = new ServletNode(pkgFrom + iSep + cutServlet); nodeTo = new FolderNode(pkgTo); }catch (Exception e) { fail("Please check that all mounts are done properly"); e.printStackTrace(); } cutViaHotKeys(node1); pasteViaHotKeys(nodeTo); isFail(CommonUtils.handleConfirmChangesDialog(true)); if(CommonUtils.isExplorerItemExist(pkgFrom + iSep + cutServlet)) { fail("Not deleted after cut/paste"); } if(!CommonUtils.isExplorerItemExist(pkgTo + iSep + cutServlet)) { fail("Not pasted after cut/paste"); } } public void testCutServletFileToTheSamePackage () { ServletNode node1 = null; FolderNode nodeTo = null; try { node1 = new ServletNode(pkgFrom + iSep + cutServletSameDir); nodeTo = new FolderNode(pkgFrom); }catch (Exception e) { fail("Please check that all mounts are done properly"); e.printStackTrace(); } cutViaHotKeys(node1); pasteViaHotKeys(nodeTo); isFail(CommonUtils.handleConfirmChangesDialog(false)); try { node1 = new ServletNode(pkgFrom + iSep + cutServletSameDir); }catch (Exception e) { fail("Opration Cut/Paste failed"); } } public void testCutPasteServletFileToFilesystem () { ServletNode node1 = null; FolderNode nodeTo = null; String tempDir = System.getProperty("nbjunit.workdir") + "/testCPSFTF_hc"; CommonUtils.mountLocalDirectory(tempDir); try { node1 = new ServletNode(pkgFrom + iSep + cutServletOut); nodeTo = new FolderNode(tempDir); }catch (Exception e) { fail("Please check that all mounts are done properly"); e.printStackTrace(); } cutViaHotKeys(node1); pasteViaHotKeys(nodeTo); isFail(CommonUtils.handleConfirmChangesDialog(true)); checkValid(tempDir + iSep + cutServletOut); } /******************* Private methods ******************************/ /*DO private methods*/ private void copyViaHotKeys(ServletNode node) { try { new CopyAction().performShortcut(node); }catch(Exception e) { e.printStackTrace(); fail("Exception while try to copy servlet via HotKeys: " + e); } } private void cutViaHotKeys(ServletNode node) { try { new CutAction().performShortcut(node); }catch(Exception e) { e.printStackTrace(); fail("Exception while try to cut servlet via HotKeys: " + e); } } private void deleteViaHotKeys(ServletNode node) { try { new DeleteAction().performShortcut(node); }catch(Exception e) { e.printStackTrace(); fail("Exception while try to delete servlet via HotKeys: " + e); } } private void pasteViaHotKeys(FolderNode node) { try { new PasteAction().performShortcut(node); }catch(Exception e) { e.printStackTrace(); fail("Exception while try to paste servlet via HotKeys: " + e); } } private void pasteCopyViaHotKeys(FolderNode node) { try { new PasteAction().performShortcut(node); }catch(Exception e) { e.printStackTrace(); fail("Exception while try to paste copy of servlet via HotKeys: " + e); } } private void checkValid(String node) { try { ServletNode war = new ServletNode(node); }catch(Exception e) { fail("Valid servlet node (" + node + ")not found. " + e); e.printStackTrace(); } } private void isFail(String res) { if(res!=null) { fail(res); } } } |
... 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.