|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.click.Context
org.apache.click.MockContext
public class MockContext
Provides a mock Context object for unit testing.
MockContainer instead.
This class defines a couple of helper methods to quickly create all the mock
objects needed for unit testing. Please see the following methods:
initContext()initContext(Locale)initContext(String)initContext(Locale, String)initContext(MockServletConfig, MockRequest, MockResponse, ClickServlet)
public class FormTest extends TestCase {
// Create a mock context
MockContext context = MockContext.initContext("test-form.htm");
MockRequest request = context.getMockRequest();
// The request value that should be set as the textField value
String requestValue = "one";
// Set form name and field name parameters
request.setParameter("form_name", "form");
request.setParameter("name", requestValue);
// Create form and fields
Form form = new Form("form");
TextField nameField = new TextField("name");
form.add(nameField);
// Check that nameField value is null
Assert.assertNull(nameField.getValueObject());
// Simulate a form onProcess event
form.onProcess();
// Check that nameField value is now bound to request value
Assert.assertEquals(requestValue, nameField.getValueObject());
}
Please note: using MockContext to run performance tests over a large
number of Controls could lead to out of memory errors. If you run
into memory issues, you can either re-recreate a MockContext or invoke
reset(), which removes all references to Controls,
ActionListeners and Behaviors.
| Field Summary |
|---|
| Fields inherited from class org.apache.click.Context |
|---|
config, context, isPost, LOCALE, response |
| Method Summary | |
|---|---|
boolean |
executeActionListeners()
Execute all listeners that was registered by processed Controls. |
boolean |
executeBehaviors()
Execute all behaviors that was registered by processed Controls. |
void |
executePreDestroy()
Execute the preDestroy method for all registered behaviors. |
void |
executePreRenderHeadElements()
Execute the preRenderHeadElements method for all registered behaviors. |
void |
executePreResponse()
Execute the preResponse method for all registered behaviors. |
boolean |
fireActionEventsAndClearRegistry()
Deprecated. use executeActionListeners() instead |
MockRequest |
getMockRequest()
Return the MockRequest instance for this
context. |
ClickServlet |
getServlet()
Return the mock ClickServlet instance for this
context. |
static MockContext |
initContext()
Creates and returns a new Context instance. |
static MockContext |
initContext(HttpServletRequest request)
Deprecated. use one of the other initContext methods because those will construct a complete mock stack including a MockRequest. |
static MockContext |
initContext(Locale locale)
Creates and returns a new Context instance for the specified locale. |
static MockContext |
initContext(Locale locale,
String servletPath)
Creates and returns a new Context instance for the specified locale and servletPath. |
static MockContext |
initContext(MockServletConfig servletConfig,
MockRequest request,
MockResponse response,
ClickServlet clickServlet)
Creates and returns a new Context instance for the specified mock objects. |
static MockContext |
initContext(MockServletConfig servletConfig,
MockRequest request,
MockResponse response,
ClickServlet clickServlet,
ActionEventDispatcher actionEventDispatcher,
ControlRegistry controlRegistry)
Creates and returns a new Context instance for the specified mock objects. |
static MockContext |
initContext(String servletPath)
Creates and returns a new Context instance for the specified servletPath. |
void |
reset()
Reset mock internal state. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public ClickServlet getServlet()
ClickServlet instance for this
context.
public MockRequest getMockRequest()
MockRequest instance for this
context.
public static MockContext initContext()
public static MockContext initContext(String servletPath)
servletPath - the requests servletPath
public static MockContext initContext(Locale locale)
locale - the requests locale
public static MockContext initContext(HttpServletRequest request)
request - the mock request
public static MockContext initContext(Locale locale,
String servletPath)
locale - the requests localeservletPath - the requests servletPath
public static MockContext initContext(MockServletConfig servletConfig,
MockRequest request,
MockResponse response,
ClickServlet clickServlet)
servletConfig - the mock servletConfigrequest - the mock requestresponse - the mock responseclickServlet - the mock clickServlet
public static MockContext initContext(MockServletConfig servletConfig,
MockRequest request,
MockResponse response,
ClickServlet clickServlet,
ActionEventDispatcher actionEventDispatcher,
ControlRegistry controlRegistry)
servletConfig - the mock servletConfigrequest - the mock requestresponse - the mock responseclickServlet - the mock clickServletactionEventDispatcher - action and behavior dispatchercontrolRegistry - the control registry
public boolean executeActionListeners()
public boolean executeBehaviors()
public void executePreResponse()
public void executePreRenderHeadElements()
public void executePreDestroy()
public boolean fireActionEventsAndClearRegistry()
executeActionListeners() instead
public void reset()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||