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-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.test.gui.web.warpackager; 

import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.Bundle;

import org.netbeans.jellytools.nodes.FilesystemNode;
import org.netbeans.jellytools.nodes.Node;
import org.netbeans.web.test.nodes.WARNode;


import org.netbeans.jellytools.OutputWindowOperator;
import org.netbeans.jellytools.NbDialogOperator;
import org.netbeans.jellytools.RuntimeTabOperator;
import org.netbeans.jellytools.ExplorerOperator;
import org.netbeans.jellytools.MainWindowOperator;

import org.netbeans.jellytools.actions.ExplorerViewAction;
import org.netbeans.jellytools.actions.CopyAction;
import org.netbeans.jellytools.actions.CutAction;
import org.netbeans.jellytools.actions.PasteAction;
import org.netbeans.jellytools.actions.PasteCopyAction;
import org.netbeans.jellytools.actions.DeleteAction;

import org.netbeans.junit.NbTestSuite;

import org.netbeans.jemmy.operators.JTreeOperator;
import org.netbeans.jemmy.util.RegExComparator;
import org.netbeans.jemmy.operators.Operator;
import org.netbeans.jemmy.Waiter;
import org.netbeans.jemmy.Waitable;
import org.netbeans.jemmy.TimeoutExpiredException;

import java.awt.event.KeyEvent;

import org.netbeans.jellytools.EditorOperator;
import org.netbeans.jellytools.EditorWindowOperator;

import org.netbeans.jemmy.operators.JEditorPaneOperator;
/* */
public class WARFileDOViaPopup extends JellyTestCase {
    private static String workDir = null;     
    private static String webModule = null;
    private static String wmName = "wmdo";
    private static String fSep = System.getProperty("file.separator");
    private static String iSep = "|";
    private static String classes = null;
    private static String from1 = null;
    private static String from2 = null;
    private static String from3 = null;
    private static String to1 = null;
    private static String to2 = null;
    private static String to3 = null;
    private static ExplorerOperator explorer = null;
    //constructor required by JUnit
    public WARFileDOViaPopup(java.lang.String testName) {
        super(testName);
    }
    
    //method allowing to execute test directly
    //from IDE for debugging    
    public static void main(java.lang.String[] args) {
        junit.textui.TestRunner.run(suite());
    }
         
    //method required by JUnit
    public static junit.framework.Test suite() {
        junit.framework.Test suite =  new NbTestSuite(WARFileDOViaPopup.class);
	workDir = System.getProperty("warpackager.workdir").replace('/', fSep.charAt(0));
        from1 = workDir + iSep + "from1";
	from2 = workDir + iSep + "from2";
	from3 = workDir + iSep + "from3";
	to1 = workDir + iSep + "to1";
	to2 = workDir + iSep + "to2";
	to3 = workDir + iSep + "to3";
	explorer = ExplorerOperator.invoke();
	explorer.selectPageFilesystems();
	return suite;
    }

    public void testCopyWARFile() {
	WARNode node1 = null;
        FilesystemNode nodeTo = null;

        try {
	    System.out.println("Try to construct node : " + from1 + "|war1");
            node1 = new WARNode(from1 + "|war1");
	    nodeTo = new FilesystemNode(to1);
        } catch (Exception e) {
            fail("Please check that all mounts are done properly");
            e.printStackTrace();
        }
	try {
	    node1.select();
            (new CopyAction()).performPopup(node1);
            nodeTo.select();
            (new PasteCopyAction()).performPopup(nodeTo);
            nodeTo.select();
            (new PasteCopyAction()).performPopup(nodeTo);
        }catch(Exception e) {
            fail("Exception while try to copy WAR via popup menu: " + e);
        }
	checkValid(to1 + "|war1");
	checkValid(to1 + "|war1_1");
    }

    public void testCopyWARFileToTheSameLocation() {
	WARNode node1 = null;
        FilesystemNode nodeTo = null;

        try {
            node1 = new WARNode(from2 + "|war1");
	    nodeTo = new FilesystemNode(from2);
        } catch (Exception e) {
            fail("Please check that all mounts are done properly");
            e.printStackTrace();
        }
	try {
	    node1.select();
            (new CopyAction()).performPopup(node1);
            nodeTo.select();
            (new PasteCopyAction()).performPopup(nodeTo);
            nodeTo.select();
            (new PasteCopyAction()).performPopup(nodeTo);
        }catch(Exception e) {
            fail("Exception while try to copy WAR via popup menu: " + e);
        }
	checkValid(from2 + "|war1_1");
	checkValid(from2 + "|war1_2");
    }

