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.JSPServletDebug;  

import java.io.File;
import java.awt.event.InputEvent;
import javax.swing.JPopupMenu;

import org.netbeans.junit.NbTestSuite; 
import org.netbeans.junit.NbTestCase; 
import junit.framework.Test;
import junit.framework.TestSuite;

import org.netbeans.jellytools.ExplorerOperator; 
import org.netbeans.jellytools.EditorOperator; 
import org.netbeans.jellytools.EditorWindowOperator; 
import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.MainWindowOperator;
import org.netbeans.jellytools.nodes.FilesystemNode;
import org.netbeans.jellytools.nodes.FormNode;

import org.netbeans.jellytools.actions.BuildAction;
import org.netbeans.jellytools.actions.CleanAction;
import org.netbeans.jellytools.actions.CompileAction;

import org.netbeans.jemmy.operators.JPopupMenuOperator;

import org.netbeans.web.test.actions.AddBreakpointAction;
import org.netbeans.web.test.actions.StopCompileAction;
import org.netbeans.web.test.actions.ToggleBreakpointAction;

import org.netbeans.web.test.util.Utils;
import org.netbeans.test.gui.web.util.CommonUtils;
import org.netbeans.test.gui.web.util.CompilationUtils;


/**
 * Collection of tests corresponding "Breakpoints in Uncompiled JSP" part of JSP/Servlet Debug specification.
 * @author Vladimir Strigun
 */
public class Uncompiled extends JellyTestCase { 

    private static ExplorerOperator explorer= null;
    private EditorOperator editor = null;
    private static String fileNameForBreakpoint1 = null;
    private static String fileNameForBreakpoint2 = null;
    private static String fileNameForBreakpoint3 = null;
    private static String fileNameForBreakpoint4 = null;
    private static String workDir = null;
    private static String webModule = null;
    private static String wmName = "wm";
    private static String testWMDir = "uncompiled";
    public static final String delim = "|";
    private String jsp1 = "jsp1";
    private String jsp2 = "jsp2";
    private String jsp3 = "jsp3";
    private String jsp4 = "jsp4";


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

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

    public static Test suite(){
        TestSuite suite = new NbTestSuite(Uncompiled.class);
	workDir = System.getProperty("jspservletdebug.workdir").replace('/', File.separatorChar);
	webModule = workDir + File.separatorChar + wmName;
        workDir = webModule+delim+testWMDir;
        explorer = ExplorerOperator.invoke();
        explorer.selectPageFilesystems();
        Utils.handleDialogAfterNewWebModule();
        fileNameForBreakpoint1 = testWMDir+"/"+"jsp1";
        fileNameForBreakpoint2 = testWMDir+"/"+"jsp2";
        fileNameForBreakpoint3 = testWMDir+"/"+"jsp3";
        fileNameForBreakpoint4 = testWMDir+"/"+"jsp4";

        return suite;
    }


    /** 
        Toggle breakpoint on via hotkey for "Toggle Breakpoint" 
    */

    public void testToogleBreakpointOnHotkey(){
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(3);
        (new ToggleBreakpointAction()).performShortcut(); 
        checkResultOfAddingBreakpoint(fileNameForBreakpoint1, 3, false);
    }

    /** 
        Toggle breakpoint off via hotkey for "Toggle Breakpoint" 
    */

