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

package gui.action;

import org.netbeans.jellytools.EditorOperator;
import org.netbeans.jellytools.ProjectsTabOperator;
import org.netbeans.jellytools.nodes.Node;

import org.netbeans.jemmy.operators.ComponentOperator;
import org.netbeans.jemmy.operators.JPopupMenuOperator;

/**
 * Test of opening files.
 *
 * @author  mmirilovic@netbeans.org
 */
public class OpenWebFiles extends testUtilities.PerformanceTestCase {
    
    /** Node to be opened/edited */
    public static Node openNode ;
    
    /** Folder with data */
    public static String fileProject;
 
    /** Folder with data  */
    public static String fileFolder;
    
    /** Name of file to open */
    public static String fileName;
    
    /** Menu item name that opens the editor */
    public static String menuItem;
    
    protected static String OPEN = "Open"; //NOI18N
    
    protected static String EDIT = "Edit"; //NOI18N
    
    protected static String WEB_PAGES = "Web Pages"; //NOI18N
    
    /**
     * Creates a new instance of OpenFiles
     * @param testName the name of the test
     */
    public OpenWebFiles(String testName) {
        super(testName);
        expectedTime = WINDOW_OPEN;
    }
    
    /**
     * Creates a new instance of OpenFiles
     * @param testName the name of the test
     * @param performanceDataName measured values will be saved under this name
     */
    public OpenWebFiles(String testName, String performanceDataName) {
        super(testName, performanceDataName);
        expectedTime = WINDOW_OPEN;
    }
    
    public void testOpeningWebXmlFile(){
        WAIT_AFTER_OPEN = 3000;
        setPaintFilteringForEditor();
        setXMLEditorCaretFilteringOn();
        fileProject = "TestWebProject";
        fileFolder = "WEB-INF"; 
        fileName = "web.xml";
        menuItem = EDIT;
        doMeasurement();
    }

    public void testOpeningJSPFile(){
        WAIT_AFTER_OPEN = 3000;
        setPaintFilteringForEditor();
        setXMLEditorCaretFilteringOn();
        fileProject = "TestWebProject";
        fileFolder = "";
        fileName = "Test.jsp";
        menuItem = OPEN;
        doMeasurement();
    }

    public void testOpeningHTMLFile(){
        WAIT_AFTER_OPEN = 3000;
        setPaintFilteringForEditor();
        setXMLEditorCaretFilteringOn();
        fileProject = "TestWebProject";
        fileFolder = "";
        fileName = "HTML.html";
        menuItem = OPEN;
        doMeasurement();
    }

    public void testOpeningTagFile(){
        WAIT_AFTER_OPEN = 3000;
        setPaintFilteringForEditor();
        setXMLEditorCaretFilteringOn();
        fileProject = "TestWebProject";
        fileFolder = "WEB-INF|tags"; 
        fileName = "mytag.tag";
        menuItem = OPEN;
        doMeasurement();
    }

    public void testOpeningTldFile(){
        WAIT_AFTER_OPEN = 3000;
        setPaintFilteringForEditor();
        setXMLEditorCaretFilteringOn();
        fileProject = "TestWebProject";
        fileFolder = "WEB-INF"; 
        fileName = "MyTLD.tld";
        menuItem = OPEN;
        doMeasurement();
    }
    
    public void initialize(){
        EditorOperator.closeDiscardAll();
    }

    public void shutdown(){
        EditorOperator.closeDiscardAll();
    }
    
    public void prepare(){
        System.out.println("PREPARE: "+WEB_PAGES + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName);
        this.openNode = new Node(new ProjectsTabOperator().getProjectRootNode(fileProject),WEB_PAGES + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName);
        
        if (this.openNode == null) {
            fail ("Cannot find node ["+WEB_PAGES  + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName + "] in project [" + fileProject + "]");
        }
        log("========== Open file path ="+this.openNode.getPath());
    }
    
    public ComponentOperator open(){
        JPopupMenuOperator popup =  this.openNode.callPopup();
        if (popup == null) {
            fail ("Cannot get context menu for node ["+WEB_PAGES + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName + "] in project [" + fileProject + "]");
        }
        log("------------------------- after popup invocation ------------");
        try {
            popup.pushMenu(this.menuItem);
        }
        catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
            fail ("Cannot push menu item "+this.menuItem+" of node ["+WEB_PAGES  + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName + "] in project [" + fileProject + "]");
        }
        log("------------------------- after open ------------");
        return new EditorOperator(this.fileName);
    }
    
    public void close(){
        if (testedComponentOperator != null) {
            ((EditorOperator)testedComponentOperator).closeDiscard();
        }
        else {
            fail ("no component to close");
        }
    }
    
}
... 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.