org.seasar.cubby.unit
クラス CubbyTestCase

java.lang.Object
  上位を拡張 junit.framework.Assert
      上位を拡張 junit.framework.TestCase
          上位を拡張 org.seasar.framework.unit.S2FrameworkTestCase
              上位を拡張 org.seasar.extension.unit.S2TestCase
                  上位を拡張 org.seasar.framework.unit.S2TigerTestCase
                      上位を拡張 org.seasar.cubby.unit.CubbyTestCase
すべての実装されたインタフェース:
junit.framework.Test

public abstract class CubbyTestCase
extends S2TigerTestCase

CubbyのActionクラスの単体テスト用のクラスです。

このクラスを継承して、それぞれのActionクラス用の単体テストを作成します。 詳細はCubbyドキュメントの「アクションのテスト」を参照下さい。

 public class HelloActionTest extends CubbyTestCase {
        // 対象のアクション
        private HelloAction action;
 
        // 初期化処理
        protected void setUp() throws Exception {
                // diconファイルの読み込み
                include("app.dicon");
        }
 
        public void testIndex() throws Exception {
                // アクションの実行
                ActionResult result = processAction("/hello/");
                // 結果のチェック
                assertPathEquals(Forward.class, "input.jsp", result);
        }
 
        public void testMessage() throws Exception {
                // リクエストパラメータのセット
                getRequest().addParameter("name", "name1");
                // アクションの実行
                ActionResult result = processAction("/hello/message");
                // 結果のチェック
                assertPathEquals(Forward.class, "result.jsp", result);
                // 実行後のアクションの状態を確認
                assertEquals("name1", action.name);
        }
 }
 
 public class TodoActionTest extends CubbyTestCase {
        private TodoAction action;
 
        protected void setUp() throws Exception {
                include("app.dicon");
                RunDdlServletRequestListener listener = new RunDdlServletRequestListener();
                listener.requestInitialized(null);
        }
 
        @Override
        protected void setUpAfterBindFields() throws Throwable {
                super.setUpAfterBindFields();
                getRequest().addParameter("userId", "test");
                getRequest().addParameter("password", "test");
                // 後続のテストを実行するためにログインアクションを実行
                assertPathEquals(Redirect.class, "/todo/",
                                processAction("/todo/login/process"));
        }
 
        public void testShow() throws Exception {
                this.readXlsAllReplaceDb("TodoActionTest_PREPARE.xls");
                // CoolURIの場合のテスト
                ActionResult result = processAction("/todo/1");
                assertPathEquals(Forward.class, "show.jsp", result);
                assertEquals(new Integer(1), action.id);
                assertEquals("todo1", action.text);
                assertEquals("todo1 memo", action.memo);
                assertEquals(new Integer(1), action.todoType.getId());
                assertEquals("type1", action.todoType.getName());
                assertEquals("2008-01-01", action.limitDate);
        }
 }
 

導入されたバージョン:
1.0.0
作成者:
agata, baba

入れ子のクラスの概要
 
クラス org.seasar.framework.unit.S2TigerTestCase から継承された入れ子のクラス/インタフェース
S2TigerTestCase.Subsequence
 
フィールドの概要
 
クラス org.seasar.framework.unit.S2TigerTestCase から継承されたフィールド
easyMockSupport
 
クラス org.seasar.framework.unit.S2FrameworkTestCase から継承されたフィールド
ENV_PATH, ENV_VALUE
 
コンストラクタの概要
CubbyTestCase()
           
 
メソッドの概要
static void assertPathEquals(Class<? extends ActionResult> resultClass, String expectedPath, ActionResult actualResult)
          ActionResultの型とパスをチェックします。
protected  ActionResult processAction(String orginalPath)
          アクションメソッドを実行します。
protected  String routing(String orginalPath)
          CubbyFilterで行っているルーティングをエミュレートして、内部フォワードパスをリクエストにセットします。
 
クラス org.seasar.framework.unit.S2TigerTestCase から継承されたメソッド
addAspecDef, applyMockInterceptor, applyMockInterceptor, createExpression, createMock, createNiceMock, createStrictMock, doRecord, doRunTest, runBare, setUpForEachTestMethod, tearDownForEachTestMethod
 
クラス org.seasar.extension.unit.S2TestCase から継承されたメソッド
assertBeanEquals, assertBeanListEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertMapEquals, assertMapListEquals, deleteDb, deleteTable, getConnection, getDatabaseMetaData, getDataSource, getSqlWriter, needTransaction, readDb, readDbBySql, readDbByTable, readDbByTable, readXls, readXls, readXlsAllReplaceDb, readXlsAllReplaceDb, readXlsReplaceDb, readXlsReplaceDb, readXlsWriteDb, readXlsWriteDb, reload, reload, reloadOrReadDb, setUpAfterContainerInit, setupDataSource, tearDownBeforeContainerDestroy, tearDownDataSource, writeDb, writeXls
 
クラス org.seasar.framework.unit.S2FrameworkTestCase から継承されたメソッド
bindField, bindFields, convertPath, getComponent, getComponent, getComponentDef, getComponentDef, getContainer, getNamingConvention, getOriginalClassLoader, getRequest, getResponse, getRootDicon, getServlet, getServletConfig, getServletContext, getTargetMethod, getTargetName, include, invoke, isAutoBindable, isRegisterNamingConvention, isWarmDeploy, normalizeName, register, register, register, register, register, resolveRootDicon, setRegisterNamingConvention, setRequest, setResponse, setServlet, setServletConfig, setServletContext, setUpAfterBindFields, setUpContainer, setWarmDeploy, tearDownBeforeUnbindFields, tearDownContainer, unbindFields
 
クラス junit.framework.TestCase から継承されたメソッド
countTestCases, createResult, getName, run, run, runTest, setName, setUp, tearDown, toString
 
クラス 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, failNotEquals, failNotSame, failSame, format
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

CubbyTestCase

public CubbyTestCase()
メソッドの詳細

assertPathEquals

public static void assertPathEquals(Class<? extends ActionResult> resultClass,
                                    String expectedPath,
                                    ActionResult actualResult)
ActionResultの型とパスをチェックします。

パラメータ:
resultClass - ActionResultの型
expectedPath - 期待されるパス
actualResult - チェックするActionResult

processAction

protected ActionResult processAction(String orginalPath)
                              throws Exception
アクションメソッドを実行します。

パラメータ:
orginalPath - パス
戻り値:
アクションメソッドの実行結果。アクションメソッドが見つからなかったり結果がない場合、null
例外:
Exception

routing

protected String routing(String orginalPath)
CubbyFilterで行っているルーティングをエミュレートして、内部フォワードパスをリクエストにセットします。

パラメータ:
orginalPath - オリジナルパス
戻り値:
内部フォワードパス


Copyright ツゥ 2006-2008 The Seasar Foundation. All Rights Reserved.