alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

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.
 */


/*
 * TestDOActionHotKey.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.web.test.nodes.*;
import org.netbeans.web.test.actions.*;

public class TestDOActionHotKey extends JellyTestCase {

    private static String workDir = null;
    private static ExplorerOperator explorer = null;
    private static TreeTableOperator treeOper = null;

    public TestDOActionHotKey(String testName) {
        super(testName);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }

    public static Test suite() {
            TestSuite suite = new NbTestSuite(TestDOActionHotKey.class);
            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()).performShortcut(nodeF);
            nodeT = new FilesystemNode(nodeTo);
            nodeT.select();
            (new PasteAction()).performShortcut(nodeT);
            nodeT.select();
            (new PasteAction()).performShortcut(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()).performShortcut(nodeF);
            nodeT = new FilesystemNode(nodeTo);
            nodeT.select();
            (new PasteAction()).performShortcut(nodeT);
            nodeT.select();
            (new PasteAction()).performShortcut(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 {
            nodeF = new JSPNode(node + "|JSP");
            nodeT = new FilesystemNode(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 {
            nodeF.select();
            (new CopyAction()).performShortcut(nodeF);
            nodeT.select();
            (new PasteAction()).performShortcut(nodeT);
            nodeT.select();
            (new PasteAction()).performShortcut(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 'Move' action                */
    /*------------------------------------------------------*/

    // TEST  ---- move JSP from one directory to another
    // 10-11

    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()).performShortcut(nodeF);
            nodeT = new FilesystemNode(nodeTo);
            nodeT.select();
            (new PasteAction()).performShortcut(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 
    // 12

    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()).performShortcut(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();
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.