From: Tim P <ti...@us...> - 2008-03-28 20:10:25
|
Update of /cvsroot/webmacro/webmacro/test/unit/org/webmacro/servlet/test In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv7033/test/unit/org/webmacro/servlet/test Added Files: JettyWebTestCase.java InvokeExampleServletsTest.java Log Message: Initial version --- NEW FILE: InvokeExampleServletsTest.java --- /* * $Source: /cvsroot/webmacro/webmacro/test/unit/org/webmacro/servlet/test/InvokeExampleServletsTest.java,v $ * $Revision: 1.1 $ * * Copyright (C) 2008 Tim Pizey * * Part of Melati (http://melati.org), a framework for the rapid * development of clean, maintainable web applications. * * Melati is free software; Permission is granted to copy, distribute * and/or modify this software under the terms either: * * a) the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version, * * or * * b) any version of the Melati Software License, as published * at http://melati.org * * You should have received a copy of the GNU General Public License and * the Melati Software License along with this program; * if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the * GNU General Public License and visit http://melati.org to obtain the * Melati Software License. * * Feel free to contact the Developers of Melati (http://melati.org), * if you would like to work out a different arrangement than the options * outlined here. It is our intention to allow Melati to be used by as * wide an audience as possible. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Contact details for copyright holder: * * Tim Pizey <timp At paneris.org> * http://paneris.org/~timp */ package org.webmacro.servlet.test; /** * @author timp * @since 18 Mar 2008 * */ public class InvokeExampleServletsTest extends JettyWebTestCase { /** * Constructor. * * @param name */ public InvokeExampleServletsTest(String name) { super(name); } /** * {@inheritDoc} */ protected void setUp () throws Exception { super.setUp(); } /** * {@inheritDoc} */ protected void tearDown () throws Exception { super.tearDown(); } public void testInvokeHelloWorld () throws Exception { beginAt("/servlet/HelloWorld"); assertTextPresent("WebMacro is working!"); } public void testInvokeCheckConfig () throws Exception { beginAt("/servlet/CheckConfig"); assertTextPresent("WebMacro Configuration"); } public void testInvokeGuestBook () throws Exception { beginAt("/servlet/GuestBook"); assertTextPresent("GuestBook Example"); } public void testInvokeStandalone () throws Exception { beginAt("/servlet/Standalone"); assertTextPresent("WebMacro \"Standalone\" example"); } } --- NEW FILE: JettyWebTestCase.java --- package org.webmacro.servlet.test; import org.mortbay.jetty.Server; import org.mortbay.jetty.webapp.WebAppContext; import net.sourceforge.jwebunit.junit.WebTestCase; /** * * Much thanks to * http://today.java.net/pub/a/today/2007/04/12/embedded-integration-testing-of-web-applications.html * * Run as an application and try http://localhost:8080/wmtest/index.html * or extend for your htmlunit tests. * * @author timp * @since 2008/03/18 * */ public abstract class JettyWebTestCase extends WebTestCase { private static Server server; private static String contextName = "wmtest"; private static String webRoot ="examples"; /** * Constructor. */ public JettyWebTestCase() { super(); } /** * Constructor, with name. * @param name */ public JettyWebTestCase(String name) { super(name); } protected void setUp() throws Exception { // Port 0 means "assign arbitrarily port number" server = new Server(0); startServer(); // getLocalPort returns the port that was actually assigned int actualPort = server.getConnectors()[0].getLocalPort(); getTestContext().setBaseUrl( "http://localhost:" + actualPort + "/" ); } private static void startServer() throws Exception { WebAppContext wac = new WebAppContext( webRoot, "/" + contextName); org.mortbay.resource.FileResource.setCheckAliases(false); server.addHandler(wac); server.start(); wac.dumpUrl(); } protected void tearDown() throws Exception { super.tearDown(); } /** * If you don't know by now. * @param args * @throws Exception */ public static void main(String[] args) throws Exception { server = new Server(8080); startServer(); } /** * Just to say hello. */ public void testIndex() { beginAt("/index.html"); assertTextPresent("Hello World"); } /** * {@inheritDoc} * @see net.sourceforge.jwebunit.junit.WebTestCase#beginAt(java.lang.String) */ public void beginAt(String url) { super.beginAt(contextUrl(url)); } /** * {@inheritDoc} * @see net.sourceforge.jwebunit.junit.WebTestCase#gotoPage(java.lang.String) */ public void gotoPage(String url) { super.gotoPage(contextUrl(url)); } protected String contextUrl(String url) { return "/" + contextName + url; } } |