Return-Path: Delivered-To: apmail-incubator-beehive-user-archive@www.apache.org Received: (qmail 55370 invoked from network); 8 Jun 2005 18:14:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 Jun 2005 18:14:29 -0000 Received: (qmail 57172 invoked by uid 500); 8 Jun 2005 18:14:27 -0000 Delivered-To: apmail-incubator-beehive-user-archive@incubator.apache.org Received: (qmail 57118 invoked by uid 500); 8 Jun 2005 18:14:26 -0000 Mailing-List: contact beehive-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Beehive Users" Delivered-To: mailing list beehive-user@incubator.apache.org Received: (qmail 57098 invoked by uid 99); 8 Jun 2005 18:14:25 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from palrel13.hp.com (HELO palrel13.hp.com) (156.153.255.238) by apache.org (qpsmtpd/0.28) with ESMTP; Wed, 08 Jun 2005 11:14:21 -0700 Received: from cacexg13.americas.cpqcorp.net (cacexg13.americas.cpqcorp.net [16.92.1.76]) by palrel13.hp.com (Postfix) with ESMTP id BAD911C05764 for ; Wed, 8 Jun 2005 11:14:09 -0700 (PDT) Received: from cacexc03.americas.cpqcorp.net ([16.92.1.27]) by cacexg13.americas.cpqcorp.net with Microsoft SMTPSVC(6.0.3790.211); Wed, 8 Jun 2005 11:14:09 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: MockStrutsTestCase, action method with form data Date: Wed, 8 Jun 2005 11:14:07 -0700 Message-ID: <4DEF16167D0B3A4889E4C5940F9E5B1C057C6CCC@cacexc03.americas.cpqcorp.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: MockStrutsTestCase, action method with form data thread-index: AcVsS0Q/ZgFv8yzEQAWCjDDXexw4ywACVD7w From: "Yee, Sunny K" To: "Beehive Users" X-OriginalArrivalTime: 08 Jun 2005 18:14:09.0419 (UTC) FILETIME=[DD815DB0:01C56C55] X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi Richard, I subclassed from MockPageFlowTestCase, and ran the test case, resulting in the same exception with a console warning. It doesn't look like that I set the first parameter value correctly to AddUpdateExpression. I tried different values, and each one doesn't work:=20 addUpdateExpression("username", "testuser") addUpdateExpression("actionForm.username", "testuser") addUpdateExpression("LoginForm.username", "testuser") Warning message in console: NetUI Warning: Unable to update expression "{username}". The typical cause is that the object represented by the expression is not available or is the wrong type for updating. Cause: org.apache.beehive.netui.script.ExpressionUpdateException: Exception when attempting to update the expression "{username}" with available binding contexts [actionForm, pageFlow, globalApp]. Root cause: org.apache.beehive.netui.script.IllegalExpressionException: Could not resolve variable named "username" for an expression update. Stack trace: servletunit.struts.ExceptionDuringTestError: An uncaught exception was thrown during actionExecute() at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.j ava:409) at com.hp.frameworks.wpa.test.preprocessor.MockPageFlowTestCase.runAction(M ockPageFlowTestCase.java:84) at com.hp.frameworks.wpa.test.preprocessor.TestPreprocessor.testRequestWith Form(TestPreprocessor.java:80) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) 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(RemoteTe stRunner.java:474) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun ner.java:342) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu nner.java:194) ------------ Root Cause: ------------ javax.servlet.ServletException: Could not find matching action method for action=3DdoLogin, form=3D[none] in page flow /com/hp/frameworks/wpa/test/preprocessor/Controller.jpf. at org.apache.beehive.netui.pageflow.internal.DefaultExceptionsHandler.hand leException(DefaultExceptionsHandler.java:188) at org.apache.beehive.netui.pageflow.FlowController.handleException(FlowCon troller.java:258) at org.apache.beehive.netui.pageflow.FlowController.internalExecute(FlowCon troller.java:442) at org.apache.beehive.netui.pageflow.PageFlowController.internalExecute(Pag eFlowController.java:282) at org.apache.beehive.netui.pageflow.FlowController.execute(FlowController. java:306) at org.apache.beehive.netui.pageflow.internal.FlowControllerAction.execute( FlowControllerAction.java:48) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestPr ocessor.java:421) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.access$201(Pa geFlowRequestProcessor.java:109) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor$ActionRunner. execute(PageFlowRequestProcessor.java:1979) at org.apache.beehive.netui.pageflow.interceptor.action.internal.ActionInte rceptors$WrapActionInterceptorChain.continueChain(ActionInterceptors.jav a:63) at org.apache.beehive.netui.pageflow.interceptor.action.internal.ActionInte rceptors.wrapAction(ActionInterceptors.java:86) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processAction Perform(PageFlowRequestProcessor.java:2048) at com.hp.frameworks.wpa.pageflow.action.WpaPageFlowRequestProcessor.proces sActionPerform(WpaPageFlowRequestProcessor.java:120) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java: 226) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processIntern al(PageFlowRequestProcessor.java:592) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.process(PageF lowRequestProcessor.java:856) at org.apache.beehive.netui.pageflow.AutoRegisterActionServlet.process(Auto RegisterActionServlet.java:600) at org.apache.beehive.netui.pageflow.PageFlowActionServlet.process(PageFlow ActionServlet.java:163) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415) at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.j ava:394) at com.hp.frameworks.wpa.test.preprocessor.MockPageFlowTestCase.runAction(M ockPageFlowTestCase.java:84) at com.hp.frameworks.wpa.test.preprocessor.TestPreprocessor.testRequestWith Form(TestPreprocessor.java:80) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) 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(RemoteTe stRunner.java:474) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun ner.java:342) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu nner.java:194) ------------ Root Cause: ------------ org.apache.beehive.netui.pageflow.NoMatchingActionMethodException: Could not find matching action method for action=3DdoLogin, form=3D[none] in = page flow /com/hp/frameworks/wpa/test/preprocessor/Controller.jpf. at org.apache.beehive.netui.pageflow.FlowController.getActionMethodForward( FlowController.java:761) at org.apache.beehive.netui.pageflow.FlowController.internalExecute(FlowCon troller.java:425) at org.apache.beehive.netui.pageflow.PageFlowController.internalExecute(Pag eFlowController.java:282) at org.apache.beehive.netui.pageflow.FlowController.execute(FlowController. java:306) at org.apache.beehive.netui.pageflow.internal.FlowControllerAction.execute( FlowControllerAction.java:48) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestPr ocessor.java:421) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.access$201(Pa geFlowRequestProcessor.java:109) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor$ActionRunner. execute(PageFlowRequestProcessor.java:1979) at org.apache.beehive.netui.pageflow.interceptor.action.internal.ActionInte rceptors$WrapActionInterceptorChain.continueChain(ActionInterceptors.jav a:63) at org.apache.beehive.netui.pageflow.interceptor.action.internal.ActionInte rceptors.wrapAction(ActionInterceptors.java:86) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processAction Perform(PageFlowRequestProcessor.java:2048) at com.hp.frameworks.wpa.pageflow.action.WpaPageFlowRequestProcessor.proces sActionPerform(WpaPageFlowRequestProcessor.java:120) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java: 226) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processIntern al(PageFlowRequestProcessor.java:592) at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.process(PageF lowRequestProcessor.java:856) at org.apache.beehive.netui.pageflow.AutoRegisterActionServlet.process(Auto RegisterActionServlet.java:600) at org.apache.beehive.netui.pageflow.PageFlowActionServlet.process(PageFlow ActionServlet.java:163) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415) at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.j ava:394) at com.hp.frameworks.wpa.test.preprocessor.MockPageFlowTestCase.runAction(M ockPageFlowTestCase.java:84) at com.hp.frameworks.wpa.test.preprocessor.TestPreprocessor.testRequestWith Form(TestPreprocessor.java:80) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) 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(RemoteTe stRunner.java:474) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun ner.java:342) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu nner.java:194) -Sunny -----Original Message----- From: Richard Feit [mailto:richard.feit@bea.com]=20 Sent: Wednesday, June 08, 2005 9:55 AM To: Beehive Users Subject: Re: MockStrutsTestCase, action method with form data Hi Sunny, We do use a derivative of MockStrutsTestCase in our automated tests. =20 It's not ready for prime-time release, but it may be enough to get you up and running. I'll paste it below (this list doesn't accept attachments). 1) Does using this help with your problem? To update the form bean, you'd call addUpdateExpression("actionForm.username") rather than addRequestParameter(). Then you'd call runAction("processData"). 2) If that doesn't help, would you paste in the entire stacktrace from the log (including any "Caused by:" pieces)? MockPageFlowTestCase.java: --- import org.apache.beehive.netui.pageflow.PageFlowActionServlet; import servletunit.struts.MockStrutsTestCase; import servletunit.HttpServletRequestSimulator; import junit.framework.AssertionFailedError; /** * Base class for Page Flow test cases running under StrutsTestCase/JUnit. */ public abstract class MockPageFlowTestCase extends MockStrutsTestCase { protected void setUp() throws Exception { super.setUp(); setActionServlet( new PageFlowActionServlet() ); =20 // The page flow class must be on classpath; if not, assert. try { Class.forName( getPageFlowClassName() ); } catch ( ClassNotFoundException e ) { throw new AssertionFailedError( "Page flow class " + getPageFlowClassName() + " not found." ); } } protected void tearDown() throws Exception { super.tearDown(); } =20 /** * Get the fully-qualified class name for the page flow to be tested. */ protected abstract String getPageFlowClassName(); =20 /** * Get the webapp name, to be used in constructing the request URI. It is rarely necessary to specify this; it * defaults to "mockPageFlowWebapp". */ protected String getWebappName() { return "mockPageFlowWebapp"; } =20 /** * Run the given action on the page flow determined by {@link #getPageFlowClassName}. */ protected void runAction( String actionName ) { String modulePath =3D getPageFlowClassName().replace( '.', '/' = ); int lastSlash =3D modulePath.lastIndexOf( '/' ); String actionPath =3D '/' + actionName + ".do"; HttpServletRequestSimulator mockRequest =3D getMockRequest(); =20 // // Set up the request path-info and request servlet-path. The logic differs when the page flow is the root // module (the second case, below. // if ( lastSlash !=3D -1 ) { modulePath =3D modulePath.substring( 0, lastSlash ); setRequestPathInfo( modulePath, actionPath ); mockRequest.setServletPath( modulePath + actionPath ); } else { assertTrue( false ); setRequestPathInfo( actionPath ); mockRequest.setServletPath( actionPath ); } =20 mockRequest.setRequestURI( '/' + getWebappName() + mockRequest.getServletPath() ); =20 actionPerform(); } =20 /** * Add an update expression and the value to be set. * @param expression the update expression, e.g., "actionForm.foo". * @param value the value to be set. */ protected void addUpdateExpression( String expression, String value ) { addRequestParameter( '{' + expression + '}', new String[]{ value } ); } =20 protected MockPageFlowTestCase( String name ) { super( name ); } } --- -Rich Yee, Sunny K wrote: >Hi, > >I'm using MockStrutsTestCase to write a pageflow test case, and have a >simple action method with a form parameter in my controller. I set the >form data in the test case method using the addRequestParameter method, >but the pageflow controller doesn't recognize it (that it is for the=20 >form parameter), and looks for the action method with no form parameter. >Am I missing something in my test case code, or is the page flow=20 >controller, in working with the MockStrutsTestCase, not translating the >request parameter to a form object? > >Thanks in advance. >Sunny Yee >Hewlett-Packard Co. >=20 > >Junit message: > >javax.servlet.ServletException: Could not find matching action method=20 >for action=3DdoLogin, form=3D[none] in page flow=20 >/com/hp/frameworks/wpa/test/preprocessor/Controller.jpf. > at >org.apache.beehive.netui.pageflow.internal.DefaultExceptionsHandler.han >d >leException(DefaultExceptionsHandler.java:188) > at >org.apache.beehive.netui.pageflow.FlowController.handleException(FlowCo >n >troller.java:258) > at >org.apache.beehive.netui.pageflow.FlowController.internalExecute(FlowCo >n >troller.java:442) > at >org.apache.beehive.netui.pageflow.PageFlowController.internalExecute(Pa >g >eFlowController.java:282) > at >org.apache.beehive.netui.pageflow.FlowController.execute(FlowController . >java:306) > at >org.apache.beehive.netui.pageflow.internal.FlowControllerAction.execute >( >FlowControllerAction.java:48) > at >org.apache.struts.action.RequestProcessor.processActionPerform(RequestP >r >ocessor.java:421) > ... > > >My MockStrutsTestCase test case method: > > public void testRequestWithForm() > { =20 > this.getMockRequest().setServletPath("/processData.do"); > this.setRequestPathInfo(null, "/processData.do"); > =09 > // Is this sufficient to set the form data? > > this.addRequestParameter("username", "testuser"); > this.actionPerform(); > =09 > ... > > } > >My Controller.java: > > ... > @Jpf.Action( > forwards=3D{ > @Jpf.Forward(name=3D"success", path=3D"index.jsp"), > @Jpf.Forward(name=3D"login", path=3D"login.jsp") > } > ) > > // This is the action that I want call. > > public Forward processData(LoginForm loginForm) > { > if (loginForm.getUsername().equals("test") =3D=3D true) > return new Forward("success"); > else > return new Forward("login"); > } > ... > >My LoginForm.java: > > import org.apache.struts.action.ActionForm; > > > public class LoginForm extends ActionForm { >=09 > private String username; >=09 > public String getUsername() { > return username; > } >=09 > public void setUsername(String username) { > this.username =3D username; > } > > } > > =20 >