トップ «前の日記(2007-12-29 (Sat)) 最新 次の日記(2008-01-01 (Tue))» 編集

ふたつの川うるおう日記


2007-12-31 (Mon)

_ [Java][Seasar] 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 の良いとこどりがあれば良いのかも?

| Bookmark:
本日のツッコミ(全2件) [ツッコミを入れる]
_ agata (2008-01-05 (Sat) 17:08)

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

_ jfut (2008-01-05 (Sat) 20:41)

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

[]

| Return to page top | Vicuna CMS - WordPress Theme - Vicuna Ninja Style for tDiary |