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

import org.netbeans.jemmy.operators.JPopupMenuOperator;

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

import org.netbeans.jellytools.actions.CompileAllAction;

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

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 Included JSP" part of JSP/Servlet Debug specification.
 * @author Vladimir Strigun
 */
public class Included extends NbTestCase { 

    private static String fileName = "mainjsp";
    private static String includedFileName = "included";
    public static final String delim = "|";
    private static String workDir = null;
    private static String tmpWebModule = null;
    private static String webModule = null;
    private static String wmName = "wm";
    private EditorOperator editor;
    private static ExplorerOperator explorer;

    private static String testWMDir = "included";
    private static String servletName1 = null;
    private static String fileNameForBreakpoint1 = null;
    private static String fileNameForBreakpoint2 = null;

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

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

    public static Test suite(){
        TestSuite suite = new NbTestSuite(Included.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();
        servletName1 = "org.apache.jsp."+fileName+"$jsp";
        fileNameForBreakpoint1 = testWMDir+"/"+fileName;
        fileNameForBreakpoint2 = testWMDir+"/"+includedFileName;
        FilesystemNode tmpNode = null;
        tmpNode = new FilesystemNode(workDir);
        FormNode fNode = new FormNode(tmpNode, fileName);
        (new CompileAllAction()).performMenu();
        String res = CompilationUtils.checkResultOfBuildAll(workDir, testWMDir);
        if(res!=null)
            System.out.println("FAILED: cannot compile all jsp's!!! "+res);
        return suite;
    }


    /** Toggle breakpoint on inside main jsp via hotkey for "Toggle Breakpoint" 
        item 
    */

    public void testToggleBreakpointOnMainMenu() {
        editor = Utils.openFile(workDir, fileName);
        editor.setCaretPositionToLine(3);
        (new ToggleBreakpointAction()).performShortcut(); 
        checkResultOfAddingBreakpoint(fileNameForBreakpoint1, servletName1, 3, 56, false);
    }


    /** Toggle breakpoint on inside included jsp via hotkey for "Toggle 
        Breakpoint"
    */

    public void testToggleBreakpointOnHotkey(){
        editor = Utils.openFile(workDir, includedFileName);
        editor.setCaretPositionToLine(3);
        (new ToggleBreakpointAction()).performShortcut(); 
        checkResultOfAddingBreakpoint(fileNameForBreakpoint2, servletName1, 3, 63, false);
    }


    /** Toggle breakpoint off inside main jsp via hotkey for  "Toggle 
        Breakpoint" item 
    */

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


    /** Toggle breakpoint off inside generated servlet via hotkey for 
        "Toggle Breakpoint" 
    */

    public void testToggleBreakpointOffServlet(){
        CommonUtils.checkBreakpointExist(includedFileName, fileNameForBreakpoint2, 3, 0, false, workDir);
        editor = Utils.openFile(workDir, includedFileName);
        editor.select(3, 1, 2);
        editor.clickForPopup();
        EditorWindowOperator editorWindow = new EditorWindowOperator(includedFileName);
        new JPopupMenuOperator().pushMenu("Show code in Servlet", "|");
        editor = new EditorOperator("Servlet for "+includedFileName);
        editor = new EditorOperator("Servlet for "+fileName);
        (new ToggleBreakpointAction()).performShortcut(); 
        checkResultOfRemovingServletBreakpoint(fileNameForBreakpoint2, servletName1, 3, 63, false);
    }


    /** 
        Add breakpoint to generated servlet via shotrcut
    */

    public void testAddBreakpointMainMenu() {
        editor = Utils.openFile(workDir, fileName);
        editor.clickForPopup();
        new JPopupMenuOperator().pushMenu("Show code in Servlet", "|");
        EditorWindowOperator editorWindow = new EditorWindowOperator("Servlet for "+fileName);
        editor = editorWindow.selectPage("Servlet for "+fileName);
        editor.setCaretPositionToLine(65);
        (new ToggleBreakpointAction()).performShortcut(); 
        checkResultOfAddingBreakpoint(fileNameForBreakpoint2, servletName1, 5, 65, true);
    } 

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

    private void checkResultOfRemovingServletBreakpoint(String name, String servletName, int line, int servletLineNumber, boolean isDeferred){
        if(!CommonUtils.getPropertiesWindowForBreakpoint(name, line, isDeferred)){
            fail("Debugger remove deferred breakpoint for file "+name+" and line "+line);
        }
        if(CommonUtils.isServletBreakpointExist(name, servletName, line, servletLineNumber, isDeferred)){
            fail("Debugger do not delete servlet breakpoint for servlet "+servletName+" and line"+ servletLineNumber);
        }
    }

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

} 





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