public class MockAction extends Object implements Action
A mock for facilitating action testing. It internally creates mocks for the input, output, session and context.
Example:
MyAction action = new MyAction();
Input input = new InputMap();
Output output = new OutputMap();
Context session = new ContextMap();
Context application = new ContextMap();
action.setInput(input);
action.setOutput(output);
action.setSession(session);
action.setApplication(application);
input.setValue("asdasdas", someValue)/
String result = action.execute();
assertEqual(result, "balblablablal");
assertEqual(output.getValue("asdasd"), "asdasdasdasdas");
with the mock:
MyAction action = new MyAction();
MockAction mockAction = new MockAction(action);
mockAction.getInput().setValue("asdsaxa", adsdasdas);
String result = mockAction.execute();
assertEqual(result, "balblablablal");
assertEqual(mockAction.getOutput().getValue("asdasd"), "asdasdasdasdas");
| Constructor and Description |
|---|
MockAction() |
MockAction(Action action) |
MockAction(Class<? extends Object> klass) |
| Modifier and Type | Method and Description |
|---|---|
String |
callInnerAction(String innerAction) |
String |
execute() |
Action |
getAction() |
Context |
getApplication()
Gets this action application context.
|
Context |
getCookies()
Gets the cookie context for this action.
|
Input |
getInput()
Gets the action input.
|
Locale |
getLocale()
Gets the use locale for this action.
|
static <E> E |
getMockAction(Class<? extends E> klass)
Creates a mock action from the given class, returning
a new instance of the given class that can be used
as a regular action, but it is actually a mock action.
|
Output |
getOutput()
Gets the action output.
|
Context |
getSession()
Gets this action session context.
|
static void |
init(Action action) |
void |
setApplication(Context application)
Sets the application context for this action.
|
void |
setCookies(Context context)
Sets the cookie context for this action.
|
void |
setInput(Input input)
Sets the input for this action.
|
void |
setLocale(Locale locale)
Sets the user locale for this action.
|
void |
setOutput(Output output)
Sets the output for this action.
|
void |
setSession(Context session)
Sets the session context for this action.
|
public MockAction(Action action)
public MockAction()
public static <E> E getMockAction(Class<? extends E> klass)
E - klass - Exceptionpublic static void init(Action action)
public String callInnerAction(String innerAction) throws Exception
Exceptionpublic Action getAction()
public Context getApplication()
ActiongetApplication in interface Actionpublic void setApplication(Context application)
ActionsetApplication in interface Actionapplication - The context to be setpublic void setInput(Input input)
Actionpublic Locale getLocale()
Actionpublic void setLocale(Locale locale)
Actionpublic Output getOutput()
Actionpublic void setOutput(Output output)
Actionpublic Context getSession()
ActiongetSession in interface Actionpublic void setSession(Context session)
ActionsetSession in interface Actionsession - The context to be setpublic Context getCookies()
ActiongetCookies in interface Actionpublic void setCookies(Context context)
ActionsetCookies in interface Actioncontext - The cookie context to be setCopyright © 2015. All Rights Reserved.