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

Modified Files:
        WebFixtureTest.java 
Log Message:
Refactored to get jetty configuration in separate methods.

Index: WebFixtureTest.java
===================================================================
RCS file: 
/cvsroot/jwebunit/jWebUnit/fitplugin/test/net/sourceforge/jwebunit/fit/WebFixtureTest.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** WebFixtureTest.java 3 Jan 2006 15:28:20 -0000       1.21
--- WebFixtureTest.java 3 Jan 2006 15:41:54 -0000       1.22
***************
*** 7,10 ****
--- 7,11 ----
  
  import java.io.IOException;
+ import java.net.UnknownHostException;
  import java.util.HashMap;
  import java.util.Map;
***************
*** 26,37 ****
      public static final String TEST_ROOT = "test/";
      public static final String TEST_HTML_FOLDER = "sampleHtml/";
-     public static final String TEST_CONTEXT = "/";
      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 {
--- 27,38 ----
      public static final String TEST_ROOT = "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";
!     public static final String JETTY_CONTEXT = "/";
!     public static final String JETTY_HOST = "localhost";
      
      private HttpServer server = null;
      
!     // translation between urls used in old .fit files and the urls in jetty 
context
      private static Map oldUrls = null;
      static {
***************
*** 51,94 ****
      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 files in sampleHtml to context
!         HttpContext context = server.addContext(TEST_CONTEXT);
!         context.setResourceBase(TEST_ROOT + TEST_HTML_FOLDER);
!         if (!context.getResource("index.html").exists()) {
!             // allow the test to run from parent project
!             context.setResourceBase(PLUGIN_FOLDER + TEST_ROOT + 
TEST_HTML_FOLDER);
!         }
!         // check that the context root contains the web pages
!         assertTrue("Should find index.html in the configured jetty context: " 
+ context.getResourceBase(),
!                 context.getResource("index.html").exists());
!         // handle static HTML
!         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();
--- 52,74 ----
      protected void setUp() throws Exception {
          super.setUp();
!         setUpConfiguredServer();
!         setUpContextWithTestWebapp();
          // run
          server.start();
      }
+     
+     protected void tearDown() throws Exception {
+         server.stop();
+         super.tearDown();
+     }
  
      public void testFixtureStart() throws Exception {
          WebFixture fixture = new WebFixture();
!         fixture.setBaseUrl("http://"; + JETTY_HOST + ":" + getJettyPort());
          WebTester tester = WebFixture.tester;
          tester.beginAt("index.html");
          tester.assertTitleEquals("Test root");
      }
! 
      public void testWebFixture() throws Exception {
          //new PseudoWebApp();
***************
*** 101,105 ****
                   TEST_ROOT + "testOutput"});
          testRunner.run();
!               testRunner.getResultWriter().write();
          // sanity check
          assertTrue("Should find at least " + MINIMUM_TESTS + " tests",
--- 81,85 ----
                   TEST_ROOT + "testOutput"});
          testRunner.run();
!         testRunner.getResultWriter().write();
          // sanity check
          assertTrue("Should find at least " + MINIMUM_TESTS + " tests",
***************
*** 107,120 ****
          // report failures to JUnit
          String resultsUrl = TEST_ROOT + "testOutput/index.html";
!               assertEquals("Failures detected. Check " + resultsUrl + ".", 0, 
!                       testRunner.getResultWriter().getCounts().wrong);
          assertEquals("Exceptions detected. Check " + resultsUrl + ".", 0, 
!               testRunner.getResultWriter().getCounts().exceptions);
      }
      
!     protected void tearDown() throws Exception {
!         server.stop();
!         server = null;
!         super.tearDown();
      }
      
--- 87,138 ----
          // report failures to JUnit
          String resultsUrl = TEST_ROOT + "testOutput/index.html";
!         assertEquals("Failures detected. Check " + resultsUrl + ".", 0, 
!             testRunner.getResultWriter().getCounts().wrong);
          assertEquals("Exceptions detected. Check " + resultsUrl + ".", 0, 
!             testRunner.getResultWriter().getCounts().exceptions);
!     }    
!     
!     // ---- below are methods for setting up the test web ----
!     
!     private void setUpConfiguredServer() throws UnknownHostException {
!         server = new HttpServer();
!         SocketListener listener = new SocketListener();
!         listener.setPort(getJettyPort());
!         listener.setHost(JETTY_HOST);
!         listener.setMinThreads(1);
!         listener.setMaxThreads(10);
!         server.addListener(listener);
      }
      
!     private void setUpContextWithTestWebapp() throws IOException {
!         // add the files in sampleHtml to context
!         HttpContext context = server.addContext(JETTY_CONTEXT);
!         context.setResourceBase(TEST_ROOT + TEST_HTML_FOLDER);
!         if (!context.getResource("index.html").exists()) {
!             // allow the test to run from parent project
!             context.setResourceBase(PLUGIN_FOLDER + TEST_ROOT + 
TEST_HTML_FOLDER);
!         }
!         // check that the context root contains the web pages
!         assertTrue("Should find index.html in the configured jetty context: " 
+ context.getResourceBase(),
!                 context.getResource("index.html").exists());
!         setUpContextHandlers(context);
!     }
! 
!     private void setUpContextHandlers(HttpContext context) {
!         // handle static HTML
!         context.addHandler(getStaticHTMLResourceHandler());        
!     }
!     
!     private ResourceHandler getStaticHTMLResourceHandler() {
!         return 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;
!             }
!         };
      }
      



-------------------------------------------------------
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