Update of /cvsroot/jwebunit/jWebUnit/fitplugin/test/net/sourceforge/jwebunit/fit
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14837/fitplugin/test/net/sourceforge/jwebunit/fit

Modified Files:
        WebFixtureTest.java 
Log Message:
Implemented use of jetty for fixture test. Use of the PseudoWebApp has been 
commented out. Temporarily added dummy files for the dynamic pages needed.

Index: WebFixtureTest.java
===================================================================
RCS file: 
/cvsroot/jwebunit/jWebUnit/fitplugin/test/net/sourceforge/jwebunit/fit/WebFixtureTest.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** WebFixtureTest.java 3 Jan 2006 10:40:54 -0000       1.18
--- WebFixtureTest.java 3 Jan 2006 13:47:22 -0000       1.19
***************
*** 6,9 ****
--- 6,21 ----
  package net.sourceforge.jwebunit.fit;
  
+ import java.io.IOException;
+ import java.util.HashMap;
+ import java.util.Map;
+ 
+ import net.sourceforge.jwebunit.WebTester;
+ 
+ import org.mortbay.http.HttpContext;
+ import org.mortbay.http.HttpServer;
+ import org.mortbay.http.SocketListener;
+ import org.mortbay.http.handler.ResourceHandler;
+ import org.mortbay.util.Resource;
+ 
  import junit.framework.TestCase;
  
***************
*** 12,15 ****
--- 24,45 ----
      public static final int MINIMUM_TESTS = 50;
      public static final String TEST_ROOT = "fitplugin/test/";
+     public static final String TEST_HTML_FOLDER = "sampleHtml/";
+     public static final int JETTY_PORT_DEFAULT = 8081;
+     public static final String JETTY_PORT_PROPERTY = "jetty.port";
+     private static final String HOST = "localhost";
+     
+     private HttpServer server = null;
+     
+     // translation between urls used in .fit files and the urls in jetty 
context
+     private static Map oldUrls = null;
+     static {
+         oldUrls = new HashMap();
+         oldUrls.put("/colorForm", "/ColorForm.html");
+         oldUrls.put("/moriaDoorForm", "/MoriaDoorForm.html");
+         oldUrls.put("/personalInfoForm", "/PersonalInfoForm.html");
+         oldUrls.put("/sampleMenu", "/SampleMenu.html");
+         oldUrls.put("/pageWithPopupLink", "/pageWithPopupLink.html");
+         oldUrls.put("/menu", "/menu.html");
+     }
      
      public WebFixtureTest(String s) {
***************
*** 17,22 ****
      }
  
      public void testWebFixture() throws Exception {
!         new PseudoWebApp();
          // avoid the need of the system property, always use .fit files for 
input
          RunnerUtility.overrideSystemPropertyAndUseWikiParser = true;
--- 47,88 ----
      }
  
+     protected void setUp() throws Exception {
+         super.setUp();
+         server = new HttpServer();
+         SocketListener listener = new SocketListener();
+         listener.setPort(getJettyPort());
+         listener.setHost(HOST);
+         listener.setMinThreads(1);
+         listener.setMaxThreads(10);
+         server.addListener(listener);
+         // add the tiles in sampleHtml to context
+         final HttpContext context = server.addContext("/");
+         context.setResourceBase(TEST_ROOT + TEST_HTML_FOLDER);
+         assertTrue("Should find index.html in the configured jetty context",
+                 context.getResource("index.html").exists());
+         context.addHandler(new ResourceHandler() {
+             protected Resource getResource(String pathInContext) throws 
IOException {
+                 Resource r = super.getResource(pathInContext);
+                 if (!r.exists() && oldUrls.containsKey(pathInContext)) { // 
don't want to update the .fit files until the old tests work
+                     r = 
super.getResource(oldUrls.get(pathInContext).toString());
+                 }
+                 assertTrue("The requested resource '" + pathInContext + "' 
must exist", r.exists());
+                 return r;
+             }
+         });
+         // run
+         server.start();
+     }
+ 
+     public void testFixtureStart() throws Exception {
+         WebFixture fixture = new WebFixture();
+         fixture.setBaseUrl("http://"; + HOST + ":" + getJettyPort());
+         WebTester tester = WebFixture.tester;
+         tester.beginAt("index.html");
+         tester.assertTitleEquals("Test root");
+     }
+     
      public void testWebFixture() throws Exception {
!         //new PseudoWebApp();
          // avoid the need of the system property, always use .fit files for 
input
          RunnerUtility.overrideSystemPropertyAndUseWikiParser = true;
***************
*** 38,41 ****
--- 104,118 ----
                testRunner.getResultWriter().getCounts().exceptions);
      }
+     
+     protected void tearDown() throws Exception {
+         server.stop();
+         server = null;
+         super.tearDown();
+     }
+     
+     public static int getJettyPort() {
+         String p = System.getProperty(JETTY_PORT_PROPERTY, "" + 
JETTY_PORT_DEFAULT);
+         return Integer.parseInt(p);
+     }
  
  }
\ No newline at end of file



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to