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 junit.framework.Test;
import junit.framework.TestSuite;
import org.netbeans.junit.NbTestSuite; 
import org.netbeans.junit.NbTestCase; 

import org.netbeans.jemmy.operators.DialogOperator;
import org.netbeans.jemmy.operators.JButtonOperator;
import org.netbeans.jemmy.operators.JComboBoxOperator;
import org.netbeans.jemmy.operators.JTextComponentOperator;

import org.netbeans.jellytools.Bundle;
import org.netbeans.jellytools.EditorOperator; 
import org.netbeans.jellytools.EditorWindowOperator; 
import org.netbeans.jellytools.ExplorerOperator; 
import org.netbeans.jellytools.MainWindowOperator; 
import org.netbeans.jellytools.NbFrameOperator;

import org.netbeans.jellytools.nodes.FilesystemNode;
import org.netbeans.jellytools.nodes.FormNode;

import org.netbeans.jellytools.actions.ActionNoBlock; 

import org.netbeans.web.test.actions.FinishDebugAction;
import org.netbeans.web.test.actions.PauseDebugAction;
import org.netbeans.web.test.actions.RunToCursorAction;
import org.netbeans.web.test.actions.StartDebugAction;
import org.netbeans.web.test.actions.StepIntoAction;
import org.netbeans.web.test.actions.StepOverAction;
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;
import org.netbeans.web.test.util.StatusWaitable;

import org.netbeans.core.NbTopManager;

/**
 * Collection of tests corresponding "Debugging Process" part of JSP/Servlet Debug specification.
 * @author Vladimir Strigun
 */
public class Debugging extends NbTestCase { 

    private static String jsp1 = "jsp1";
    private static String jsp2 = "jsp2";
    private static String jsp3 = "jsp3";
    private static String jsp4 = "jsp4";
    private static String jsp5 = "jsp5";
    private static String jsp6 = "jsp6";
    private static String jsp7 = "jsp7";
    private static String jsp8 = "jsp8";
    private static String jsp9 = "jsp9";
    private static String jsp10 = "jsp10";
    private static String jsp11 = "jsp11";
    private static String jsp12 = "jsp12";
    private static String jsp13 = "jsp13";
    private static String jsp14 = "jsp14";
    private static String jsp15 = "jsp15";
    private static String includedFileName = "included";
    private static String javaIncluded = "JavaIncluded";
    private static String includingFileName = "mainjsp";
    private EditorOperator editor  = null;

    public static final String delim = "|";
    private static boolean informDialogsAlreadyOpened = false;
    private static boolean compilationDialogAlreadyOpened = false;
    private static String workDir = null;
    private static String webModule = null;
    private static String wmName = "wm";
    private static ExplorerOperator explorer = null;

    private static String testWMDir = "debugging";

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

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

