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.extbrowser.execution; 

import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.Bundle;
import org.netbeans.jellytools.ExplorerOperator;
import org.netbeans.jellytools.NbFrameOperator;



import org.netbeans.jellytools.nodes.FolderNode;
import org.netbeans.jellytools.nodes.JavaNode;
import org.netbeans.jellytools.nodes.HTMLNode;


import org.netbeans.jellytools.actions.ExecuteAction;

import org.netbeans.junit.NbTestSuite;



import org.netbeans.jemmy.Waiter;

import org.netbeans.web.test.nodes.JSPNode;
import org.netbeans.web.test.nodes.ServletNode;
import org.netbeans.test.gui.web.util.JSPServletResponseWaitable;
import org.netbeans.test.gui.web.util.HttpRequestWaitable;
import org.netbeans.test.gui.web.util.BrowserUtils;



import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.netbeans.jemmy.operators.JTextComponentOperator;

public class ExecuteSwingBrowser extends JellyTestCase {
    private static String workDir = null;     
    private static String webModule = null;
    private static String wmName = "wm1";
    private static String fSep = System.getProperty("file.separator");
    private static String iSep = "|";
    private static String classes = "Classes";
    private static String servletForExecution = "ServletForExecution";
    private static String htmlForExecution = null;;
    private static String wmForExecution = "wmForExecution"; 
    private static String urlToRedirectFromHTML = "RedirectFromHtmlForExecution.html";
    private static String jspForExecution = null;
    private static String pkg = "execution";
    private static ExplorerOperator explorer = null;
    private String servletId = "cebde3e2-e8f1-4421-8a1c-df11dcc6e79a";
    private String jspId     = "c78eae2b-39f2-4b41-b2be-032e5373d7f4";
    private String wmId      = "9bc4ac0b-0a21-452a-9e51-ca9df3c2fa04";
    private int defaultPort = 1357;
    private int port = 2468;
    private String defaultAnswer = "HTTP/1.0 200 OK\nServer: FFJ Automated Tests SimpleServ\nLast-Modified: Fri, 12 Jul 2002 09:53:56 GMT\nContent-Length: 281\nConnection: close\nContent-Type: text/html\n\n\n\n   Tests passed\n\n\n

Request Accepted

\n\n"; public ExecuteSwingBrowser(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } //method required by JUnit public static junit.framework.Test suite() { workDir = System.getProperty("extbrowser.workdir").replace('/', fSep.charAt(0)); webModule = workDir + fSep + wmName; htmlForExecution = webModule + iSep + "html" + iSep + "HtmlFileForExecution"; jspForExecution = webModule + iSep + "jsp" + iSep + "JSPForExecution"; pkg = webModule + iSep + "WEB-INF" + iSep + classes + iSep + pkg; return new NbTestSuite(ExecuteSwingBrowser.class); } public void testExecuteHtml() { NbFrameOperator fo = null; HTMLNode node1 = null; BrowserUtils.setSwingBrowser(); try { node1 = new HTMLNode(htmlForExecution); }catch(Exception e) { fail("Not found: " + htmlForExecution); } new ExecuteAction().perform(node1); BrowserUtils.handleSwingBrowserDialog(); try { fo = new NbFrameOperator("Web Browser"); }catch(Exception e) { e.printStackTrace(); fail("Looks like browser not started."); } JTextFieldOperator tf = new JTextFieldOperator(fo,0); if(tf.getText().indexOf("HtmlFileForExecution")==-1) { fail("Wrong URL in SWING browser: " + tf.getText()); } JTextComponentOperator tf1 = new JTextComponentOperator(fo,0); System.out.println("TEXTFIELD 1: " + tf1.getText()); if(tf1.getText().indexOf("Html file executed correctly")==-1) { fail("Wrong CONTENT shown in SWING browser: " + tf1.getText()); } } public void testExecuteSevlet() { ServletNode node1 = null; BrowserUtils.setSwingBrowser(); try { node1 = new ServletNode(pkg + iSep + servletForExecution); }catch(Exception e) { fail("Not found: " + servletForExecution); } JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(servletId, defaultAnswer, port); node1.execute(); BrowserUtils.handleSwingBrowserDialog(); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (Exception e) { e.printStackTrace(); fail("Looks like browser not started or URL not loaded"); } } public void testExecuteJSP() { JSPNode node1 = null; BrowserUtils.setSwingBrowser(); try { node1 = new JSPNode(jspForExecution); }catch(Exception e) { fail("Not found: " + jspForExecution); } JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(jspId, defaultAnswer, port); node1.execute(); BrowserUtils.handleSwingBrowserDialog(); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (Exception e) { e.printStackTrace(); fail("Looks like browser not started or URL not loaded"); } } public void testExecuteWebModule() { FolderNode node1 = null; BrowserUtils.setSwingBrowser(); try { node1 = new FolderNode(workDir + fSep + wmForExecution + iSep + "WEB-INF"); }catch(Exception e) { fail("Web Module for execution not found"); } JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(wmId, defaultAnswer, port); new ExecuteAction().perform(node1); BrowserUtils.handleSwingBrowserDialog(); Waiter w = new Waiter(jsrw); try { w.waitAction(jsrw); } catch (Exception e) { e.printStackTrace(); fail("Looks like browser not started or URL not loaded"); } } }
... 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.