|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mentawai.util.MockAction
public class MockAction
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");
| Field Summary |
|---|
| Fields inherited from interface org.mentawai.core.Action |
|---|
ACCESSDENIED, ADD, AJAX, ALREADY, BACK, BLOCKED, CREATED, EDIT, ERROR, EXCEPTION, HTML, INDEX, JSON, JSP, LIST, LOGIN, MAIN, NEXT, NULL, REMOVED, SHOW, STREAM, SUCCESS, TEST, UPDATED, XML |
| Constructor Summary | |
|---|---|
MockAction()
|
|
MockAction(Action action)
|
|
MockAction(Class<? extends Object> klass)
|
|
| Method Summary | ||
|---|---|---|
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
|
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. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MockAction(Action action)
public MockAction(Class<? extends Object> klass)
public MockAction()
| Method Detail |
|---|
public static <E> E getMockAction(Class<? extends E> klass)
E - klass -
Exceptionpublic static void init(Action action)
public String execute()
throws Exception
Exception
public String callInnerAction(String innerAction)
throws Exception
Exceptionpublic Action getAction()
public Context getApplication()
Action
getApplication in interface Actionpublic void setApplication(Context application)
Action
setApplication in interface Actionapplication - The context to be setpublic Input getInput()
Action
getInput in interface Actionpublic void setInput(Input input)
Action
setInput in interface Actioninput - the input to be setpublic Locale getLocale()
Action
getLocale in interface Actionpublic void setLocale(Locale locale)
Action
setLocale in interface Actionlocale - The user locale to set.public Output getOutput()
Action
getOutput in interface Actionpublic void setOutput(Output output)
Action
setOutput in interface Actionoutput - the output to be setpublic Context getSession()
Action
getSession in interface Actionpublic void setSession(Context session)
Action
setSession in interface Actionsession - The context to be setpublic Context getCookies()
Action
getCookies in interface Actionpublic void setCookies(Context context)
Action
setCookies in interface Actioncontext - The cookie context to be set
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||