JSF-Spring

de.mindmatters.faces.spring.test
Class AbstractJsfSpringContextTests

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.springframework.test.ConditionalTestCase
              extended by org.springframework.test.AbstractSpringContextTests
                  extended by org.springframework.test.AbstractSingleSpringContextTests
                      extended by org.springframework.test.AbstractDependencyInjectionSpringContextTests
                          extended by de.mindmatters.faces.spring.test.AbstractJsfSpringContextTests
All Implemented Interfaces:
junit.framework.Test

public abstract class AbstractJsfSpringContextTests
extends AbstractDependencyInjectionSpringContextTests

Convenient superclass for integration tests depending on a JSF-Spring context hierarchy. The test instance itself is populated by Dependency Injection.

This test mocks the servlet-api and builds up a fully working JSF implementation based upon any production environment you choose (e.g. MyFaces with the help of the MyFacesStartupDriver or SunRI with JsfRIStartupDriver).

Subclasses have to implement getResourceBasePath() which should point to an 'unzipped' WAR. All relevant context files will be automatically loaded and you are able to test your production setup or build up 'fake' web applications for testing your managed beans.

Author:
Andreas Kuhrwahl

Field Summary
 
Fields inherited from class org.springframework.test.AbstractDependencyInjectionSpringContextTests
AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_NO
 
Fields inherited from class org.springframework.test.AbstractSingleSpringContextTests
applicationContext
 
Fields inherited from class org.springframework.test.ConditionalTestCase
logger
 
Constructor Summary
AbstractJsfSpringContextTests()
          Default constructor - populating protected variables via dependency injection is turned on.
 
Method Summary
protected  java.lang.String contextKeyString(java.lang.Object contextKey)
          Subclasses can override this to return a String representation of their context key for use in logging.
protected  javax.servlet.ServletContext createServletContext()
          Creates the ServletContext mock implementation - default is MockServletContext.
protected  java.lang.String[] getConfigLocations()
          Subclasses must implement this method to return the locations of their config files.
protected abstract  java.lang.String getResourceBasePath()
           
protected  javax.servlet.ServletContext getServletContext()
           
protected  WebApplicationContext getWebApplicationContext()
           
protected  ConfigurableWebApplicationContext loadContext(javax.servlet.ServletContext servletContext)
          Loads the FacesWebApplicationContext by default - with the parent loaded by loadParentContext(ServletContext).
protected  ConfigurableApplicationContext loadContextLocations(java.lang.String[] locations)
          Load an ApplicationContext from the given config locations.
protected  JsfEnvironment loadJsfEnvironment(javax.servlet.ServletContext servletContext)
          Loads the JsfEnvironment of the particular test case.
protected  JsfStartupDriver loadJsfImplementation(javax.servlet.ServletContext servletContext)
          Loads the current JSF implementation startup driver used for configuration and initialization purposes.
protected  ConfigurableWebApplicationContext loadParentContext(javax.servlet.ServletContext servletContext)
          Loads the parent WebApplicationContext - the ContextLoader is used for loading and initialization by default.
protected  void onSetUp()
          Subclasses can override this method in place of the setUp() method, which is final in this class.
protected  void onTearDown()
          Subclasses can override this to add custom behavior on teardown.
protected  void prepareTestInstance()
          Prepare this test instance, injecting dependencies into its protected fields and its bean properties.
 
Methods inherited from class org.springframework.test.AbstractDependencyInjectionSpringContextTests
getAutowireMode, isDependencyCheck, isPopulateProtectedVariables, setAutowireMode, setDependencyCheck, setPopulateProtectedVariables
 
Methods inherited from class org.springframework.test.AbstractSingleSpringContextTests
contextKey, getLoadCount, loadContext, setDirty, setUp, tearDown
 
Methods inherited from class org.springframework.test.AbstractSpringContextTests
addContext, getContext, hasCachedContext, setDirty
 
Methods inherited from class org.springframework.test.ConditionalTestCase
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled, runBare
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractJsfSpringContextTests

public AbstractJsfSpringContextTests()
Default constructor - populating protected variables via dependency injection is turned on.

Method Detail

prepareTestInstance

