public abstract class AbstractJsfConfigurableMockTestCase extends Object
Abstract JUnit 4.5 test case base class, which sets up the JavaServer Faces
mock object environment for a particular simulated request. The following
protected variables are initialized in the setUp() method, and
cleaned up in the tearDown() method:
application (Application)config (MockServletConfig)externalContext (ExternalContext)facesContext (FacesContext)lifecycle (Lifecycle)request (MockHttpServletRequestresponse (MockHttpServletResponse)servletContext (MockServletContext)session (MockHttpSession)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.
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
AbstractJsfConfigurableMockTestCase()
Construct a new instance of this test case.
|
| Modifier and Type | Method and Description |
|---|---|
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 |
setUpJSFObjects()
Setup JSF object used for the test.
|
protected void |
setUpLifecycle()
Setup the
lifecycle and lifecycleFactory
variables. |
protected void |
setUpRenderKit()
Setup the
renderKit variable. |
protected void |
setUpServletObjects()
Setup servlet objects that will be used for the test:
|
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() |
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
public AbstractJsfConfigurableMockTestCase()
Construct a new instance of this test case.
name - Name of this test casepublic void setUp()
throws Exception
Set up instance variables required by this test case.
Exceptionprotected void setUpClassloader()
throws Exception
Exceptionprotected void setUpJSFObjects()
throws Exception
Setup JSF object used for the test. By default it calls to the following methods in this order:
setUpExternalContext();setUpLifecycle();setUpFacesContext();setUpView();setUpApplication();setUpRenderKit();Exceptionprotected void setUpServletObjects()
throws Exception
Setup servlet objects that will be used for the test:
config (MockServletConfig)servletContext (MockServletContext)request (MockHttpServletRequestresponse (MockHttpServletResponse)session (MockHttpSession)Exceptionprotected void setFactories()
throws Exception
Set JSF factories using FactoryFinder method setFactory.
Exceptionprotected void setUpExternalContext()
throws Exception
externalContext variable, using the
servlet variables already initialized.Exceptionprotected void setUpLifecycle()
throws Exception
lifecycle and lifecycleFactory
variables.Exceptionprotected void setUpFacesContext()
throws Exception
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.Exceptionprotected void setUpView()
throws Exception
Exceptionprotected void setUpApplication()
throws Exception
application variable and before
the end by default it is assigned to the facesContext
variable, calling facesContext.setApplication(application)Exceptionprotected void setUpRenderKit()
throws Exception
renderKit variable. This is a good place to use
ConfigParser to register converters, validators, components
or renderkits.Exceptionpublic void tearDown()
throws Exception
Tear down instance variables required by this test case.
ExceptionCopyright © 2017 The Apache Software Foundation. All rights reserved.