    public void testToogleBreakpointOffHotkey(){
        CommonUtils.checkBreakpointExist(jsp1, fileNameForBreakpoint1, 3, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(3);
        (new ToggleBreakpointAction()).performShortcut(); 
        checkResultOfRemovingBreakpoint(fileNameForBreakpoint1, 3, false);
    }


    /** 
        Toggle breakpoint on via "Toggle Breakpoint" context menu item 
    */

    public void testToggleBreakpointOnContextMenu() {
        editor = Utils.openFile(workDir, jsp2);
        //Popup will be openedon 1st line
        editor.clickForPopup(100, 30);
        new JPopupMenuOperator().pushMenu("Toggle Breakpoint", "|");
        checkResultOfAddingBreakpoint(fileNameForBreakpoint2, 1, false);
    }


    /** 
        Toggle breakpoint off via "Toggle Breakpoint" context-menu item 
    */

    public void testToggleBreakpointOffContextMenu() {
        CommonUtils.checkBreakpointExist(jsp2, fileNameForBreakpoint2, 1, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp2);
        editor.clickForPopup(100, 30);
        new JPopupMenuOperator().pushMenu("Toggle Breakpoint", "|");
        checkResultOfRemovingBreakpoint(fileNameForBreakpoint2, 1, false);
    }

    /** 
        Toggle breakpoint on via one mouse click
    */

    public void testToggleBreakpointOnOneMouseClick() {
        editor = Utils.openFile(workDir, jsp4);
        editor.clickMouse(5, 30, 1, InputEvent.BUTTON1_MASK);
        checkResultOfAddingBreakpoint(fileNameForBreakpoint4, 1, false);
    }


    /** 
        Toggle breakpoint off via one mouse click
    */

    public void testToggleBreakpointOffOneMouseClick() {
        CommonUtils.checkBreakpointExist(jsp4, fileNameForBreakpoint4, 1, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp4);
        editor.clickMouse(5, 30, 1, InputEvent.BUTTON1_MASK);
        checkResultOfRemovingBreakpoint(fileNameForBreakpoint4, 1, false);
    }


    /** 
        Add breakpoint via main menu item 
    */

    public void testAddBreakpointMainMenu() {
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(9);
        (new AddBreakpointAction()).performMenu(); 
        Utils.fillAddBreakpointDialog(null, 0, ""); 
        checkResultOfAddingBreakpoint(fileNameForBreakpoint1, 9, false);
    } 

      
    /**
        Add breakpoint via hotkey for menu item 
    */

    public void testAddBreakpointHotkey() {
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(10);
        (new AddBreakpointAction()).performShortcut(); 
        Utils.fillAddBreakpointDialog(null, 0, "");
        checkResultOfAddingBreakpoint(fileNameForBreakpoint1, 10, false);
    }


    /** 
        Add breakpoint via to not current line 
    */

    public void testAddBreakpointToLine() {
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(1);
        (new AddBreakpointAction()).performMenu(); 
        Utils.fillAddBreakpointDialog(null, 6, "");
        checkResultOfAddingBreakpoint(fileNameForBreakpoint1, 6, false);
    }


    /** 
        Add breakpoint to not current file line via hotkey for menu item 
    */

    public void testAddBreakpointToFile() {
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(7);
        (new AddBreakpointAction()).performShortcut(); 
        Utils.fillAddBreakpointDialog(fileNameForBreakpoint2+".jsp", 7, "");
        checkResultOfAddingBreakpoint(fileNameForBreakpoint2, 7, false);
    }


    /** 
        Interrupt compilation of JSP file via "Stop compile" main menu item 
    */

    public void testStopCompilationMainMenu(){
        editor = Utils.openFile(workDir, jsp1);
        (new CompileAction()).performMenu();
        //wait(1000);
        (new StopCompileAction()).performMenu();
        //(new StopCompileAction()).performMenu();
        //(new StopCompileAction()).performMenu();
        wait(5000);
        checkStopCompilationSuccessful(jsp1);
    }


    /** 
        Interrupt compilation of JSP file via hotkey for "Stop compile" 
        main menu item
    */

    public void testStopCompilationHotkey(){
        editor = Utils.openFile(workDir, jsp2);
        (new CompileAction()).performMenu();
        //wait(2000);
        (new StopCompileAction()).performShortcut();
        //(new StopCompileAction()).performShortcut();
        //(new StopCompileAction()).performShortcut();
        checkStopCompilationSuccessful(jsp2);
    }


    /** 
        Compile JSP file with breakpoints via Compile main menu item 
    */

    public void testCompileMainMenu(){
        CommonUtils.checkBreakpointExist(jsp1, fileNameForBreakpoint1, 9, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp1);
        (new CompileAction()).performMenu();
        checkCompilationSuccessful(jsp1, 9, 68);
    }


    /** 
        Compile JSP file with breakpoints via hotkey Compile main menu item 
    */

    public void testCompileHotkeyMainMenu(){
        CommonUtils.checkBreakpointExist(jsp3, fileNameForBreakpoint3, 2, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp3);
        (new CompileAction()).performShortcut();
        checkCompilationSuccessful(jsp3, 2, 55);
    }


    /** 
        Compile JSP file with breakpoints via Compile contextual menu item 
    */ 

    public void testCompileContextMenu(){
        CommonUtils.checkBreakpointExist(jsp2, fileNameForBreakpoint2, 2, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp2);
        editor.clickForPopup();
        new JPopupMenuOperator().pushMenu("Compile", "|");
        checkCompilationSuccessful(jsp2, 2, 55);
    }


    /** 
        Build JSP file with breakpoints via Build main menu item 
    */

    public void testBuildMainMenu(){
        CommonUtils.checkBreakpointExist(jsp4, fileNameForBreakpoint4, 5, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp4);
        (new BuildAction()).performMenu();
        checkCompilationSuccessful(jsp4, 5, 58);
    }


    /** 
        Build JSP file with breakpoints via Build hotkey
    */

    public void testBuildHotkey(){
        editor = Utils.openFile(workDir, jsp4);
        (new CleanAction()).performMenu();
        CommonUtils.checkBreakpointExist(jsp4, fileNameForBreakpoint4, 9, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp4);
        (new BuildAction()).performShortcut();
        checkCompilationSuccessful(jsp4, 9, 68);
    }
    

    /*here is a part of service function to operate with dialogs, breakpoint, etc.*/

    private void checkResultOfAddingBreakpoint(String name, int line, boolean isDeferred){
        if(!CommonUtils.getPropertiesWindowForBreakpoint(name, line, isDeferred)){
            fail("Debugger do not add breakpoint for file "+name+" and line "+line);
        }
    }

    private void checkResultOfRemovingBreakpoint(String name, int line, boolean isDeferred){
        if(CommonUtils.getPropertiesWindowForBreakpoint(name, line, false)){
            fail("Debugger do not delete breakpoint for file "+name+" and line "+line);
        }
    }

    private void checkStopCompilationSuccessful(String name){
        if(!CommonUtils.isCompilationBreakSuccessful(name)) 
          fail("Aborting compilation isn't successful");
    }

    //should be corrected

    private void checkCompilationSuccessful(String name, int line, int servletLineNumber){
        String nameServlet = name;
        String res = CompilationUtils.checkResultOfJSPCompilation(workDir, name);
        if(res!=null){
            System.out.println("Compilation isn't successful and result is:"+res);
            fail("Compilation of file "+name+" isn't successful");
        }
        if(name.indexOf("/")!=-1){
            nameServlet = name.substring(name.indexOf(File.separatorChar)+1);
        }
        nameServlet = "org.apache.jsp."+nameServlet+"$jsp";
        //System.out.println("\n\nSVA DEBUG::nameservlet="+nameServlet+"\n\n");
        if(!CommonUtils.isServletBreakpointExist(testWMDir+"/"+name, nameServlet, line, servletLineNumber, false))
            fail("Debugger do not add servlet breakpoint for file "+name+"("+nameServlet+") for line"+line);
    } 

    private void wait(int millisec) {
        try {
            Thread.sleep(millisec);
        } catch(Exception e) {}
    }


    /** 
        Toggle breakpoint on via main menu "Toggle Breakpoint" item 
    *

    public void testToggleBreakpointOnMainMenu() {
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(2);
        (new ToggleBreakpointAction()).performMenu(); 
        checkResultOfAddingBreakpoint(fileNameForBreakpoint1, 2, false);
    }
    
    Test was removed because Toggle Breakpoint menu item was removed.
    */

    /** 
        Toggle breakpoint off via main menu "Toggle Breakpoint" item 
    *

    public void testToggleBreakpointOffMainMenu() {
        CommonUtils.checkBreakpointExist(jsp1, fileNameForBreakpoint1, 2, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(2);
        (new ToggleBreakpointAction()).performMenu(); 
        checkResultOfRemovingBreakpoint(fileNameForBreakpoint1, 2, false);
    }
    
    Test was removed because Toggle Breakpoint menu item was removed.
    */


    /** 
        Toggle breakpoint on via "Toggle Breakpoint" toolbar item 
    *

    public void testToggleBreakpointOnToolbar() {
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(6);
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Toggle Breakpoint").push();
        checkResultOfAddingBreakpoint(fileNameForBreakpoint1, 6, false);
    }
    Test was removed because Toggle Breakpoint menu item was removed.
    */


    /** 
        Toggle breakpoint off via "Toggle Breakpoint" toolbar item 
    *

    public void testToggleBreakpointOffToolbar() {
        CommonUtils.checkBreakpointExist(jsp1, fileNameForBreakpoint1, 6, 0, false, workDir);
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(6);
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Toggle Breakpoint").push();
        checkResultOfRemovingBreakpoint(fileNameForBreakpoint1, 6, false);
    }
    Test was removed because Toggle Breakpoint menu item was removed.
    */


    /**
        Add breakpoint via toolbar button
    *

    public void testAddBreakpointToolbar() {
        editor = Utils.openFile(workDir, jsp1);
        editor.setCaretPositionToLine(4);
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Add Breakpoint").push();
        Utils.fillAddBreakpointDialog(null, 0, "");
        checkResultOfAddingBreakpoint(fileNameForBreakpoint1, 4, false);
    }
    test was removed because "New breakpoint" button removed from toolbar
    */
} 





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