- - PR -
strutstestでDynaValidatorFormのテストは?
1
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2005-04-11 17:19
strutstestでMockを使用してDynaValidatorFormを使用した物をテストしようとすると
以下のようなエラーになってしまいます。 DynaValidatorFormを使用している場合はMockでのテストはできないのでしょうか? 内容はstrutstestでのサンプルのLoginの部分をLoginFormを使用せずに DynaValidatorFormを使用するように変更しています。 どなたか、DynaValidatorFormでテストをされた方助言いただけますか? 0 [main] INFO org.apache.struts.validator.ValidatorPlugIn - Loading validation rules file from '/WEB-INF/validator-rules.xml' 60 [main] INFO org.apache.struts.validator.ValidatorPlugIn - Loading validation rules file from '/WEB-INF/validation.xml' 240 [main] ERROR org.apache.struts.validator.DynaValidatorForm - org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest) org.apache.commons.validator.ValidatorException: org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest) at org.apache.commons.validator.ValidatorAction.loadValidationMethod(ValidatorAction.java:627) at org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:557) at org.apache.commons.validator.Field.validateForRule(Field.java:811) at org.apache.commons.validator.Field.validate(Field.java:890) at org.apache.commons.validator.Form.validate(Form.java:174) at org.apache.commons.validator.Validator.validate(Validator.java:367) at org.apache.struts.validator.DynaValidatorForm.validate(DynaValidatorForm.java:110) at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:919) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:204) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1169) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:413) at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:394) at test.TestLoginAction.testSuccessfulLogin(TestLoginAction.java:41) 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:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) |
|
投稿日時: 2005-04-11 18:54
よく見たらweb.xmlでstruts ActionServletの初期パラメータが
<init-param> <param-name>validating</param-name> <param-value>false</param-value> </init-param> になっていたので、trueに変更しました。 しかし、まだエラーになります。今度はエラーコードが違います。 0 [main] INFO org.apache.struts.validator.ValidatorPlugIn - Loading validation rules file from '/WEB-INF/validator-rules.xml' 10 [main] INFO org.apache.struts.validator.ValidatorPlugIn - Loading validation rules file from '/WEB-INF/validation.xml' 131 [main] ERROR org.apache.struts.validator.DynaValidatorForm - org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest) org.apache.commons.validator.ValidatorException: org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest) at org.apache.commons.validator.ValidatorAction.loadValidationMethod(ValidatorAction.java:627) at org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:557) at org.apache.commons.validator.Field.validateForRule(Field.java:811) at org.apache.commons.validator.Field.validate(Field.java:890) at org.apache.commons.validator.Form.validate(Form.java:174) at org.apache.commons.validator.Validator.validate(Validator.java:367) at org.apache.struts.validator.DynaValidatorForm.validate(DynaValidatorForm.java:110) at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:919) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:204) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1169) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:413) at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:394) at test.TestLoginAction.testSuccessfulLogin(TestLoginAction.java:41) 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:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) |
|
投稿日時: 2005-04-12 18:52
本家の方の英語のサイトを見ていたら動いたというような内容が書かれていたので
以下のようにソースを変更しました。 public void setUp() throws Exception { super.setUp(); setInitParameter("validating","false"); this.setContextDirectory(new File(".")); dvf = new DynaValidatorForm(); } public void testSuccessfulLogin() { setRequestPathInfo("/login"); setActionForm(dvf); addRequestParameter("username","deryl"); addRequestParameter("password","radar"); actionPerform(); verifyForward("success"); verifyForwardPath("/main/success.jsp"); assertEquals("deryl",getSession().getAttribute("authentication")); verifyNoActionErrors(); } しかし、まだエラーが出ます。 1) testSuccessfulLogin(test.TestLoginAction)servletunit.struts.ExceptionDuringTestError: A NullPointerException was thrown. This may indicate an error in your ActionForm, or it may indicate that the Struts ActionServlet was unable to find struts config file. TestCase is running from C:\\eclipse\\workspace\\strutstestcase03 directory. Context directory is C:\\eclipse\\workspace\\strutstestcase03\\.. struts config file must be found under the context directory, the directory the test case is running from, or in the classpath. at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:407) at test.TestLoginAction.testSuccessfulLogin(TestLoginAction.java:46) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at test.TestLoginAction.main(TestLoginAction.java:69) ------------ Root Cause: ------------ java.lang.NullPointerException at org.apache.struts.util.RequestUtils.canReuseActionForm(RequestUtils.java:244) at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:183) at org.apache.struts.action.RequestProcessor.processActionForm(RequestProcessor.java:319) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:202) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1169) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:413) at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:394) at test.TestLoginAction.testSuccessfulLogin(TestLoginAction.java:46) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at test.TestLoginAction.main(TestLoginAction.java:69) |
1