    public void testMoveWARFile() {
	WARNode node1 = null;
        FilesystemNode nodeTo = null;

        try {
            node1 = new WARNode(from1 + "|war2");
	    nodeTo = new FilesystemNode(to1);
        } catch (Exception e) {
            fail("Please check that all mounts are done properly");
            e.printStackTrace();
        }
	try {
	    node1.select();
            (new CutAction()).performPopup(node1);
            nodeTo.select();
            (new PasteAction()).performPopup(nodeTo);
        }catch(Exception e) {
            fail("Exception while try to copy WAR via popup menu: " + e);
        }
	checkValid(to1 + "|war2");
	//OK. But we shoul not paste more then once
	try {
	    nodeTo = new FilesystemNode(to2);
	    nodeTo.select();
	    (new PasteAction()).performPopup(nodeTo);
	}catch(Exception e) {
	    //Pass
        }
	try {
            node1 = new WARNode(to2 + "|war2");
	    fail("Paste twice after cut");
	} catch (Exception e) {
	    //PASS
        }

    }

    public void testMoveWARFileToTheSameLocation() {
	WARNode node1 = null;
        FilesystemNode nodeTo = null;

        try {
            node1 = new WARNode(from1 + "|war3");
	    nodeTo = new FilesystemNode(from1);
        } catch (Exception e) {
            fail("Please check that all mounts are done properly");
            e.printStackTrace();
        }
	try {
	    node1.select();
            (new CutAction()).performPopup(node1);
            nodeTo.select();
            (new PasteAction()).performPopup(nodeTo);
        }catch(Exception e) {
            fail("Exception while try to cut/paste WAR via popup menu: " + e);
        }
	checkValid(from1 + "|war3");
    }

    public void testDeleteYesXSWARFile() {
	WARNode node1 = null;
        FilesystemNode nodeTo = null;

        try {
            node1 = new WARNode(from1 + "|war4");
	} catch (Exception e) {
            fail("Please check that all mounts are done properly");
            e.printStackTrace();
        }
	try {
	    node1.select();
            (new DeleteAction()).performPopup(node1);
	    deleteYes();
        }catch(Exception e) {
            fail("Exception while try to delete WAR via popup menu: " + e);
        }

	try {
            node1 = new WARNode(from1 + "|war4");
	    fail("war4 node was not deleted via popup");
	} catch (Exception e) {
	    //PASS
        }

	
    }

    public void testDeleteNoXSWARFile() {
	WARNode node1 = null;
        FilesystemNode nodeTo = null;

        try {
            node1 = new WARNode(from2 + "|war4");
	} catch (Exception e) {
            fail("Please check that all mounts are done properly");
            e.printStackTrace();
        }
	try {
	    node1.select();
            (new DeleteAction()).performPopup(node1);
	    deleteNo();
        }catch(Exception e) {
            fail("Exception while try to delete WAR via popup menu: " + e);
        }

	try {
            node1 = new WARNode(from2 + "|war4");
	} catch (Exception e) {
	    fail("war4 node was deleted via popup");
	    //PASS
        }

	
    }




    private void checkValid(String node) {
	try {
	    WARNode war = new WARNode(node);
	}catch(Exception e) {
	    fail("Valid war node (" + node + ")not found.  " + e);
	    e.printStackTrace();
	}
    }
    private void deleteYes() {
	String deleteTitle = Bundle.getStringTrimmed("org.openide.explorer.Bundle", "MSG_ConfirmDeleteObjectTitle");
	NbDialogOperator dialog = new NbDialogOperator(deleteTitle);
	dialog.yes();
    }
    private void deleteNo() {
	String deleteTitle = Bundle.getStringTrimmed("org.openide.explorer.Bundle", "MSG_ConfirmDeleteObjectTitle");
	NbDialogOperator dialog = new NbDialogOperator(deleteTitle);
	dialog.no();
    }

}
... 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.