org.apache.myfaces.test.base.junit4
Class AbstractJsfConfigurableMultipleRequestsTestCase

java.lang.Object
  extended by org.apache.myfaces.test.base.junit4.AbstractJsfConfigurableMultipleRequestsTestCase

public abstract class AbstractJsfConfigurableMultipleRequestsTestCase
extends Object

Abstract JUnit 4.5 test case base class, which sets up the JavaServer Faces mock object environment for multiple simulated request. The following protected variables are initialized in the setUp() method, and cleaned up in the tearDown() method:

In addition, appropriate factory classes will have been registered with javax.faces.FactoryFinder for Application and RenderKit instances. The created FacesContext instance will also have been registered in the proper thread local variable, to simulate what a servlet container would do.

WARNING - If you choose to subclass this class, be sure your setUp() and tearDown() methods call super.setUp() and super.tearDown() respectively, and that you implement your own suite() method that exposes the test methods for your test case. Additionally, check on each test that setupRequest() and tearDownRequest() are called correctly.

Since:
1.0.3

Field Summary
protected  javax.faces.application.Application application
           
protected  MockServletConfig config
           
protected  javax.faces.context.ExternalContext externalContext
           
protected  javax.faces.context.FacesContext facesContext
           
protected  javax.faces.context.FacesContextFactory facesContextFactory
           
protected  javax.faces.lifecycle.Lifecycle lifecycle
           
protected  javax.faces.lifecycle.LifecycleFactory lifecycleFactory
           
protected  javax.faces.render.RenderKit renderKit
           
protected  MockHttpServletRequest request
           
protected  MockHttpServletResponse response
           
protected  MockServletContext servletContext
           
protected  MockHttpSession session
           
 
Constructor Summary
AbstractJsfConfigurableMultipleRequestsTestCase()
          Construct a new instance of this test case.
 
Method Summary
protected  void setFactories()
          Set JSF factories using FactoryFinder method setFactory.
 void setUp()
          Set up instance variables required by this test case.
protected  void setUpApplication()
          Setup the application variable and before the end by default it is assigned to the facesContext variable, calling facesContext.setApplication(application)
protected  void setUpClassloader()
          Set up the thread context classloader.
protected  void setUpExternalContext()
          Setup the externalContext variable, using the servlet variables already initialized.
protected  void setUpFacesContext()
          Setup the facesContextFactory and facesContext variable.
protected  void setUpJSFRequestObjects()
          Setup JSF object used for the test.
protected  void setUpLifecycle()
          Setup the lifecycle and lifecycleFactory variables.
protected  void setUpRenderKit()
          Setup the renderKit variable.
 void setupRequest()
          This method initialize an new empty request.
protected  void setUpServletContextAndSession()
          Setup servlet objects that will be used for the test:
protected  void setUpServletRequestAndResponse()
           
protected  void setUpView()
          By default, create an instance of UIViewRoot, set its viewId as "/viewId" and assign it to the current facesContext.
 void tearDown()
          Tear down instance variables required by this test case.
protected  void tearDownClassloader()
           
 void tearDownRequest()
          This method ends the current request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

application

protected javax.faces.application.Application application

config

protected MockServletConfig config

externalContext

protected javax.faces.context.ExternalContext externalContext

facesContext

protected javax.faces.context.FacesContext facesContext

facesContextFactory

protected javax.faces.context.FacesContextFactory facesContextFactory

lifecycle

protected javax.faces.lifecycle.Lifecycle lifecycle

lifecycleFactory

protected javax.faces.lifecycle.LifecycleFactory lifecycleFactory

renderKit

protected javax.faces.render.RenderKit renderKit

request

protected MockHttpServletRequest request

response

protected MockHttpServletResponse response

servletContext

protected MockServletContext servletContext

session

protected MockHttpSession session
Constructor Detail

AbstractJsfConfigurableMultipleRequestsTestCase

public AbstractJsfConfigurableMultipleRequestsTestCase()

Construct a new instance of this test case.

Parameters:
name - Name of this test case
Method Detail

setUp

public void setUp()
           throws Exception

Set up instance variables required by this test case.

Throws:
Exception

setUpClassloader

protected void setUpClassloader()
                         throws Exception
Set up the thread context classloader. JSF uses the this classloader in order to find related factory classes and other resources, but in some selected cases, the default classloader cannot be properly set.

Throws:
Exception

setupRequest

public void setupRequest()
                  throws Exception
This method initialize an new empty request.

Throws:
Exception

setUpJSFRequestObjects

protected void setUpJSFRequestObjects()
                               throws Exception

Setup JSF object used for the test. By default it calls to the following methods in this order:

Throws:
Exception

setUpServletContextAndSession

protected void setUpServletContextAndSession()
                                      throws Exception

Setup servlet objects that will be used for the test:

Throws:
Exception

setUpServletRequestAndResponse

protected void setUpServletRequestAndResponse()
                                       throws Exception
Throws:
Exception

setFactories

protected void setFactories()
                     throws Exception

Set JSF factories using FactoryFinder method setFactory.

Throws:
Exception

setUpExternalContext

protected void setUpExternalContext()
                             throws Exception
Setup the externalContext variable, using the servlet variables already initialized.

Throws:
Exception

setUpLifecycle

protected void setUpLifecycle()
                       throws Exception
Setup the lifecycle and lifecycleFactory variables.

Throws:
Exception

setUpFacesContext

protected void setUpFacesContext()
                          throws Exception
Setup the facesContextFactory and facesContext variable. Before end, by default it override externalContext variable from the value retrieved from facesContext.getExternalContext(), because sometimes it is possible facesContext overrides externalContext internally.

Throws:
Exception

setUpView

protected void setUpView()
                  throws Exception
By default, create an instance of UIViewRoot, set its viewId as "/viewId" and assign it to the current facesContext.

Throws:
Exception

setUpApplication

protected void setUpApplication()
                         throws Exception
Setup the application variable and before the end by default it is assigned to the facesContext variable, calling facesContext.setApplication(application)

Throws:
Exception

setUpRenderKit

protected void setUpRenderKit()
                       throws Exception
Setup the renderKit variable. This is a good place to use ConfigParser to register converters, validators, components or renderkits.

Throws:
Exception

tearDown

public void tearDown()
              throws Exception

Tear down instance variables required by this test case.

Throws:
Exception

tearDownClassloader

protected void tearDownClassloader()
                            throws Exception
Throws:
Exception

tearDownRequest

public void tearDownRequest()
This method ends the current request.



Copyright © 2014 The Apache Software Foundation. All Rights Reserved.