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

/*
 * Tests for JSP Compilation
*/

package org.netbeans.test.gui.web.JSP_Compilation_and_Execution;

import org.netbeans.junit.NbTestSuite; 
import org.netbeans.junit.NbTestCase; 

import java.awt.Robot;
import java.awt.event.*;

import org.netbeans.jellytools.*;
import org.netbeans.jellytools.nodes.*;
import org.netbeans.jellytools.actions.*;
import org.netbeans.jellytools.properties.*;
import org.netbeans.jemmy.*;
import org.netbeans.jemmy.operators.*;

public class JSP_Compilation extends NbTestCase { 

	String workDir=null;
	ExplorerOperator explorer=null;
	private String delim="|";	// NOI18N
	EditorOperator editor= null;
	private static boolean mwm=true;
	private JavaNode node=null;
	private NbDialogOperator dop=null;
	private String value=null;
	String serverType = "no server";	// NOI18N
	String serverName = "no server";	// NOI18N
	String serverHost = "no server";	// NOI18N


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

    /** Use for execution inside IDE */ 
    public static void main(java.lang.String[] args) { 
        junit.textui.TestRunner.run(new NbTestSuite(JSP_Compilation.class)); 
    } 

    public void setUp() { 

	serverType=System.getProperty("serverType");
	serverName=System.getProperty("serverName");
	serverHost=System.getProperty("serverHost");

	String fSep = System.getProperty("file.separator");	// NOI18N
	workDir = (java.lang.System.getProperty("jsptests.workdir")+"/testSystem").replace('/',fSep.charAt(0));	// NOI18N

	if(mwm) {

		mwm=false;

		try {
			dop=new NbDialogOperator(org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.web.context.Bundle", "CTL_TITLE"));
			dop.close();
			dop=new NbDialogOperator(org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.web.context.Bundle", "CTL_TITLE"));
			dop.close();
		} catch(Exception e) {
			System.out.println(org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.web.context.Bundle", "CTL_TITLE")+" dialog not found");
		}

//		String tc=path+" [Not running]"+delim+host+":"+port;
//		tc=tc.replace('/',fSep.charAt(0));

		explorer = ExplorerOperator.invoke();
		explorer.selectPageRuntime();
		try {
			Node node=new Node(new RuntimeTabOperator().tree(),"Server Registry"+delim+"Installed Servers"+delim+serverType+delim+serverName+delim+serverHost);
			new ActionNoBlock(null,"Set As Default").performPopup(node);
		}catch(Exception e) {
			fail("Default server is not found");
		}
	}

	explorer = ExplorerOperator.invoke();
        explorer.selectPageFilesystems();
    }

    private JavaNode getNode(String path) {

	try {
		node=new JavaNode(workDir+delim+path);
	}catch(Exception e) {
		fail(path+" is not found");
	}
	return node;
    }

    private void checkDialog(String name) {

	try {
		dop=new NbDialogOperator(name);
	} catch(Exception ex) {
		fail("No '"+name+"' dialog appears");
	}
	dop.close();
    }

    private void waitFor(int ms) {
//  On W2k k=1, on Solaris/Linux it's better to set k=2-3
	int k=2;
        new EventTool().waitNoEvent(ms*k);
    }


//1 Compile simple JSP in default package via popup menu 
    public void test_JSP_in_defpkg_via_popup() {

	node=getNode("SimpleJSPpopup");		// NOI18N
	new CompileAction().performPopup(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("SimpleJSPpopup");	// NOI18N
	if (!editor.contains("public class SimpleJSPpopup"))	// NOI18N
		 fail("Invalid servlet content.");
	editor.close();
    }

//2 Compile simple JSP in default package via F9 shortcut
    public void test_JSP_in_defpkg_via_F9() {

	node=getNode("SimpleJSPf9");	// NOI18N	
	new CompileAction().performShortcut(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("SimpleJSPf9");	// NOI18N
	if (!editor.contains("public class SimpleJSPf9"))	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//3 Compile simple JSP in default package via main menu
    public void test_JSP_in_defpkg_via_main() {
	
	node=getNode("SimpleJSPmain");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("SimpleJSPmain");	// NOI18N
	if (!editor.contains("public class SimpleJSPmain")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//4  Compile simple JSP in non default package via main menu
    public void test_JSP_in_nondefpkg() {

	node=getNode("jsps"+delim+"simple"+delim+"TestJSP");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("TestJSP");	// NOI18N
	if (!editor.contains("public class TestJSP"))	// NOI18N
		 fail("Invalid servlet content.");
	editor.close();
    }

//5  Compile JSP returning some (404) error code
    public void test_JSP_with_404_error() {

	node=getNode("jsps"+delim+"errors"+delim+"ErrorPage");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("ErrorPage");	// NOI18N
	if (!editor.contains("public class ErrorPage")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//6   Compile JSP throwing some exception;
    public void test_JSP_with_exception() {
	

	node=getNode("jsps"+delim+"errors"+delim+"Exception");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Exception");	// NOI18N
	if (!editor.contains("public class Exception")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//7  Compile JSP redirecting to another JSP
    public void test_JSP_with_redirect() {

	node=getNode("jsps"+delim+"jsp"+delim+"Redirect");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Redirect");	// NOI18N
	if (!editor.contains("public class Redirect")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//8  Compile JSP including another JSPs
    public void test_JSP_including_JSP() {

	node=getNode("jsps"+delim+"jsp"+delim+"Include");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Include");	// NOI18N
	if (!editor.contains("public class Include")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//9  Compile JSP with nonempty request parameters
    public void test_JSP_with_request_parameters() {

	node=getNode("jsps"+delim+"param"+delim+"Request");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Request");	// NOI18N
	if (!editor.contains("public class Request")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//10  Compile JSP using initial parameter
    public void test_JSP_with_initial_parameters() {

	node=getNode("jsps"+delim+"param"+delim+"Initial");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Initial");	// NOI18N
	if (!editor.contains("public class Initial")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//11  Compile JSP using context paramter 
    public void test_JSP_with_context_parameters() {

	node=getNode("jsps"+delim+"param"+delim+"Context");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Context");	// NOI18N
	if (!editor.contains("public class Context")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//12  Compile JSP using Environment Entry reference
    public void test_JSP_with_Environment_Entry_reference() {

	node=getNode("jsps"+delim+"refs"+delim+"EnvEntryRef");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("EnvEntryRef");	// NOI18N
	if (!editor.contains("public class EnvEntryRef")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//13  Compile JSP using Resource reference
    public void test_JSP_with_Resource_reference() {

	node=getNode("jsps"+delim+"refs"+delim+"ResourceRef");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("ResourceRef");	// NOI18N
	if (!editor.contains("public class ResourceRef")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//14  Compile JSP with fixed URL pattern mapping
    public void test_JSP_with_fixed_URL_pattern_map() {

	node=getNode("jsps"+delim+"map"+delim+"FixedMapping");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("FixedMapping");	// NOI18N
	if (!editor.contains("public class FixedMapping")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//15  Compile JSP with non-fixed (using '*') URL pattern mapping
    public void test_JSP_with_non_fixed_URL_pattern_map() {

	node=getNode("jsps"+delim+"map"+delim+"Path");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Path");	// NOI18N
	if (!editor.contains("public class Path")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//16  Compile JSP after Copy(Cut)-Paste (as copy) operation
    public void test_JSP_after_Copy_Paste() {

	node=getNode("jsps"+delim+"CopyPaste");		// NOI18N
	new CopyAction().performMenu(node);
	waitFor(1000);
	node=getNode("jsps"+delim+"simple");		// NOI18N
	new PasteCopyAction().performMenu(node);
	waitFor(5000);

	node=getNode("jsps"+delim+"simple"+delim+"CopyPaste");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("CopyPaste");	// NOI18N
	if (!editor.contains("public class CopyPaste")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//17  Compile JSP after Copy(Cut)-Paste (as link) operation
    public void test_JSP_after_Copy_Paste_link() {

	node=getNode("jsps"+delim+"CopyPasteLink");		// NOI18N
	new CopyAction().performMenu(node);
	waitFor(1000);
	node=getNode("jsps"+delim+"simple");		// NOI18N
	new PasteLinkAction().performMenu(node);
	waitFor(5000);

	node=getNode("jsps"+delim+"simple"+delim+"CopyPasteLink");	// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("CopyPasteLink");	// NOI18N
	if (!editor.contains("public class CopyPasteLink")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

// S1S test
//18 "Show code in JSP" action
    public void test_Show_code_in_JSP() {

	node=getNode("ShowCode");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Servlet for ShowCode");	// NOI18N
	editor.setCaretPosition("out.write(\"Test test_Show_code_in_JSP() Passed\\r\\n\");",true);	// NOI18N
	waitFor(5000);

	new org.netbeans.jellytools.actions.Action(null,"Show code in JSP").performPopup(editor);
	waitFor(3000);

	editor=ewo.getEditor();

	if (!(editor.getText(editor.getLineNumber()-1).trim().equals("Test test_Show_code_in_JSP() Passed"))) 	// NOI18N
		fail("Invalid line mapping.");
	editor.close();
    }

//19  Compile simple JSP with internal compiler
    public void test_Compile_with_internal() {

	node=getNode("jsps"+delim+"compilers"+delim+"Internal");	// NOI18N

	new PropertiesAction().perform(node);
        PropertySheetOperator pw = new PropertySheetOperator(PropertySheetOperator.MODE_PROPERTIES_OF_ONE_OBJECT,"Internal");
        PropertySheetTabOperator psto = pw.getPropertySheetTabOperator("Execution");
	ComboBoxProperty cb=new ComboBoxProperty(psto, "Servlet Compiler");

	cb.setValue("Internal Compilation");
	pw.close();

	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Internal");	// NOI18N
	if (!editor.contains("public class Internal")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//20  Compile simple JSP with external compiler
    public void test_Compile_with_external() {

	node=getNode("jsps"+delim+"compilers"+delim+"External");	// NOI18N

	new PropertiesAction().perform(node);
        PropertySheetOperator pw = new PropertySheetOperator(PropertySheetOperator.MODE_PROPERTIES_OF_ONE_OBJECT,"External");
        PropertySheetTabOperator psto = pw.getPropertySheetTabOperator("Execution");
	ComboBoxProperty cb=new ComboBoxProperty(psto, "Servlet Compiler");

	cb.setValue("External Compilation");
	pw.close();

	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("External");	// NOI18N
	if (!editor.contains("public class External")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//21  Compile simple JSP with fastjavac compiler
    public void test_Compile_with_fastjavac() {

	node=getNode("jsps"+delim+"compilers"+delim+"Fastjavac");	// NOI18N

	new PropertiesAction().perform(node);
        PropertySheetOperator pw = new PropertySheetOperator(PropertySheetOperator.MODE_PROPERTIES_OF_ONE_OBJECT,"Fastjavac");
        PropertySheetTabOperator psto = pw.getPropertySheetTabOperator("Execution");
	ComboBoxProperty cb=new ComboBoxProperty(psto, "Servlet Compiler");

	cb.setValue("Fastjavac Compilation");
	pw.close();

	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Fastjavac");	// NOI18N
	if (!editor.contains("public class Fastjavac")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//22  Compile simple JSP with (don't compile) option
    public void test_Compile_with_dont_compile() {

	node=getNode("jsps"+delim+"compilers"+delim+"DontCompile");	// NOI18N

	new PropertiesAction().perform(node);
        PropertySheetOperator pw = new PropertySheetOperator(PropertySheetOperator.MODE_PROPERTIES_OF_ONE_OBJECT,"DontCompile");
        PropertySheetTabOperator psto = pw.getPropertySheetTabOperator("Execution");
	ComboBoxProperty cb=new ComboBoxProperty(psto, "Servlet Compiler");

	cb.setValue("(do not compile)");
	pw.close();

	try {
		new CompileAction().performMenu(node);
		waitFor(5000);
		new ViewAction().performPopup(node);
		waitFor(5000);
        } catch (org.netbeans.jemmy.TimeoutExpiredException e) {
			
	}

	try {
	        EditorWindowOperator ewo = new EditorWindowOperator();
	        EditorOperator editor = ewo.getEditor("DontCompile");	// NOI18N
		if (editor.contains("public class DontCompile")) 	// NOI18N
			fail("Servlet was created.");
		editor.close();
	} catch (Exception e) {

	}
    }

//23  Compile JSP with extension (using '*.') pattern mapping
    public void test_JSP_with_extension_pattern_map() {

	node=getNode("jsps"+delim+"map"+delim+"Extension");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("Extension");	// NOI18N
	if (!editor.contains("public class Extension")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//24 Compile JSP using packed bean class 
    public void test_JSP_with_packed_bean() {

	node=getNode("jsps"+delim+"beans"+delim+"xPackedBean");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("xPackedBean");	// NOI18N
	if (!editor.contains("public class xPackedBean")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//25 Compile JSP using nonpacked bean class 
    public void test_JSP_with_non_packed_bean() {

	node=getNode("jsps"+delim+"beans"+delim+"NonPackedBean");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("NonPackedBean");	// NOI18N
	if (!editor.contains("public class NonPackedBean")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }


//26 Compile JSP using packed tag library 
    public void test_JSP_with_packed_taglib() {

	node=getNode("jsps"+delim+"taglibs"+delim+"xPackedTagLib");	// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("xPackedTagLib");	// NOI18N
	if (!editor.contains("public class xPackedTagLib")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//27 Compile JSP using nonpacked tag library 
    public void test_JSP_with_non_packed_taglib() {

	node=getNode("jsps"+delim+"taglibs"+delim+"NonPackedTagLib");		// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("NonPackedTagLib");	// NOI18N
	if (!editor.contains("public class NonPackedTagLib")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.close();
    }

//28 Compile JSP with Context Root web module property set to non-empty value
    public void test_JSP_with_non_empty_CR() {

	node=getNode("WEB-INF");	// NOI18N

	new PropertiesAction().perform(node);
        PropertySheetOperator pw = new PropertySheetOperator(PropertySheetOperator.MODE_PROPERTIES_OF_ONE_OBJECT,"WEB-INF");
        PropertySheetTabOperator psto = pw.getPropertySheetTabOperator("Properties");
	TextFieldProperty tf=new TextFieldProperty(psto,"Context Root");

	value=tf.getValue();
	tf.setValue("/test-wm");	// NOI18N

	node=getNode("jsps"+delim+"ContextRoot");	// NOI18N
	new CompileAction().performMenu(node);
	waitFor(5000);
	new ViewAction().performPopup(node);
	waitFor(5000);

        EditorWindowOperator ewo = new EditorWindowOperator();
        EditorOperator editor = ewo.getEditor("ContextRoot");	// NOI18N
	if (!editor.contains("public class ContextRoot")) 	// NOI18N
		fail("Invalid servlet content.");
	editor.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.