org.mentawai.util
Class MockAction

java.lang.Object
  extended by org.mentawai.util.MockAction
All Implemented Interfaces:
Action

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:

Testing the action without this mock:
 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");
 

Author:
Rubem Azenha

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, NOT_FOUND, 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
<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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockAction

public MockAction(Action action)

MockAction

public MockAction(Class<? extends Object> klass)

MockAction

public MockAction()
Method Detail

getMockAction

public 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.

Type Parameters:
E -
Parameters:
klass -
Returns:
action
Throws:
Exception

init

public static void init(Action action)

execute

public String execute()
               throws Exception
Throws:
Exception

callInnerAction

public String callInnerAction(String innerAction)
                       throws Exception
Throws:
Exception

getAction

public Action getAction()

getApplication

public Context getApplication()
Description copied from interface: Action
Gets this action application context.

Specified by:
getApplication in interface Action
Returns:
The application context

setApplication

public void setApplication(Context application)
Description copied from interface: Action
Sets the application context for this action.

Specified by:
setApplication in interface Action
Parameters:
application - The context to be set

getInput

public Input getInput()
Description copied from interface: Action
Gets the action input.

Specified by:
getInput in interface Action
Returns:
The action input

setInput

public void setInput(Input input)
Description copied from interface: Action
Sets the input for this action.

Specified by:
setInput in interface Action
Parameters:
input - the input to be set

getLocale

public Locale getLocale()
Description copied from interface: Action
Gets the use locale for this action.

Specified by:
getLocale in interface Action
Returns:
The user locale

setLocale

public void setLocale(Locale locale)
Description copied from interface: Action
Sets the user locale for this action.

Specified by:
setLocale in interface Action
Parameters:
locale - The user locale to set.

getOutput

public Output getOutput()
Description copied from interface: Action
Gets the action output.

Specified by:
getOutput in interface Action
Returns:
The action output

setOutput

public void setOutput(Output output)
Description copied from interface: Action
Sets the output for this action.

Specified by:
setOutput in interface Action
Parameters:
output - the output to be set

getSession

public Context getSession()
Description copied from interface: Action
Gets this action session context.

Specified by:
getSession in interface Action
Returns:
The session context

setSession

public void setSession(Context session)
Description copied from interface: Action
Sets the session context for this action.

Specified by:
setSession in interface Action
Parameters:
session - The context to be set

getCookies

public Context getCookies()
Description copied from interface: Action
Gets the cookie context for this action.

Specified by:
getCookies in interface Action
Returns:
The cookie context

setCookies

public void setCookies(Context context)
Description copied from interface: Action
Sets the cookie context for this action.

Specified by:
setCookies in interface Action
Parameters:
context - The cookie context to be set


Copyright © 2013. All Rights Reserved.