|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.Context net.sf.click.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 callback form.onProcess(); // Check that nameField value is now bound to request value Assert.assertEquals(requestValue, nameField.getValueObject()); }
Field Summary |
Fields inherited from class net.sf.click.Context |
config, context, isPost, LOCALE, response |
Method Summary | |
boolean |
fireActionEventsAndClearRegistry()
Fire all action events that was registered by the processed Controls, and clears all registered listeners from the ControlRegistry. |
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,
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. |
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 requets 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, ControlRegistry controlRegistry)
servletConfig
- the mock servletConfigrequest
- the mock requestresponse
- the mock responseclickServlet
- the mock clickServletcontrolRegistry
- the controlRegistry instance
public boolean fireActionEventsAndClearRegistry()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |