Home > Java | Seasar > Cubby入門中

Cubby入門中


CubbyのRESTっぽいURIが個人的に激しく良いです。でも、Actionの単体テストがどうしたら良いかよくわからないです。org.seasar.cubby.examples.todo.action.LoginActionに対して次のようなテストを書くと。

public class LoginActionTest extends S2TigerTestCase {
    private LoginAction loginAction;

    protected void setUp() throws Exception {
        include("app.dicon");
    }

    public void testLogin() {
        loginAction.sessionScope = new HashMap<String, Object>();
        loginAction.userId = "test";
        loginAction.password = "test";
        loginAction.process();
        assertEquals(1, loginAction.sessionScope.size());
    }
}

次のぬるぽが出ちゃってテスト出来ません。

java.lang.NullPointerException
    at org.seasar.cubby.controller.impl.ActionContextImpl.getAction(ActionContextImpl.java:63)
    at org.seasar.cubby.controller.impl.ActionContextImpl.getFormBean(ActionContextImpl.java:92)
    at org.seasar.cubby.interceptor.InitializeInterceptor.setupForm(InitializeInterceptor.java:68)
    at org.seasar.cubby.interceptor.InitializeInterceptor.invoke(InitializeInterceptor.java:43)
    at org.seasar.framework.aop.impl.NestedMethodInvocation.proceed(NestedMethodInvocation.java:53)
    at org.seasar.framework.container.customizer.AspectCustomizer$LookupAdaptorInterceptor.invoke
      (AspectCustomizer.java:195)
    at org.seasar.cubby.examples.todo.action.LoginAction$$EnhancedByS2AOP$$787d6a$$MethodInvocation$$process2.proceed
      (MethodInvocationClassGenerator.java)
    at org.seasar.extension.tx.RequiredInterceptor.invoke(RequiredInterceptor.java:48)
    at org.seasar.cubby.examples.todo.action.LoginAction$$EnhancedByS2AOP$$787d6a$$MethodInvocation$$process2.proceed
      (MethodInvocationClassGenerator.java)
    at org.seasar.cubby.examples.todo.action.LoginAction$$EnhancedByS2AOP$$787d6a.process
      (LoginAction$$EnhancedByS2AOP$$787d6a.java)
    at org.seasar.cubby.examples.todo.action.LoginActionTest.testLogin(LoginActionTest.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:168)
    at org.seasar.framework.unit.S2FrameworkTestCase.doRunTest(S2FrameworkTestCase.java:519)
    at org.seasar.extension.unit.S2TestCase.doRunTest(S2TestCase.java:103)
    at org.seasar.framework.unit.S2TigerTestCase.doRunTest(S2TigerTestCase.java:82)
    at org.seasar.framework.unit.S2FrameworkTestCase.runBare(S2FrameworkTestCase.java:308)
    at org.seasar.framework.unit.S2TigerTestCase.runBare(S2TigerTestCase.java:66)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

とりあえずValidationだけをテストするか、Helper MethodもしくはServiceとして実装してそっちでテストかな?。SAStrutsだと返り値がパスを表したStringなので単体テストしやすいです。

と、RESTっぽいURIを持つCubbyとSAStruts の良いとこどりがあれば良いのかも?

この記事に関連する別の記事:

  1. COOL deploy時のサブアプリケーションのコンポーネント名がまずいかも (解決) ...
  2. S2Struts HotDeployでActionConfigのパス修正への道 (5) ...
  3. コンストラクタを探さないでー (解決) ...
  4. S2StrutsV1.3.0-beta-2に入れ替えてみる (解決) ...
  5. Windows Vista 64-bit版でEclipse とりあえず大学の環境をWindows Vista 64-bit版に移行しました。だいたい問題無く、これなら大丈夫かなーっと思ってたらEclipseがとても大丈夫じゃありませんでした。 OK: JDK 1.4.2_16 3 [...]...

コメント:2

agata 08-01-06 (日) 17:08

Actionの単体テスト対応したいと思います。
と、RESTっぽいURIを持つCubbyとSAStruts の良いとこどりがあれば良いのかも?>ほんとそうですね。
Restletとか選択肢が増えていますが、せっかくなのでCubbyらしさを追求したいなと思っています。

jfut 08-01-06 (日) 20:41

単体テスト対応の予定ありがとうございます。
tokenや同一クラス内の機能ごとのvalidationなど今でも結構良いCubbyらしさ出てると思います。

コメントフォーム
Remember personal info

トラックバック:0

このエントリーのトラックバックURL
http://jfut.integ.jp/2007/12/31/cubby%E5%85%A5%E9%96%80%E4%B8%AD/trackback/
Listed below are links to weblogs that reference
Cubby入門中 from ふたつの川うるおう日記

Home > Java | Seasar > Cubby入門中

検索
フィード
メタ情報

Return to page top