org.chwf.servlet.mock
Class ControllerTestCase

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--junit.framework.TestCase
              |
              +--org.chwf.servlet.mock.ReflectingTestCase
                    |
                    +--org.chwf.servlet.mock.ServletTestCase
                          |
                          +--org.chwf.servlet.mock.ControllerTestCase
All Implemented Interfaces:
junit.framework.Test

public class ControllerTestCase
extends ServletTestCase

A test case for controllers that sets up mock objects for servlets and initializes and releases data in the ServletData class. If you define your own setUp() and tearDown() methods in subclasses of the ControllerTestCase, be sure to invoke the superclass's methods:

 public class MyControllerTest extends ControllerTestCase {
   private MyController myController = null;
   private InvocationContext context = null;
 
   public MyControllerTest(String name) {
     super(name);
   }
 
   protected void setUp() {
     super.setUp();
     this.myController = new MyController();
     this.context = myController.initContext();
     // Other setup
   }
 }
You can test the results of redirect operations inside the controller with the getView() method of the InvocationContext:
 public void testRedirect() throws Exception {
   myContext.commandMethod();
   String view = context.getView();
   assertEquals("expected-page.jsp", view);
 }

Author:
Paul Strack

Constructor Summary
ControllerTestCase(java.lang.String name)
          Constructor for ControllerTestCase.
ControllerTestCase(java.lang.String name, java.lang.Class cls)
          Constructor for ControllerTestCase.
 
Method Summary
protected  void setUp()
          This method must be invoked in the setUp() method of subclasses: super.setUp()
protected  void tearDown()
          This method must be invoked in the tearDown() method of subclasses: super.tearDown()
 
Methods inherited from class org.chwf.servlet.mock.ServletTestCase
getApplication, getConfig, getOut, getOutput, getPageContext, getRequest, getResponse
 
Methods inherited from class org.chwf.servlet.mock.ReflectingTestCase
testWhetherAllMethodsAreTested, testWhetherClassAndTestNameMatches
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ControllerTestCase

public ControllerTestCase(java.lang.String name)
Constructor for ControllerTestCase. Non-reflecting test.
Parameters:
name - Test name

ControllerTestCase

public ControllerTestCase(java.lang.String name,
                          java.lang.Class cls)
Constructor for ControllerTestCase. Reflecting test.
Parameters:
name - Test name.
cls - Tested class.
Method Detail

setUp

protected void setUp()
              throws java.lang.Exception
This method must be invoked in the setUp() method of subclasses: super.setUp()
Overrides:
setUp in class ServletTestCase
Throws:
java.lang.Exception - for errors.

tearDown

protected void tearDown()
                 throws java.lang.Exception
This method must be invoked in the tearDown() method of subclasses: super.tearDown()
Overrides:
tearDown in class ServletTestCase
Throws:
java.lang.Exception - for errors.


Copyright © 2002-2004, Paul Strack. All Rights Reserved.