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.jellytools.EditorOperator; 
import org.netbeans.jellytools.ExplorerOperator; 

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

import org.netbeans.jellytools.actions.ActionNoBlock; 

import org.netbeans.web.test.actions.ContinueDebugAction;
import org.netbeans.web.test.actions.RunToCursorAction;

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


import org.netbeans.core.NbTopManager;


/**
 * Collection of tests corresponding "Global Options Setting" part of JSP/Servlet Debug specification.
 * @author Vladimir Strigun
 */
public class GlobalOptions extends NbTestCase { 

    private static String jsp1 = "jsp1";
    private static String jsp2 = "jsp2";
    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 = "global";

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

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

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


    /** 
        Debugging jsp file with "Skip static lines" option.
        Test sets "Skip static lines" option to true and start debugger.
        This test corresponds "Skip Static Lines - True" test from specification.
    */

    public void testSkipStaticLinesTrue() {
        Utils.deleteAllBreakpoints();
        CommonUtils.selectStaticLines(true);
        editor = Utils.openFile(workDir, jsp1); 
        editor.setCaretPositionToLine(3);
        (new RunToCursorAction()).performMenu();
        handleDialogsBeforeDebuggerStart();

         checkDebuggerStoppedOnBreakpoint(jsp1, 56);
         new ActionNoBlock("Debug|Step Over", null).perform();
         Utils.wait(3000);
         checkDebuggerStoppedOnLine(jsp1, 61);
         new ActionNoBlock("Debug|Step Over", null).perform();
         Utils.wait(3000);
         checkDebuggerStoppedOnLine(jsp1, 77);
         (new ContinueDebugAction()).performMenu();

        String res = CommonUtils.checkCorrectJSPOutput(jsp1, "Just a simple JSP file 1. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res); 
    }

    /**
        Changing Skip Static LInes property while debugging.
    */

    public void testSkipStaticChanging() {
        Utils.deleteAllBreakpoints();
        CommonUtils.selectStaticLines(false);
        editor = Utils.openFile(workDir, jsp2); 
        editor.setCaretPositionToLine(2);
        (new RunToCursorAction()).performMenu();
        handleDialogsBeforeDebuggerStart();

         checkDebuggerStoppedOnBreakpoint(jsp2, 55);
         new ActionNoBlock("Debug|Step Over", null).perform();
         Utils.wait(3000);
         checkDebuggerStoppedOnLine(jsp2, 56);
         new ActionNoBlock("Debug|Step Over", null).perform();
         Utils.wait(3000);
         checkDebuggerStoppedOnLine(jsp2, 57);
         CommonUtils.selectStaticLines(true);
         new ActionNoBlock("Debug|Step Over", null).perform();
         Utils.wait(3000);
         checkDebuggerStoppedOnLine(jsp2, 62);
         new ActionNoBlock("Debug|Step Over", null).perform();
         Utils.wait(3000);
         checkDebuggerStoppedOnLine(jsp2, 80);
         new ActionNoBlock("Debug|Step Over", null).perform();
         Utils.wait(3000);
         checkDebuggerStoppedOnLine(jsp2, 89);
         CommonUtils.selectStaticLines(false);
         new ActionNoBlock("Debug|Step Over", null).perform();
         Utils.wait(3000);
         checkDebuggerStoppedOnLine(jsp2, 92);
         new ActionNoBlock("Debug|Step Over", null).perform();
         Utils.wait(3000);
         checkDebuggerStoppedOnLine(jsp2, 93);
         (new ContinueDebugAction()).performMenu();

        String res = CommonUtils.checkCorrectJSPOutput(jsp2, "Just a simple JSP file 2. Test passed.", testWMDir);
        Utils.finishDebugger();
        if(res!=null) fail(res);
    }

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

    private void checkDebuggerStoppedOnLine(String name, int line){
         StatusWaitable csw = new StatusWaitable("Thread", "stopped at org.apache.jsp."+name+"$jsp._jspService line "+line+".");
         String result = Utils.waitDebuggerStop(csw);
         if(result!=null){
             System.out.println("Error while waiting of debugger stop: "+result);
             Utils.finishDebugger();
             fail("Debugger do not stopped on line "+line+".");
         }
    }

    private void checkDebuggerStoppedOnBreakpoint(String name, int line) {
        String result = CommonUtils.waitDebuggerStoppedOnBreakpoint(name, line);
        if(result!=null){
            System.out.println("Error while waiting of debugger stop: "+result);
            Utils.finishDebugger();
            fail("Debugger do not stopped on "+line+" in file "+name);
        }
    }

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





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