org.apache.cactus.extension.jetty
Class Jetty5xTestSetup

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.extensions.TestDecorator
          extended by junit.extensions.TestSetup
              extended by org.apache.cactus.extension.jetty.Jetty5xTestSetup
All Implemented Interfaces:
junit.framework.Test

public class Jetty5xTestSetup
extends junit.extensions.TestSetup

Custom JUnit test setup to use to automatically start Jetty. Example:

 public static Test suite()
 {
     TestSuite suite = new TestSuite(Myclass.class);
     return new JettyTestSetup(suite);
 }
 

Version:
$Id: JettyTestSetup.java 239036 2004-08-17 10:35:57Z vmassol $

Field Summary
 
Fields inherited from class junit.extensions.TestDecorator
fTest
 
Constructor Summary
Jetty5xTestSetup(junit.framework.Test theTest)
           
Jetty5xTestSetup(junit.framework.Test theTest, Configuration theBaseConfiguration, ServletConfiguration theServletConfiguration, FilterConfiguration theFilterConfiguration)
           
 
Method Summary
protected  java.io.File getConfigFile()
           
protected  java.io.File getResourceDir()
           
protected  boolean isAvailable(int theCode)
          Tests whether an HTTP return code corresponds to a valid connection to the test URL or not.
protected  boolean isRunning()
           
protected  void readFully(java.net.HttpURLConnection theConnection)
          Fully reads the input stream from the passed HTTP URL connection to prevent (harmless) server-side exception.
 void run(junit.framework.TestResult theResult)
          Make sure that tearDown() is called if setUp() fails to start the container properly.
 void setConfigFile(java.io.File theConfigFile)
          Sets the configuration file to use for initializing Jetty.
 void setForceShutdown(boolean isForcedShutdown)
           
 void setResourceDir(java.io.File theResourceDir)
          Sets the directory in which Jetty will look for the web-application resources.
protected  void setUp()
          Start an embedded Jetty server.
protected  void tearDown()
          Stop the running Jetty server.
protected  int testConnectivity(java.net.URL theUrl)
          Tests whether we are able to connect to the HTTP server identified by the specified URL.
 
Methods inherited from class junit.extensions.TestDecorator
basicRun, countTestCases, getTest, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Jetty5xTestSetup

public Jetty5xTestSetup(junit.framework.Test theTest)
Parameters:
theTest - the test we are decorating (usually a test suite)

Jetty5xTestSetup

public Jetty5xTestSetup(junit.framework.Test theTest,
                        Configuration theBaseConfiguration,
                        ServletConfiguration theServletConfiguration,
                        FilterConfiguration theFilterConfiguration)
Parameters:
theTest - the test we are decorating (usually a test suite)
theBaseConfiguration - the base configuration object used to configure Jetty
theServletConfiguration - the servlet configuration object used to configure Jetty
theFilterConfiguration - the filter configuration object used to configure Jetty
Method Detail

run

public void run(junit.framework.TestResult theResult)
Make sure that tearDown() is called if setUp() fails to start the container properly. The default TestSetup.run(TestResult) method does not provide this feature unfortunately.

Specified by:
run in interface junit.framework.Test
Overrides:
run in class junit.extensions.TestSetup
See Also:
TestSetup.run(TestResult)

setUp

protected void setUp()
              throws java.lang.Exception
Start an embedded Jetty server. It is allowed to pass a Jetty XML as a system property (cactus.jetty.config) to further configure Jetty. Example: -Dcactus.jetty.config=./jetty.xml.

Overrides:
setUp in class junit.extensions.TestSetup
Throws:
java.lang.Exception - if an error happens during initialization

tearDown

protected void tearDown()
                 throws java.lang.Exception
Stop the running Jetty server.

Overrides:
tearDown in class junit.extensions.TestSetup
Throws:
java.lang.Exception - if an error happens during the shutdown

setConfigFile

public final void setConfigFile(java.io.File theConfigFile)
Sets the configuration file to use for initializing Jetty.

Parameters:
theConfigFile - The configuration file to set

setResourceDir

public final void setResourceDir(java.io.File theResourceDir)
Sets the directory in which Jetty will look for the web-application resources.

Parameters:
theResourceDir - The resource directory to set

setForceShutdown

public final void setForceShutdown(boolean isForcedShutdown)
Parameters:
isForcedShutdown - if true the container will be stopped even if it has not been started by us

getConfigFile

protected final java.io.File getConfigFile()
Returns:
The resource directory, or null if it has not been set

getResourceDir

protected final java.io.File getResourceDir()
Returns:
The resource directory, or null if it has not been set

testConnectivity

protected int testConnectivity(java.net.URL theUrl)
Tests whether we are able to connect to the HTTP server identified by the specified URL.

Parameters:
theUrl - The URL to check
Returns:
the HTTP response code or -1 if no connection could be established

isAvailable

protected boolean isAvailable(int theCode)
Tests whether an HTTP return code corresponds to a valid connection to the test URL or not. Success is 200 up to but excluding 300.

Parameters:
theCode - the HTTP response code to verify
Returns:
true if the test URL could be called without error, false otherwise

readFully

protected void readFully(java.net.HttpURLConnection theConnection)
                  throws java.io.IOException
Fully reads the input stream from the passed HTTP URL connection to prevent (harmless) server-side exception.

Parameters:
theConnection - the HTTP URL connection to read from
Throws:
java.io.IOException - if an error happens during the read

isRunning

protected boolean isRunning()
Returns:
true if the server is running or false otherwise


Copyright © 2001-2009 The Apache Software Foundation. All Rights Reserved.