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-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */




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

import org.netbeans.junit.NbTestSuite;
import org.netbeans.jellytools.ExplorerOperator;
import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.RepositoryTabOperator;
import org.netbeans.jellytools.nodes.FilesystemNode;
import org.netbeans.jellytools.nodes.FolderNode;
import org.netbeans.jellytools.QuestionDialogOperator;
import org.netbeans.jellytools.WizardOperator;
import org.netbeans.jellytools.actions.ActionNoBlock;
import org.netbeans.jellytools.ChooseTemplateStepOperator;
import org.netbeans.jellytools.TargetLocationStepOperator;
import org.netbeans.jellytools.EditorOperator;
import org.netbeans.jellytools.EditorWindowOperator;
import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.netbeans.jellytools.Bundle;

import org.netbeans.test.gui.web.webmodule.util.Test_Support;

import java.io.*;
import java.net.*;
/**
 */
public class Webmodule_e2e_jsp_servlet extends JellyTestCase 
{
    private static String ssep = "|";
    private static String fsep = System.getProperty("file.separator");
    private static String webmodule_name = "webapp_test1";
    
    /** Creates a new instance of webmodule_creation */
    public Webmodule_e2e_jsp_servlet(String testName) {
        super(testName);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        NbTestSuite suite = new NbTestSuite();
        suite.addTest(new Webmodule_e2e_jsp_servlet("test_WebModuleCreation"));
        suite.addTest(new Webmodule_e2e_jsp_servlet("test_AddJSP2WebModule"));
        suite.addTest(new Webmodule_e2e_jsp_servlet("test_AddServlet2WebModule"));
        suite.addTest(new Webmodule_e2e_jsp_servlet("test_EditJSP"));
        suite.addTest(new Webmodule_e2e_jsp_servlet("test_EditServlet"));
        suite.addTest(new Webmodule_e2e_jsp_servlet("test_CompileWebModule"));
        suite.addTest(new Webmodule_e2e_jsp_servlet("test_ExecuteWebModule"));
        junit.textui.TestRunner.run(suite);
        
    }
    
        public void test_WebModuleCreation(){
            String path = Test_Support.getTestDir(webmodule_name);
            String m_path1 = Bundle.getString("org.netbeans.core.Bundle","Actions/Tools");
            String m_path2 = Bundle.getStringTrimmed("org.netbeans.modules.web.context.actions.Bundle","ACT_ConvertWar");
            new RepositoryTabOperator().mountLocalDirectoryAPI(path);
            new FolderNode(path).performPopupActionNoBlock(m_path1+ssep+m_path2);
            new QuestionDialogOperator().ok();
            Test_Support.sleep();
            assertTrue(verify_webmodule(path));
            
        }   
    
    
    public void test_AddJSP2WebModule(){
      
        String path = System.getProperty("netbeans.user")+fsep+webmodule_name;
        
        String m_path1 = Bundle.getString("org.netbeans.core.ui.Bundle","CTL_New");
        String m_path2 = Bundle.getString("org.netbeans.modules.web.core.Bundle","Templates/JSP_Servlet");
        String m_path3 = Bundle.getString("org.netbeans.modules.web.core.Bundle","Templates/JSP_Servlet/JSP.jsp");
        new FolderNode(path).select();
        new ActionNoBlock("File|New", null).perform();
        WizardOperator wzd = new WizardOperator(m_path1);
        new ChooseTemplateStepOperator().selectTemplate(m_path2+ssep+m_path3);
        wzd.next();
        wzd.finish();
        Test_Support.sleep();
        assertTrue(verify_file(path+fsep+"JSP.jsp"));
    } 

