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 setUpMessage() {
                // リクエストパラメータのセット
                getRequest().addParameter("name", "name1");
        }
 
        public void testMessage() throws Exception {
                // アクションの実行
                ActionResult result = processAction("/hello/message");
                // 結果のチェック
                assertPathEquals(Forward.class, "result.jsp", result);
                // 実行後のアクションの状態を確認
                assertEquals("name1", action.name);
        }
 }
 
 public class TodoActionTest extends CubbyTestCase {
 
        private TodoAction action;
 
        public void setUpShow() throws Exception {
                emulateLogin();
        }
 
        private void emulateLogin() throws Exception {
                User user = new User();
                user.setId("mock");
                user.setName("mock");
                user.setPassword("mock");
                getRequest().getSession().setAttribute("user", user);
        }
 
        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の型とパスをチェックします。
static void assertPathEquals(Class<? extends ActionResult> resultClass, String expectedPath, ActionResult actualResult, String characterEncoding)
          ActionResultの型とパスをチェックします。
protected  ActionResult processAction(String originalPath)
          アクションメソッドを実行します。
protected  String routing(MockHttpServletRequest request, MockHttpServletResponse response)
          CubbyFilterで行っているルーティングをエミュレートして、内部フォワードパスをリクエストにセットします。
protected  String routing(String orginalPath)
          推奨されていません。 
protected  void setupThreadContext()
          ThreadContextにリクエストをセットします。
 
クラス 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

assertPathEquals

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

パラメータ:
resultClass - ActionResultの型
expectedPath - 期待されるパス
actualResult - チェックするActionResult
characterEncoding - URI のエンコーディング

processAction

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

パラメータ:
originalPath - オリジナルパス
戻り値:
アクションメソッドの実行結果。アクションメソッドが見つからなかったり結果がない場合は null
例外:
Exception - アクションメソッドの実行時に例外が発生した場合

routing

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

パラメータ:
request - リクエスト
response - レスポンス
戻り値:
内部フォワードパス
導入されたバージョン:
1.0.5

setupThreadContext

protected void setupThreadContext()
ThreadContextにリクエストをセットします。


routing

@Deprecated
protected String routing(String orginalPath)
推奨されていません。 

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

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


Copyright © 2006-2009 The Seasar Foundation. All Rights Reserved.