protected final void prepareTestInstance()
                                  throws java.lang.Exception
Prepare this test instance, injecting dependencies into its protected fields and its bean properties.

Overrides:
prepareTestInstance in class AbstractDependencyInjectionSpringContextTests
Throws:
java.lang.Exception

loadContextLocations

protected final ConfigurableApplicationContext loadContextLocations(java.lang.String[] locations)
                                                             throws java.lang.Exception
Load an ApplicationContext from the given config locations.

Overrides:
loadContextLocations in class AbstractSingleSpringContextTests
Parameters:
locations - the config locations
Returns:
the corresponding ApplicationContext instance (potentially cached)
Throws:
java.lang.Exception

createServletContext

protected javax.servlet.ServletContext createServletContext()
Creates the ServletContext mock implementation - default is MockServletContext.

Returns:
the mock

loadJsfEnvironment

protected JsfEnvironment loadJsfEnvironment(javax.servlet.ServletContext servletContext)
                                     throws java.lang.Exception
Loads the JsfEnvironment of the particular test case.

Parameters:
servletContext - the current ServletContext
Returns:
the current JsfEnvironment
Throws:
java.lang.Exception - in case of errors

loadContext

protected ConfigurableWebApplicationContext loadContext(javax.servlet.ServletContext servletContext)
                                                 throws java.lang.Exception
Loads the FacesWebApplicationContext by default - with the parent loaded by loadParentContext(ServletContext).

Parameters:
servletContext - the current ServletContext
Returns:
the JSF WebApplicationContext
Throws:
java.lang.Exception - in case of errors

loadJsfImplementation

protected JsfStartupDriver loadJsfImplementation(javax.servlet.ServletContext servletContext)
                                          throws java.lang.Exception
Loads the current JSF implementation startup driver used for configuration and initialization purposes.

Parameters:
servletContext - the current ServletContext
Returns:
the used JsfStartupDriver
Throws:
java.lang.Exception - in case of errors

contextKeyString

protected final java.lang.String contextKeyString(java.lang.Object contextKey)
Subclasses can override this to return a String representation of their context key for use in logging.

Overrides:
contextKeyString in class AbstractSpringContextTests
Parameters:
contextKey - the context key

loadParentContext

protected ConfigurableWebApplicationContext loadParentContext(javax.servlet.ServletContext servletContext)
                                                       throws java.lang.Exception
Loads the parent WebApplicationContext - the ContextLoader is used for loading and initialization by default.

Parameters:
servletContext - the current ServletContext
Returns:
the parent WebApplicationContext
Throws:
java.lang.Exception - in case of errors

getServletContext

protected javax.servlet.ServletContext getServletContext()
Returns:
the ServletContext mock implementation

getConfigLocations

protected final java.lang.String[] getConfigLocations()
Subclasses must implement this method to return the locations of their config files. A plain path will be treated as class path location. E.g.: "org/springframework/whatever/foo.xml". Note however that you may prefix path locations with standard Spring resource prefixes. Therefore, a config location path prefixed with "classpath:" with behave the same as a plain path, but a config location such as "file:/some/path/path/location/appContext.xml" will be treated as a filesystem location.

Specified by:
getConfigLocations in class AbstractSingleSpringContextTests
Returns:
an array of config locations

getResourceBasePath

protected abstract java.lang.String getResourceBasePath()
Returns:
the path to an 'unzipped' WAR to test

onSetUp

protected void onSetUp()
                throws java.lang.Exception
Subclasses can override this method in place of the setUp() method, which is final in this class. This implementation does nothing.

Overrides:
onSetUp in class AbstractSingleSpringContextTests
Throws:
java.lang.Exception - simply let any exception propagate

onTearDown

protected void onTearDown()
                   throws java.lang.Exception
Subclasses can override this to add custom behavior on teardown.

Overrides:
onTearDown in class AbstractSingleSpringContextTests
Throws:
java.lang.Exception - simply let any exception propagate

getWebApplicationContext

protected WebApplicationContext getWebApplicationContext()
Returns:
the root WebApplicationContext

JSF-Spring

Copyright © 2006 mindmatters GmbH & Co. KG