    public static Test suite(){
        TestSuite suite = new NbTestSuite(Debugging.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();
        //CommonUtils.setCompileJSPsBeforeDebug(0);
        Utils.setSwingBrowser();
        return suite;
    }


    /** Starting debugger with compilation errors ("Start 
        Debugger with Compilation Errors" test on specification )
    */

    public void testStartDebuggerCompilationErrors() {
        editor = Utils.openFile(workDir, jsp1); 
        (new StartDebugAction()).performMenu(); 
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(jsp1, true);
        String res = CommonUtils.checkCorrectJSPOutput(jsp1, "", testWMDir);
        finishDebugger();
        if(res!=null) fail(res);
    }


    /** Starting debugger without compilation errors ("Start 
        Debugger with No Error" test on specification )
    */

    public void testStartDebuggerMainMenu() {
        editor = Utils.openFile(workDir, jsp2); 
        (new StartDebugAction()).performMenu(); 
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(jsp2, false);
        String res = CommonUtils.checkCorrectJSPOutput(jsp2, "Just a simple JSP file 2. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }


    /** Starting debugger without compilation errors toolbar button ("Start 
        Debugger with No Error" test on specification )
    */

    public void testStartDebuggerToolbar() {
        editor = Utils.openFile(workDir, jsp3); 
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Run in Debugger").push();
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(jsp3, false);
        String res = CommonUtils.checkCorrectJSPOutput(jsp3, "Just a simple JSP file 3. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }


    /** Starting debugger without compilation errors ("Start 
        Debugger with No Error" test on specification )
    */

    public void testStartDebuggerShortcut() {
        editor = Utils.openFile(workDir, jsp4); 
        (new StartDebugAction()).performShortcut(); 
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(jsp4, false);
        String res = CommonUtils.checkCorrectJSPOutput(jsp4, "Just a simple JSP file 4. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }   
    

    /** 
        "Stop on Breakpoints" test on specification.
    */

    public void testStopOnBreakpoint() {
        int[] breakpointsLines = {3, 9};
        editor = Utils.openFile(workDir, jsp5);
        addBreakpointsIfNotExist(jsp5, breakpointsLines, false);
        int[] breakpointsLines1 = {56, 68};
        (new StartDebugAction()).performShortcut(); 
        checkDebuggerStoppedOnAllBreakpoints(jsp5, breakpointsLines1);
        String res = CommonUtils.checkCorrectJSPOutput(jsp5, "Just a simple JSP file 5. Test passed.", testWMDir);
        try{
            Utils.finishDebugger();
        } catch(org.netbeans.jemmy.TimeoutExpiredException timeEx) {
             System.out.println("Catched TimeoutExpiredException when trying to finish debugger. May be correct???");
             timeEx.printStackTrace();
        }
        if(res!=null) fail(res);
    }


    /** Debugging with included JSP. Test added breakpoint to including 
        and included JSP and starting debugging session.
        "Debugging with Included JSPs" test on specification.
    */

    public void testDebuggingWithIncludedJSP() {
        int[] breakpointsLines = {3, 5, 11};
        editor = Utils.openFile(workDir, includingFileName);
        addBreakpointsIfNotExist(includingFileName, breakpointsLines, false);
        int[] breakpointsLines1 = {6, 15};
        addBreakpointsIfNotExist(includedFileName, breakpointsLines1, false);
        int[] breakpointsLines2 = {56, 58, 66, 75, 92};
        editor = Utils.openFile(workDir, includingFileName);
        (new StartDebugAction()).performShortcut(); 
        checkDebuggerStoppedOnAllBreakpoints(includingFileName, breakpointsLines2);
        String res = CommonUtils.checkCorrectJSPOutput(includingFileName, "1st column, 1st row", testWMDir);
        try{
            Utils.finishDebugger();
        } catch(org.netbeans.jemmy.TimeoutExpiredException timeEx) {
            System.out.println("Catched TimeoutExpiredException when trying to finish debugger. May be correct???");
             timeEx.printStackTrace();
        } 
        if(res!=null) fail(res);
    }


    /** 
        Starting debugger via "Run to cursor" menu item.
    */

    public void testRunToCursorMainMenu() {
        editor = Utils.openFile(workDir, jsp6);
        editor.setCaretPositionToLine(4);
        (new RunToCursorAction()).performMenu();
        checkDebuggerStoppedOnAllBreakpoints(jsp6, new int[] {57});
        String res = CommonUtils.checkCorrectJSPOutput(jsp6, "Just a simple JSP file 6. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }


    /** 
        Starting debugger via shourtcut for "Run to cursor" menu item.
    */

    public void testRunToCursorShortcut() {
        editor = Utils.openFile(workDir, jsp7);
        editor.setCaretPositionToLine(4);
        (new RunToCursorAction()).performShortcut();
        checkDebuggerStoppedOnAllBreakpoints(jsp7, new int[] {57});
        String res = CommonUtils.checkCorrectJSPOutput(jsp7, "Just a simple JSP file 7. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }


    /** 
        Starting debugger via "Run to cursor" toolbar button.
    */

    public void testRunToCursorToolbar() {
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.switchToDebuggingWorkspace();
        editor = Utils.openFile(workDir, jsp8);
        editor.setCaretPositionToLine(4);
        mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Run to Cursor").push();
        checkDebuggerStoppedOnAllBreakpoints(jsp8, new int[] {57});
        String res = CommonUtils.checkCorrectJSPOutput(jsp8, "Just a simple JSP file 8. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }


    /** 
        Starting debugger via "Step Into" main menu item.
    */

    public void testStepIntoMainMenu() {
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.switchToDebuggingWorkspace();
        editor = Utils.openFile(workDir, jsp9);
        editor.setCaretPositionToLine(4);
        (new StepIntoAction()).performMenu();
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(jsp9, false);
        String res = CommonUtils.checkCorrectJSPOutput(jsp9, "Just a simple JSP file 9. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }


    /** 
        Starting debugger via "Step Into" toolbar button.
    */

    public void testStepIntoToolbar() {
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.switchToDebuggingWorkspace();
        addBreakpointsIfNotExist(jsp10, new int[] {4}, false);
        editor = Utils.openFile(workDir, jsp10);
        editor.setCaretPositionToLine(4);
        mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Step Into").push();
        checkDebuggerStoppedOnAllBreakpoints(jsp10, new int[] {57});
        String res = CommonUtils.checkCorrectJSPOutput(jsp10, "Just a simple JSP file 10. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }


    /** 
        Starting debugger via hotkey for "Step Into" menu item.
    */

    public void testStepIntoShortcut() {
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.switchToDebuggingWorkspace();
        addBreakpointsIfNotExist(jsp11, new int[] {4}, false);
        editor = Utils.openFile(workDir, jsp11);
        editor.setCaretPositionToLine(4);
        (new StepIntoAction()).performShortcut();
        checkDebuggerStoppedOnAllBreakpoints(jsp11, new int[] {57});
        String res = CommonUtils.checkCorrectJSPOutput(jsp11, "Just a simple JSP file 11. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }
    
    /** 
        Stepping inside JSP file via "Run to cursor" action.
    */

    public void testSteppingViaRunToCursorAction() {
        editor = Utils.openFile(workDir, jsp12);
        editor.setCaretPositionToLine(2);
        (new RunToCursorAction()).performMenu();
        handleDialogsBeforeDebuggerStart();
        checkDebuggerStoppedOnBreakpoint(jsp12, 55);
        editor = Utils.openFile(workDir, jsp12);
        editor.setCaretPositionToLine(4);
        (new RunToCursorAction()).performMenu();
        checkDebuggerStoppedOnBreakpoint(jsp12, 57);
        editor = Utils.openFile(workDir, jsp12);
        editor.setCaretPositionToLine(8);
        (new RunToCursorAction()).performMenu();
        checkDebuggerStoppedOnBreakpoint(jsp12, 67);
        editor = Utils.openFile(workDir, jsp12);
        editor.setCaretPositionToLine(10);
        (new RunToCursorAction()).performMenu();
        checkDebuggerStoppedOnBreakpoint(jsp12, 69);
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.switchToDebuggingWorkspace();
        new ActionNoBlock("Debug|Continue", null).perform();
        String res = CommonUtils.checkCorrectJSPOutput(jsp12, "Just a simple JSP file 12. Test passed.", testWMDir);
        finishDebugger();
        if(res!=null) fail(res);
    }

    /** 
        Run to cursor after debugger pause.
    */

    public void testRunToCursorAfterPause() {
        editor = Utils.openFile(workDir, jsp15);
        editor.setCaretPositionToLine(2);
        (new StartDebugAction()).performMenu(); 
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(jsp15, false);
        String res = CommonUtils.checkCorrectJSPOutput(jsp15, "Just a simple JSP file 15. Test passed.", testWMDir);
        (new PauseDebugAction()).performMenu();
        editor = Utils.openFile(workDir, jsp15);
        editor.setCaretPositionToLine(4);
        (new RunToCursorAction()).performMenu();
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.switchToDebuggingWorkspace();
        CommonUtils.pressRefreshInBrowser();
        checkDebuggerStoppedOnBreakpoint(jsp15, 57);
        new ActionNoBlock("Debug|Continue", null).perform();
        res = CommonUtils.checkCorrectJSPOutput(jsp15, "Just a simple JSP file 15. Test passed.", testWMDir);
        finishDebugger();
        if(res!=null) fail(res);
    }

    /**
        Pause debug action (menu item)
    */

    public void testPauseDebugMenu() {
        editor = Utils.openFile(workDir, jsp13);
        editor.setCaretPositionToLine(2);
        (new StartDebugAction()).performMenu(); 
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(jsp13, false);
        String res = CommonUtils.checkCorrectJSPOutput(jsp13, "Just a simple JSP file 13. Test passed.", testWMDir);
        (new PauseDebugAction()).performMenu();
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        Utils.wait(2000);
        if(! (mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Continue").isEnabled()
           & mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Step Into").isEnabled()
           & mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Step Over").isEnabled()
           & mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Step Out").isEnabled())
        ){
            finishDebugger();
            fail("Some of item is disabled!!!!");
        }
        finishDebugger();
    }

    /**
        Pause debug action (toolbar button)
    */

    public void testPauseDebugToolbar() {
        editor = Utils.openFile(workDir, jsp14);
        editor.setCaretPositionToLine(2);
        (new StartDebugAction()).performMenu(); 
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(jsp14, false);
        String res = CommonUtils.checkCorrectJSPOutput(jsp14, "Just a simple JSP file 14. Test passed.", testWMDir);
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Pause").push();
        Utils.wait(2000);
        if(! (mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Continue").isEnabled()
           & mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Step Into").isEnabled()
           & mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Step Over").isEnabled()
           & mainWindow.getToolbarButton(mainWindow.getToolbar("Debug"), "Step Out").isEnabled())
        ){
            finishDebugger();
            fail("Some of item is disabled!!!!");
        }
        finishDebugger();
    }


    /**
        Debugging JSP file including method of thread start
    */

    public void testDebugWithJavaInside() {
        editor = Utils.openFile(webModule+"|WEB-INF|classes|OC", "OtherClass");
        editor.setCaretPositionToLine(13);
        new ActionNoBlock("Build|Build", null).perform();
        editor = Utils.openFile(workDir, javaIncluded);
        editor.setCaretPositionToLine(7);
        (new RunToCursorAction()).performMenu();
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(javaIncluded, false);
        checkDebuggerStoppedOnBreakpoint(javaIncluded, 75);
        editor = Utils.openFile(workDir, javaIncluded);
        editor.setCaretPositionToLine(16);
        (new RunToCursorAction()).performMenu();
        checkDebuggerStoppedOnBreakpoint(javaIncluded, 90);
        (new StepOverAction()).performMenu();
        checkDebuggerStoppedOnThread("org.apache.jsp.JavaIncluded$jsp._jspService", 91);
        (new StepOverAction()).performMenu();
        checkDebuggerStoppedOnThread("org.apache.jsp.JavaIncluded$jsp._jspService", 95);
        (new StepIntoAction()).performMenu();
        checkDebuggerStoppedOnThread("org.apache.jsp.JavaIncluded$jsp.startTest", 15);
        System.out.println("SVA DEBUG:: try to open"+workDir+"|WEB-INF|classes|OC");
        editor = Utils.openFile(webModule+"|WEB-INF|classes|OC", "OtherClass");
        editor.setCaretPositionToLine(13);
        (new RunToCursorAction()).performMenu();
        checkDebuggerStoppedOnThread("OC.OtherClass.start", 13);
        for(int i=1; i<7 ; i++){
            (new StepOverAction()).performMenu();
            checkDebuggerStoppedOnThread("OC.OtherClass.start", i+13);
        }
        MainWindowOperator mainWindow = MainWindowOperator.getDefault();
        mainWindow.switchToDebuggingWorkspace();
        (new StepOverAction()).performMenu();
        checkDebuggerStoppedOnThread("OC.OtherClass.start", 12);
        new ActionNoBlock("Debug|Continue", null).perform();
        String res = CommonUtils.checkCorrectJSPOutput(javaIncluded, "Expected result: no any problems during debugging proccess", testWMDir);
        finishDebugger();
        if(res!=null) fail(res);
    }
    


    /* Some service function needed only for current class. */

    private void handleDialogsBeforeDebuggerStart(){
        if(!compilationDialogAlreadyOpened) {
            String res = CommonUtils.handleJSPCompilationDialog();
            if(res!=null){ 
                if(res.indexOf("not opened")==-1) fail(res);
            }else{
                compilationDialogAlreadyOpened = true;
            }
        }
        if(!informDialogsAlreadyOpened){
            String res = CommonUtils.handleDialogsBeforeDebuggerStart();
            if(res!=null){ 
                if(res.indexOf("not opened")==-1) fail(res);
            }else{
                informDialogsAlreadyOpened = true;
            }
        }
    }

    private void checkDebuggerStoppedOnAllBreakpoints(String name, int[] lines) {
        handleDialogsBeforeDebuggerStart();
        checkErrorWhileStartDebugging(name, false);
        for(int i=0; i
... 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.