     public void test_EditJSP(){
        //ExplorerOperator.invoke();
         EditorWindowOperator ewo = new EditorWindowOperator();
         String filename = "JSP";
         // switches to requested editor and gets EditorOperator instance
         EditorOperator editor = ewo.getEditor(filename);
         
        
        try{
	    //create buffered reader
        editor.txtEditorPane().clearText();
        BufferedReader in = new BufferedReader(new FileReader(System.getProperty("Webmodule.workdir")+fsep+"JSP.jsp"));
	    String str;
            int i = 1;
	    while ((str = in.readLine())!= null){
		editor.insert(str+'\n');               
	    }
	    in.close();
        }catch (IOException e){
	    e.printStackTrace();
	}
       
    }
     public void test_AddServlet2WebModule(){
        //ExplorerOperator.invoke();
          
        String path = System.getProperty("netbeans.user")+fsep+webmodule_name;
        
        String m_path1 = Bundle.getString("org.netbeans.core.ui.Bundle","CTL_New");
        String m_path2 = Bundle.getString("org.netbeans.modules.web.core.Bundle","Templates/JSP_Servlet");
        String m_path3 = Bundle.getString("org.netbeans.modules.web.core.Bundle","Templates/JSP_Servlet/Servlet.java");
        
        new FolderNode(path+"|WEB-INF|Classes").select();
        new ActionNoBlock("File|New", null).perform();
        WizardOperator wzd = new WizardOperator(m_path1);
        new ChooseTemplateStepOperator().selectTemplate(m_path2+ssep+m_path3);
        wzd.next();
        wzd.finish();
        Test_Support.sleep();
        assertTrue(verify_file(path+fsep+"WEB-INF"+fsep+"classes"+fsep+"Servlet.java"));
       
    }
    public void test_EditServlet(){
         EditorWindowOperator ewo = new EditorWindowOperator();
         String filename = "Servlet";
         // switches to requested editor and gets EditorOperator instance
         EditorOperator editor = ewo.getEditor(filename);
         
        
        try{
	    //create buffered reader
        editor.txtEditorPane().clearText();
        BufferedReader in = new BufferedReader(new FileReader(System.getProperty("Webmodule.workdir")+fsep+"Servlet.java"));
	    String str;
            
	    while ((str = in.readLine())!= null){
		editor.insert(str+'\n');               
		
	    }
	    in.close();
        
        }catch (IOException e){
	    e.printStackTrace();
	}
       
       
    }
     public void test_CompileWebModule(){
        //ExplorerOperator.invoke();
        String path = System.getProperty("netbeans.user")+fsep+webmodule_name;
        String m_path1 = Bundle.getStringTrimmed("org.openide.compiler.Bundle","CompileAll");
        new FolderNode(path).performPopupActionNoBlock(m_path1);
        Test_Support.sleep(10000);
      
        assertTrue(verify_file(path+fsep+"WEB-INF"+fsep+"classes"+fsep+"Servlet.class"));
       
    }
    public void test_ExecuteWebModule(){
        //ExplorerOperator.invoke();
        String path = System.getProperty("netbeans.user")+fsep+webmodule_name;                
        String m_path2 = Bundle.getStringTrimmed("org.openide.actions.Bundle","Execute");                
        new FolderNode(path+"|WEB-INF").performPopupActionNoBlock(m_path2);                      
	Test_Support.sleep(20000);
        verify_ExecuteResult();       
    }
    
    public boolean verify_webmodule(String path){
        return (Test_Support.isFileExist(path+fsep+"WEB-INF") && Test_Support.isFileExist(path+fsep+"WEB-INF"+fsep+"web.xml"));
        
    }
    public boolean verify_file(String filename){
        return (Test_Support.isFileExist(filename));
        
    }
    public void verify_ExecuteResult()
    {
        try{
	String hostname = java.net.InetAddress.getLocalHost().getHostName();
	URL url = new URL("http://"+hostname+":8081/JSP.jsp");
	BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
	String line;	
        while ((line = in.readLine()) != null ){
            ref(line);
        }
        compareReferenceFiles();
        
    }
    catch (IOException exception){	
       exception.printStackTrace();
       fail();
    }
    }
}
... 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.