com.mockrunner.example.struts.LogoutActionTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.example.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import com.mockrunner.example.servlet.ImageButtonFilter;
import com.mockrunner.servlet.ServletTestModule;
import com.mockrunner.struts.ActionTestCaseAdapter;
/**
* Example test for {@link LogoutAction}. Demonstrates the testing of
* actions with specified filters. Also demonstrates how to prepare
* custom action mappings in tests. Please note that the use of
* custom action mappings relies on CGLib.
*/
public class LogoutActionTest extends ActionTestCaseAdapter
{
private ServletTestModule servletModule;
private LogoutActionMapping logoutMapping;
protected void setUp() throws Exception
{
super.setUp();
servletModule = createServletTestModule();
logoutMapping = (LogoutActionMapping)getActionMockObjectFactory().prepareActionMapping(LogoutActionMapping.class);
}
public void testLogout() throws Exception
{
logoutMapping.setRequestParameterName("logout");
addRequestParameter("logout.x", "11");
addRequestParameter("logout.y", "11");
servletModule.createFilter(ImageButtonFilter.class);
servletModule.setDoChain(true);
servletModule.doFilter();
getActionMockObjectFactory().addRequestWrapper(new HttpServletRequestWrapper((HttpServletRequest)servletModule.getFilteredRequest()));
actionPerform(LogoutAction.class);
assertFalse(getActionMockObjectFactory().getMockSession().isValid());
}
}