Re: why the code passes Servlet container test but fails in StrutsTestCase
This shouldn't even compile since you're attempting to return a value. On Feb 13, 2016 11:26 PM, "JOSE L MARTINEZ-AVIAL" wrote: > The method execute has void as a return type, instead of a String. > > 2016-02-13 2:26 GMT-05:00 小唐 <644282...@qq.com>: > > > Hi, > > > > I was trying to use StrutsTestCase to write a test for a Bean, which has > a > > member of String[]. The code runs perfectly in servlet container(Tomcat), > > but fails as a mock test. In EditActionTest.java, assertNotNull("The > action > > is null but should not be.", action) still works fine, but String result > = > > actionProxy.execute() returns the result as "error" instead of "success". > > All the related codes are listed below. > > > > Can anyone give me a hint? > > Thanks in advance! Tom > > > > Person.java > > public class Person{ > >String[] models = new String[]{"Ford", "Nissan"}; > > > >public void setModels(String[] models){ > > this.models = models; > >} > > > >public String[] getModels(){ > > return models; > >} > > } > > > > Edit.java > > public class EditAction extends ActionSupport{ > >Person personBean; > > > >public void execute(){ > > return SUCCESS; > >} > > } > > > > struts.xml > > > > > > /edit.jsp > > /thankyou.jsp > > > > > > > > edit.jsp > > <%@ taglib prefix="s" uri="/struts-tags" %> > > > > > > > > > > > > EditActionTest.java > > public class EditActionTest extends StrutsTestCase { > >@Test > >public void testExecuteValidationPasses() throws Exception { > > request.setParameter("personBean.models", new String[]{"Ford", > > "Nissan"}); > > ActionProxy actionProxy = getActionProxy("/edit.action") ; > > EditAction action = (EditAction) actionProxy.getAction(); > > assertNotNull("The action is null but should not be.", action); > > String result = actionProxy.execute(); > > assertEquals("The execute method did not return " + > > ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, > result); > >} > > } >
Re: why the code passes Servlet container test but fails in StrutsTestCase
The method execute has void as a return type, instead of a String. 2016-02-13 2:26 GMT-05:00 小唐 <644282...@qq.com>: > Hi, > > I was trying to use StrutsTestCase to write a test for a Bean, which has a > member of String[]. The code runs perfectly in servlet container(Tomcat), > but fails as a mock test. In EditActionTest.java, assertNotNull("The action > is null but should not be.", action) still works fine, but String result = > actionProxy.execute() returns the result as "error" instead of "success". > All the related codes are listed below. > > Can anyone give me a hint? > Thanks in advance! Tom > > Person.java > public class Person{ >String[] models = new String[]{"Ford", "Nissan"}; > >public void setModels(String[] models){ > this.models = models; >} > >public String[] getModels(){ > return models; >} > } > > Edit.java > public class EditAction extends ActionSupport{ >Person personBean; > >public void execute(){ > return SUCCESS; >} > } > > struts.xml > > > /edit.jsp > /thankyou.jsp > > > > edit.jsp > <%@ taglib prefix="s" uri="/struts-tags" %> > > > > > > EditActionTest.java > public class EditActionTest extends StrutsTestCase { >@Test >public void testExecuteValidationPasses() throws Exception { > request.setParameter("personBean.models", new String[]{"Ford", > "Nissan"}); > ActionProxy actionProxy = getActionProxy("/edit.action") ; > EditAction action = (EditAction) actionProxy.getAction(); > assertNotNull("The action is null but should not be.", action); > String result = actionProxy.execute(); > assertEquals("The execute method did not return " + > ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, result); >} > }
why the code passes Servlet container test but fails in StrutsTestCase
Hi, I was trying to use StrutsTestCase to write a test for a Bean, which has a member of String[]. The code runs perfectly in servlet container(Tomcat), but fails as a mock test. In EditActionTest.java, assertNotNull("The action is null but should not be.", action) still works fine, but String result = actionProxy.execute() returns the result as "error" instead of "success". All the related codes are listed below. Can anyone give me a hint? Thanks in advance! Tom Person.java public class Person{ String[] models = new String[]{"Ford", "Nissan"}; public void setModels(String[] models){ this.models = models; } public String[] getModels(){ return models; } } Edit.java public class EditAction extends ActionSupport{ Person personBean; public void execute(){ return SUCCESS; } } struts.xml /edit.jsp /thankyou.jsp edit.jsp <%@ taglib prefix="s" uri="/struts-tags" %> EditActionTest.java public class EditActionTest extends StrutsTestCase { @Test public void testExecuteValidationPasses() throws Exception { request.setParameter("personBean.models", new String[]{"Ford", "Nissan"}); ActionProxy actionProxy = getActionProxy("/edit.action") ; EditAction action = (EditAction) actionProxy.getAction(); assertNotNull("The action is null but should not be.", action); String result = actionProxy.execute(); assertEquals("The execute method did not return " + ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, result); } }
Re: StrutsTestCase issues with basic jsp via convention plugin
Can you publish the whole project at GitHub instead of the gist? 2014-02-23 18:35 GMT+01:00 John Patrick : > Hi, > > Having some issues around automated testing using struts2-junit-plugin > accessing a jsp via struts2-convention-plugin. > > Basically the following two url's; > http://struts.apache.org/release/2.3.x/docs/convention-plugin.html > http://struts.apache.org/release/2.3.x/docs/struts-2-junit-plugin-tutorial.html > > > ./pom.xml > ./src/main/resources/struts.xml > ./src/main/webapp/WEB-INF/content/hello-world.jsp > ./src/main/webapp/WEB-INF/web.xml > ./src/test/java/tld/example/HelloWorldTest.java > > files at; https://gist.github.com/nhojpatrick/9174445 > > When checking the web app using jetty it works correctly, i.e. > $ mvn clean install ; > $ mvn jetty:run ; > $ curl http://localhost:8080/hello-world > > Any ideas, or is this a potential issue/bug with struts2-junit-plugin? > > Cheers, > John - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
StrutsTestCase issues with basic jsp via convention plugin
Hi, Having some issues around automated testing using struts2-junit-plugin accessing a jsp via struts2-convention-plugin. Basically the following two url's; http://struts.apache.org/release/2.3.x/docs/convention-plugin.html http://struts.apache.org/release/2.3.x/docs/struts-2-junit-plugin-tutorial.html ./pom.xml ./src/main/resources/struts.xml ./src/main/webapp/WEB-INF/content/hello-world.jsp ./src/main/webapp/WEB-INF/web.xml ./src/test/java/tld/example/HelloWorldTest.java files at; https://gist.github.com/nhojpatrick/9174445 When checking the web app using jetty it works correctly, i.e. $ mvn clean install ; $ mvn jetty:run ; $ curl http://localhost:8080/hello-world Any ideas, or is this a potential issue/bug with struts2-junit-plugin? Cheers, John
Re: Does the StrutsTestCase test filters defined in web.xml?
I recommend you use canoo webtest. This is not a unit test tool, but integration test tool. This is the tool used for instance in AppFuse. It has specific pdf verification steps. Cheers, J. On Mon, May 14, 2012 at 5:33 PM, Miguel Almeida wrote: > Hi Steve, > > On Mon, 2012-05-14 at 11:09 +0100, Steve Higham wrote: > > > Hi Miguel, > > > > I haven't used the StrutsSpringTestCase however I have made use of the > StrutsTestCase. > > > > This only tests the interceptor stack / Action / Result. There is no web > server involved and no attempt to render the resulting page. > > Yes, that's what I thought. > > > You could try looking at Apache Cactus or Apache HttpClient to test this > behaviour? Alternatively if you generate the file within Struts then the > StrutsTestCase will suffice. I've generated exports from Struts this way. > > > > Both are no longer maintained (I guess httpclient got replaced with > Apache http components (http://hc.apache.org/ ) but I haven't explored > this yet. > > For this case (testing the pdf output created by the displaytag) I don't > think it'll be worth it to invest in a new testing setup: this is the > only thing that is produced outside the scope of struts and a manual > inspection might suffice. > > However, I do want to explore other tools that are available to test the > http request/response, so I'll look into this further. > > Cheers, > > Miguel Almeida > > > Cheers, > > > > Steve > > > > -Original Message- > > From: Miguel Almeida [mailto:mig...@almeida.at] > > Sent: 14 May 2012 10:16 > > To: user@struts.apache.org > > Subject: Does the StrutsTestCase test filters defined in web.xml? > > > > Dear all, > > > > I am using StrutsSpringTestCase (which extends StrutsTestCase) to > perform some acceptance tests (under the skin). I am also using Displaytag ( > www.displaytag.org/1.2/ ) to build some tables in the view. > > This tag supports excel/pdf export, which uses a filter you configure in > web.xml [1] > > > > The way the filter works is, in short: a (odd looking, numerical) > parameter is added to the request. The filter checks for the existence of > that parameter and, if it exists, creates the pdf/excel. > > > > I want to test the creation of this file (and its contents). However, > when I debug the StrutsSpringTestCase test with a breakpoint on that filter > it does not stop there, so my questions are: > > > > 1) Does the StrutsTestCase not pass through other filters in your > web.xml, and only goes through the struts filter? > > 2) If so, is there anything else in the struts tests that could help me > out? How do you suggest I perform this test? > > > > Thank you, > > > > Miguel Almeida > > > > > > > > [1]- see http://www.displaytag.org/1.2/export_filter.html > > > > > > - > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > > For additional commands, e-mail: user-h...@struts.apache.org > > > > >
Re: Does the StrutsTestCase test filters defined in web.xml?
You can try to use Jetty as an embedded server, take a look on BasePortletTest in Portlet Plugin Regards -- Łukasz http://www.lenart.org.pl/ mobile +48 606 323 122, office +27 11 0838747 Warszawa JUG conference - Confitura http://confitura.pl/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Does the StrutsTestCase test filters defined in web.xml?
Hi Steve, On Mon, 2012-05-14 at 11:09 +0100, Steve Higham wrote: > Hi Miguel, > > I haven't used the StrutsSpringTestCase however I have made use of the > StrutsTestCase. > > This only tests the interceptor stack / Action / Result. There is no web > server involved and no attempt to render the resulting page. Yes, that's what I thought. > You could try looking at Apache Cactus or Apache HttpClient to test this > behaviour? Alternatively if you generate the file within Struts then the > StrutsTestCase will suffice. I've generated exports from Struts this way. > Both are no longer maintained (I guess httpclient got replaced with Apache http components (http://hc.apache.org/ ) but I haven't explored this yet. For this case (testing the pdf output created by the displaytag) I don't think it'll be worth it to invest in a new testing setup: this is the only thing that is produced outside the scope of struts and a manual inspection might suffice. However, I do want to explore other tools that are available to test the http request/response, so I'll look into this further. Cheers, Miguel Almeida > Cheers, > > Steve > > -Original Message- > From: Miguel Almeida [mailto:mig...@almeida.at] > Sent: 14 May 2012 10:16 > To: user@struts.apache.org > Subject: Does the StrutsTestCase test filters defined in web.xml? > > Dear all, > > I am using StrutsSpringTestCase (which extends StrutsTestCase) to perform > some acceptance tests (under the skin). I am also using Displaytag > (www.displaytag.org/1.2/ ) to build some tables in the view. > This tag supports excel/pdf export, which uses a filter you configure in > web.xml [1] > > The way the filter works is, in short: a (odd looking, numerical) parameter > is added to the request. The filter checks for the existence of that > parameter and, if it exists, creates the pdf/excel. > > I want to test the creation of this file (and its contents). However, when I > debug the StrutsSpringTestCase test with a breakpoint on that filter it does > not stop there, so my questions are: > > 1) Does the StrutsTestCase not pass through other filters in your web.xml, > and only goes through the struts filter? > 2) If so, is there anything else in the struts tests that could help me out? > How do you suggest I perform this test? > > Thank you, > > Miguel Almeida > > > > [1]- see http://www.displaytag.org/1.2/export_filter.html > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org >
RE: Does the StrutsTestCase test filters defined in web.xml?
Hi Miguel, I haven't used the StrutsSpringTestCase however I have made use of the StrutsTestCase. This only tests the interceptor stack / Action / Result. There is no web server involved and no attempt to render the resulting page. Therefore I would be surprised if anything from web.xml is called. You could try looking at Apache Cactus or Apache HttpClient to test this behaviour? Alternatively if you generate the file within Struts then the StrutsTestCase will suffice. I've generated exports from Struts this way. Cheers, Steve -Original Message- From: Miguel Almeida [mailto:mig...@almeida.at] Sent: 14 May 2012 10:16 To: user@struts.apache.org Subject: Does the StrutsTestCase test filters defined in web.xml? Dear all, I am using StrutsSpringTestCase (which extends StrutsTestCase) to perform some acceptance tests (under the skin). I am also using Displaytag (www.displaytag.org/1.2/ ) to build some tables in the view. This tag supports excel/pdf export, which uses a filter you configure in web.xml [1] The way the filter works is, in short: a (odd looking, numerical) parameter is added to the request. The filter checks for the existence of that parameter and, if it exists, creates the pdf/excel. I want to test the creation of this file (and its contents). However, when I debug the StrutsSpringTestCase test with a breakpoint on that filter it does not stop there, so my questions are: 1) Does the StrutsTestCase not pass through other filters in your web.xml, and only goes through the struts filter? 2) If so, is there anything else in the struts tests that could help me out? How do you suggest I perform this test? Thank you, Miguel Almeida [1]- see http://www.displaytag.org/1.2/export_filter.html - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Does the StrutsTestCase test filters defined in web.xml?
Dear all, I am using StrutsSpringTestCase (which extends StrutsTestCase) to perform some acceptance tests (under the skin). I am also using Displaytag (www.displaytag.org/1.2/ ) to build some tables in the view. This tag supports excel/pdf export, which uses a filter you configure in web.xml [1] The way the filter works is, in short: a (odd looking, numerical) parameter is added to the request. The filter checks for the existence of that parameter and, if it exists, creates the pdf/excel. I want to test the creation of this file (and its contents). However, when I debug the StrutsSpringTestCase test with a breakpoint on that filter it does not stop there, so my questions are: 1) Does the StrutsTestCase not pass through other filters in your web.xml, and only goes through the struts filter? 2) If so, is there anything else in the struts tests that could help me out? How do you suggest I perform this test? Thank you, Miguel Almeida [1]- see http://www.displaytag.org/1.2/export_filter.html
RE: StrutsTestCase, jUnit and file upload
Thanks to Chris, Gabriel for your comments. I finally got this to work yesterday. A neat solution probably requires refactoring StrutsTestCase and deriving a new class (StrutsMultipartTestCase) from it. In the meantime the following changes will work subject to a couple of limitations: - This only supports upload of a single file - although fairly simple to extend for multiple files. I've use Mockito for a couple of mocks It's not very clean :-( First you need spring-web-x.y.z.jar on your classpath. This comes with the junit plugin. Your test class needs the following override. This is a cut & paste job from StrutsTestCase except for the request creation line. /** * We need to override this method so we can use class * MockMultipartHttpServletRequest for the request. */ @Override protected void initServletMockObjects() { servletContext = new MockServletContext(resourceLoader); response = new MockHttpServletResponse(); request = new MockMultipartHttpServletRequest(); pageContext = new MockPageContext(servletContext, request, response); } We now need a new version of getActionProxy with additional parameters as follows: - /** * We need our own version to handle the file uploading * @param uri struts action uri * @param contentType mime content type * @param filename name reported to action * @param file uploaded file * @return ActionProxy */ protected ActionProxy getActionProxy (String uri, String contentType, String filename, File file) { // Create the proxy ActionProxy result = super.getActionProxy (uri); // Not part of upload but I think required for SessionAware ActionContext context = result.getInvocation ().getInvocationContext (); if (context.getSession () == null) { context.setSession (new HashMap ()); } // Wrap the request in a MultiPartRequestWrapper MultiPartRequest mpr = createMultiPartRequest (contentType, filename, file); MultiPartRequestWrapper wrapper = new MultiPartRequestWrapper (mpr, request, null); ServletActionContext.setRequest (wrapper); return result; } protected MultiPartRequest createMultiPartRequest (String contentType, String fileName, File file) { MultiPartRequest result = Mockito.mock (MultiPartRequest.class); Vector fileParameterNames = new Vector (); fileParameterNames.add (PROP_NAME); Enumeration enumFpn = fileParameterNames.elements (); Mockito.when (result.getFileParameterNames ()).thenReturn (enumFpn); String [] contentTypes = new String [1]; contentTypes [0] = contentType; Mockito.when (result.getContentType (PROP_NAME)).thenReturn (contentTypes); String [] fileNames = new String [1]; fileNames [0] = fileName; Mockito.when (result.getFileNames (PROP_NAME)).thenReturn (fileNames); File [] files = new File [1]; files [0] = file; Mockito.when (result.getFile (PROP_NAME)).thenReturn (files); return result; } private static final String PROP_NAME = "propertyName"; This assumes that your upload action has methods setPropertyName (File), setPropertyNameContentType (String), setPropertyNameFileName (String). The @Test methods now include the following: - File uploadedFile = new File ("path to test file"); ActionProxy proxy = getActionProxy ("uri", "content type e.g. text/csv", file.getName (), file); assertTrue (proxy.execute ().equals ("expected action result"); Note that the calls to the action are generated internally. You don't need any request.setParameter (...) calls. Cheers, Steve -Original Message- From: Steve Higham [mailto:st...@sjlt.co.uk] Sent: 25 April 2012 11:08 To: 'Struts Users Mailing List' Subject: StrutsTestCase, jUnit and file upload I'm currently using StrutsTestCase and jUnit to component test my Actions within the Struts context using a Mockito mock as my Model. This is working fine. I can call request.setParamater ("paramName", "paramValue") from the test class and, when executed, Struts will call the corresponding setParamName ("paramValue") on my Action. However I now wish to test "file upload" Actions. In normal use the FileUploadInterceptor will call setUploadedFile (java.io.File file) on the action. However I can't see any methods on the StrutsTestCase request object which will prepare the request with an uploaded file. Has anyone got this to work? Steve Higham - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: StrutsTestCase, jUnit and file upload
First of all, I assume you're trying to test your own code, not the framework. With that in mind, by the time the file gets to your action, it's just a series of parameters (which could be slightly different depending on which underlying Multipart support you are using). So, my suggestion would be to just mock in values for the parameters your action is expecting. (*Chris*) On Wed, Apr 25, 2012 at 6:36 AM, Gabriel Belingueres wrote: > Coincidentally, yesterday I was struggling with testing a file upload. > I was not using S2 as web framework but I was using Commons > Fileupload, which IIRC is the default S2 upload component. > > I must say that my first strategy was trying to use Spring's > MockMultipartHttpServletRequest and MockMultipartFile to simulate the > request, without any luck, so I ended up just writing the plain > request by hand: > >request = new MockHttpServletRequest(); >request.setMethod("POST"); >request.setContentType("multipart/form-data; boundary=AaB03x"); > >request.setContent(("--AaB03x\r\n" + >"Content-Disposition: form-data; name=\"archivo\"; > filename=\"texto.txt\"\r\n" + >"Content-Type: text/plain\r\n" + >"\r\n" + >"This is the content of the file\n" + >"\r\n" + >"--AaB03x\r\n" + >"Content-Disposition: form-data; name=\"id\"\r\n" + >"\r\n" + >"1\r\n" + >"--AaB03x--\r\n").getBytes("US-ASCII")); > > simulating the following form: > > enctype="multipart/form-data"> > > > > > > Important: respect the \r\n's and the final boundary with the extra > "--" at the end of the form. > > commons upload version: 1.2.2. > > HTH, > Gabriel > > 2012/4/25 Steve Higham : > > I'm currently using StrutsTestCase and jUnit to component test my Actions > > within the Struts context using a Mockito mock as my Model. > > > > > > > > This is working fine. I can call request.setParamater ("paramName", > > "paramValue") from the test class and, when executed, Struts will call > the > > corresponding setParamName ("paramValue") on my Action. > > > > > > > > However I now wish to test "file upload" Actions. In normal use the > > FileUploadInterceptor will call setUploadedFile (java.io.File file) on > the > > action. However I can't see any methods on the StrutsTestCase request > object > > which will prepare the request with an uploaded file. Has anyone got > this to > > work? > > > > > > > > Steve Higham > > > > > > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Re: StrutsTestCase, jUnit and file upload
Coincidentally, yesterday I was struggling with testing a file upload. I was not using S2 as web framework but I was using Commons Fileupload, which IIRC is the default S2 upload component. I must say that my first strategy was trying to use Spring's MockMultipartHttpServletRequest and MockMultipartFile to simulate the request, without any luck, so I ended up just writing the plain request by hand: request = new MockHttpServletRequest(); request.setMethod("POST"); request.setContentType("multipart/form-data; boundary=AaB03x"); request.setContent(("--AaB03x\r\n" + "Content-Disposition: form-data; name=\"archivo\"; filename=\"texto.txt\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "--AaB03x\r\n" + "Content-Disposition: form-data; name=\"id\"\r\n" + "\r\n" + "1\r\n" + "--AaB03x--\r\n").getBytes("US-ASCII")); simulating the following form: Important: respect the \r\n's and the final boundary with the extra "--" at the end of the form. commons upload version: 1.2.2. HTH, Gabriel 2012/4/25 Steve Higham : > I'm currently using StrutsTestCase and jUnit to component test my Actions > within the Struts context using a Mockito mock as my Model. > > > > This is working fine. I can call request.setParamater ("paramName", > "paramValue") from the test class and, when executed, Struts will call the > corresponding setParamName ("paramValue") on my Action. > > > > However I now wish to test "file upload" Actions. In normal use the > FileUploadInterceptor will call setUploadedFile (java.io.File file) on the > action. However I can't see any methods on the StrutsTestCase request object > which will prepare the request with an uploaded file. Has anyone got this to > work? > > > > Steve Higham > > > - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
StrutsTestCase, jUnit and file upload
I'm currently using StrutsTestCase and jUnit to component test my Actions within the Struts context using a Mockito mock as my Model. This is working fine. I can call request.setParamater ("paramName", "paramValue") from the test class and, when executed, Struts will call the corresponding setParamName ("paramValue") on my Action. However I now wish to test "file upload" Actions. In normal use the FileUploadInterceptor will call setUploadedFile (java.io.File file) on the action. However I can't see any methods on the StrutsTestCase request object which will prepare the request with an uploaded file. Has anyone got this to work? Steve Higham
Re: Testing with StrutsTestCase in a Tiles application - NullPointerException
For future reference, I found the answer in http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/ Basically, you need to initialize the tiles listener. As I already used setupBeforeInitDispatcher to set the applicationContext attribute, I added the code there (inside the if(tilesApplication) segment): /** Overrides the previous in order to skip applicationContext assignment: context is @autowired * @see org.apache.struts2.StrutsSpringTestCase#setupBeforeInitDispatcher() **/ @Override protected void setupBeforeInitDispatcher() throws Exception { //init context servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); if(tilesApplication){ servletContext.addInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG, "WEB-INF/tiles.xml"); final StrutsTilesListener tilesListener = new StrutsTilesListener(); final ServletContextEvent event = new ServletContextEvent(servletContext); tilesListener.contextInitialized(event); } } Miguel Almeida On Fri, 2012-01-27 at 17:35 +, Miguel Almeida wrote: > Hi there, > > I trying to test an application with the help of StrutsTestCase (a class > that extends from StrutsSpringTestCase, to be more precise). > StrutsTestCase (which is in the struts junit plugin) involves proxied > actions to make tests more light. > > I have used the same method in another application that doesn't have > tiles successfully. Here, however, I am running into an exception when > running the actionProxy.execute() : > > > java.lang.NullPointerException > at > org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105) > at > org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186) > > > I found a user that described the problem very well on stackOverflow: > http://stackoverflow.com/questions/5823709/npe-in-strutstestcase-after-enabling-tiles > > There is also a 2008 question on the mailing list > (http://www.mail-archive.com/user@struts.apache.org/msg77582.html ). > Petrelli tried to answer, but no solution was posted. > > From these resources, do you know what the problem might be and if it is > possible to use StrutsTestCase to test an application that has Tiles > enabled through the StrutsTilesListener? > > > Cheers, > > Miguel Almeida >
Testing with StrutsTestCase in a Tiles application - NullPointerException
Hi there, I trying to test an application with the help of StrutsTestCase (a class that extends from StrutsSpringTestCase, to be more precise). StrutsTestCase (which is in the struts junit plugin) involves proxied actions to make tests more light. I have used the same method in another application that doesn't have tiles successfully. Here, however, I am running into an exception when running the actionProxy.execute() : java.lang.NullPointerException at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105) at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186) I found a user that described the problem very well on stackOverflow: http://stackoverflow.com/questions/5823709/npe-in-strutstestcase-after-enabling-tiles There is also a 2008 question on the mailing list (http://www.mail-archive.com/user@struts.apache.org/msg77582.html ). Petrelli tried to answer, but no solution was posted. >From these resources, do you know what the problem might be and if it is possible to use StrutsTestCase to test an application that has Tiles enabled through the StrutsTilesListener? Cheers, Miguel Almeida
Re: Problem with configured action method names and Testing Framework ===> StrutsTestCase cannot handle actions not calling execute()
Hi, the setup is unit testing with maven + spring + struts using StrutsSpringTestCase super class (which is an extended org.apache.struts2.StrutsTestCase with access to spring config). So this is working well with actions not having the methodname configured. Whenever I do configure such a method the code in AnnotationValidationInterceptor(struts-core-2.2.3) fails in line 83++ after failing to instantiate the method which is NOT named "execute" this time from the proxy. Environment: 1. struts action configured using a method name. 2. action test based on a StrutsTestCase (using those mock objects) 3. set a breakpoint on line 83 in the annotationvalidationinterceptor. However, the same code exists in DefaultActionInvocation line 437 and is used to instantiate the method for executing the action, so disabling the validation simply postpones the very same issue to a later point in the code as you can see in the stacktrace below! It seems that the StrustTestcase cannot handle actions with a method name configured! Thread [main] (Suspended) DefaultActionInvocation.invokeAction(Object, ActionConfig) line: 433 DefaultActionInvocation.invokeActionOnly() line: 291 DefaultActionInvocation.invoke() line: 254 DefaultWorkflowInterceptor.doIntercept(ActionInvocation) line: 176 DefaultWorkflowInterceptor(MethodFilterInterceptor).intercept(ActionInvocation) line: 98 DefaultActionInvocation.invoke() line: 248 StrutsConversionErrorInterceptor(ConversionErrorInterceptor).intercept(ActionInvocation) line: 133 DefaultActionInvocation.invoke() line: 248 ParametersInterceptor.doIntercept(ActionInvocation) line: 207 ParametersInterceptor(MethodFilterInterceptor).intercept(ActionInvocation) line: 98 DefaultActionInvocation.invoke() line: 248 ActionMappingParametersInteceptor(ParametersInterceptor).doIntercept(ActionInvocation) line: 207 ActionMappingParametersInteceptor(MethodFilterInterceptor).intercept(ActionInvocation) line: 98 DefaultActionInvocation.invoke() line: 248 StaticParametersInterceptor.intercept(ActionInvocation) line: 190 DefaultActionInvocation.invoke() line: 248 MultiselectInterceptor.intercept(ActionInvocation) line: 75 DefaultActionInvocation.invoke() line: 248 CheckboxInterceptor.intercept(ActionInvocation) line: 94 DefaultActionInvocation.invoke() line: 248 ModelDrivenInterceptor.intercept(ActionInvocation) line: 100 DefaultActionInvocation.invoke() line: 248 ScopedModelDrivenInterceptor.intercept(ActionInvocation) line: 141 DefaultActionInvocation.invoke() line: 248 DebuggingInterceptor.intercept(ActionInvocation) line: 270 DefaultActionInvocation.invoke() line: 248 ChainingInterceptor.intercept(ActionInvocation) line: 145 DefaultActionInvocation.invoke() line: 248 PrepareInterceptor.doIntercept(ActionInvocation) line: 171 PrepareInterceptor(MethodFilterInterceptor).intercept(ActionInvocation) line: 98 DefaultActionInvocation.invoke() line: 248 I18nInterceptor.intercept(ActionInvocation) line: 176 DefaultActionInvocation.invoke() line: 248 ServletConfigInterceptor.intercept(ActionInvocation) line: 164 DefaultActionInvocation.invoke() line: 248 AliasInterceptor.intercept(ActionInvocation) line: 190 DefaultActionInvocation.invoke() line: 248 ExceptionMappingInterceptor.intercept(ActionInvocation) line: 187 DefaultActionInvocation.invoke() line: 248 StrutsActionProxy.execute() line: 52 ContentActionTest.doContentDelete() line: 158 ContentActionTest.testContentLifeCycle() line: 179 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 Method.invoke(Object, Object...) line: 597 FrameworkMethod$1.runReflectiveCall() line: 44 FrameworkMethod$1(ReflectiveCallable).run() line: 15 FrameworkMethod.invokeExplosively(Object, Object...) line: 41 InvokeMethod.evaluate() line: 20 RunBefores.evaluate() line: 28 RunBeforeTestMethodCallbacks.evaluate() line: 74 RunAfterTestMethodCallbacks.evaluate() line: 82 SpringRepeat.evaluate() line: 72 SpringJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier) line: 240 SpringJUnit4ClassRunner(BlockJUnit4ClassRunner).runChild(Object, RunNotifier) line: 50 ParentRunner$3.run() line: 193 ParentRunner$1.schedule(Runnable) line: 52 SpringJUnit4ClassRunner(ParentRunner).runChildren(RunNotifier) line: 191 ParentRunner.access$000(ParentRunner, RunNotifier) line: 42 ParentRunner$2.evaluate() line: 184 RunBeforeTestClassCallbacks.evaluate() line: 61 RunAfterTestClassCallbacks.evaluate() line: 70 SpringJUnit4ClassRunner(ParentRunner).run(RunNotifier) line: 236 SpringJUnit4ClassRunner.run(RunNotifier)
Re: NPE in StrutsTestCase after enabling Tiles
Ah, ok. So the SourceForge one is not the one I'm using then. I'm extending org.apache.struts2.StrutsTestCase in the test I'm having problems with. Thanks for your input! On Fri, Apr 29, 2011 at 1:47 PM, Dave Newton wrote: > On Fri, Apr 29, 2011 at 1:35 PM, Justin Robbins wrote: >> Lastly, can anyone explain what the deal is with StrutsTestCase? >> There's a tutorial page for using it with Struts 2 on >> struts.apache.org but the SourceForge page >> (http://strutstestcase.sourceforge.net/) for it hasn't been updated >> since Struts 1.3 > > "StrutsTestCase" is a generic name. You're looking at an old, > third-party StrutsTestCase on sourceforge; the one for Struts 2 is > part of Struts 2. > > Dave > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > -- Regards, Justin Robbins 973.479.0448 justinhrobb...@gmail.com Learn more about me by viewing my professional profile on LinkedIn http://www.linkedin.com/in/justinhrobbins View my professional blog http://javadeveloperjournal.blogspot.com/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: NPE in StrutsTestCase after enabling Tiles
On Fri, Apr 29, 2011 at 1:35 PM, Justin Robbins wrote: > Lastly, can anyone explain what the deal is with StrutsTestCase? > There's a tutorial page for using it with Struts 2 on > struts.apache.org but the SourceForge page > (http://strutstestcase.sourceforge.net/) for it hasn't been updated > since Struts 1.3 "StrutsTestCase" is a generic name. You're looking at an old, third-party StrutsTestCase on sourceforge; the one for Struts 2 is part of Struts 2. Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
NPE in StrutsTestCase after enabling Tiles
Hi Folks, This is my first post to user@struts.apache.org. I yesterday posed this same question on stackoverflow but haven't garnered any responses so I figured I'd give this list a try. Hope that's cool. http://stackoverflow.com/questions/5823709/npe-in-strutstestcase-after-enabling-tiles I developed some JUnit tests that extend org.apache.struts2.StrutsTestCase. I used the tutorial (http://struts.apache.org/2.x/struts-2-junit-plugin-tutorial.html) on struts.apache.org as my starting point. Everything was working fine until I modified my simple web application to use Tiles. I have Tiles working fine in the app but now my Struts Action test cases have stopped working. I'm getting NullPointerException at org.apache.struts2.views.tiles.TilesResult.doExecute when I run the following line of code: ActionProxy proxy = getActionProxy("/displaytag.action"); The log shows the Struts 2 Action is executing succesfully until it tries to hand it off to TilesResult.doExecute. I suspect it is because the tests run outside of the container and the tiles.xml is only referenced in the web.xml and therefore my StrutsTestCase tests don't know where to find the definitions in tiles.xml. Is this making sense? I'm using Struts 2.2.1.1 and the tiles related jars (v. 2.0.6) included in the Struts distribution. I'll include a code snippet from my StrutsTestCase but please note everything runs successfully when I run the app from the browser in Tomcat, it only fails when I run the StrutsTestCase outside of Tomcat. And the test cases ran successfully before I added Tiles. public class TagActionTest extends StrutsTestCase { static Logger logger = Logger.getLogger(TagActionTest.class); public void testCreateTagFail() throws Exception { try { request.setParameter("name", ""); ActionProxy proxy = getActionProxy("/createtag.action"); TagAction tagAction = (TagAction) proxy.getAction(); proxy.execute(); assertTrue("Problem There were no errors present in fieldErrors but there should have been one error present", tagAction.getFieldErrors().size() == 1); assertTrue("Problem field 'name' not present in fieldErrors but it should have been", tagAction.getFieldErrors().containsKey("name") ); } catch (Exception e) { logger.debug("Error running testCreateTagFail()"); e.printStackTrace(); assertTrue("Error running testCreateTagFail()", false); } } Partial stack trace: java.lang.NullPointerException at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105) at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186) at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373) Lastly, can anyone explain what the deal is with StrutsTestCase? There's a tutorial page for using it with Struts 2 on struts.apache.org but the SourceForge page (http://strutstestcase.sourceforge.net/) for it hasn't been updated since Struts 1.3 Also, what's the difference between StrutsTestCase and MockStrutsTestCase -- Regards, Justin Robbins - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: StrutsTestCase and Spring 2.5
Thanks bro! I think I hated annotations until today. Was the StrutsTestCase moved into a plug-in recently? On Thu, Jun 11, 2009 at 10:41 AM, Wes Wannemacher wrote: > Scott, it is just complaining because you are trying to do something > Spring-ish in your unit test, but Spring is not initialized... Try > annotating the test class with something like the following - > > @RunWith(SpringJUnit4ClassRunner.class) > @ContextConfiguration(locations={"classpath*:applicationContext-test.xml"}) > public class ... > > > That's the easy way, but if you are using an older JDK|JUnit then > you'll have to figure out how to start Spring. > > -Wes > > On Thu, Jun 11, 2009 at 11:25 AM, stanlick wrote: > > > > I am on a project with a new combination of jars and testing Struts > > interceptors. I have added the struts2-junit-plugin-2.1.2.jar and also > > spring-test.jar. When I run my subclass test of StrutsTestCase I get the > > following exception: > > > > SEVERE: [20:44.438] ** FATAL ERROR STARTING UP STRUTS-SPRING > > INTEGRATION ** > > Looks like the Spring listener was not configured for your web app! > > Nothing will work until WebApplicationContextUtils returns a valid > > ApplicationContext. > > You might need to add the following to web.xml: > > > > > > > org.springframework.web.context.ContextLoaderListener > > > > > > > > Why is the web.xml being considered? > > > > Peace, > > Scott > > -- > > View this message in context: > http://www.nabble.com/StrutsTestCase-and-Spring-2.5-tp23983515p23983515.html > > Sent from the Struts - User mailing list archive at Nabble.com. > > > > > > - > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > > For additional commands, e-mail: user-h...@struts.apache.org > > > > > > > > -- > Wes Wannemacher > Author - Struts 2 In Practice > Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more > http://www.manning.com/wannemacher > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Re: StrutsTestCase and Spring 2.5
Scott, it is just complaining because you are trying to do something Spring-ish in your unit test, but Spring is not initialized... Try annotating the test class with something like the following - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath*:applicationContext-test.xml"}) public class ... That's the easy way, but if you are using an older JDK|JUnit then you'll have to figure out how to start Spring. -Wes On Thu, Jun 11, 2009 at 11:25 AM, stanlick wrote: > > I am on a project with a new combination of jars and testing Struts > interceptors. I have added the struts2-junit-plugin-2.1.2.jar and also > spring-test.jar. When I run my subclass test of StrutsTestCase I get the > following exception: > > SEVERE: [20:44.438] ** FATAL ERROR STARTING UP STRUTS-SPRING > INTEGRATION ** > Looks like the Spring listener was not configured for your web app! > Nothing will work until WebApplicationContextUtils returns a valid > ApplicationContext. > You might need to add the following to web.xml: > > > org.springframework.web.context.ContextLoaderListener > > > > Why is the web.xml being considered? > > Peace, > Scott > -- > View this message in context: > http://www.nabble.com/StrutsTestCase-and-Spring-2.5-tp23983515p23983515.html > Sent from the Struts - User mailing list archive at Nabble.com. > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > -- Wes Wannemacher Author - Struts 2 In Practice Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more http://www.manning.com/wannemacher - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
StrutsTestCase and Spring 2.5
I am on a project with a new combination of jars and testing Struts interceptors. I have added the struts2-junit-plugin-2.1.2.jar and also spring-test.jar. When I run my subclass test of StrutsTestCase I get the following exception: SEVERE: [20:44.438] ** FATAL ERROR STARTING UP STRUTS-SPRING INTEGRATION ** Looks like the Spring listener was not configured for your web app! Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext. You might need to add the following to web.xml: org.springframework.web.context.ContextLoaderListener Why is the web.xml being considered? Peace, Scott -- View this message in context: http://www.nabble.com/StrutsTestCase-and-Spring-2.5-tp23983515p23983515.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: StrutsTestCase and Struts2
Thanks Dave, they are there. I failed to guess that all were using JWebUnit. /Enric - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: StrutsTestCase and Struts2
Enric Jaen wrote: Hello, I'd to test the StrutsTestCase's version for Struts2 [1] but I have not found any example. There are plenty of examples for Struts1, however. Any idea how to use it? Have you looked at any of the existing tests for S2? Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
StrutsTestCase and Struts2
Hello, I'd to test the StrutsTestCase's version for Struts2 [1] but I have not found any example. There are plenty of examples for Struts1, however. Any idea how to use it? Regards, /Enric ps. I have found examples of testing Struts2 with JWebUnit, but what I want is to test the controller. [1] http://struts.apache.org/2.0.11.2/struts2-core/apidocs/org/apache/struts2/StrutsTestCase.html - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Struts2 StrutsTestCase
Hello, I'm fairly new to Struts 2. I'm currently migrating a project from Struts 1 to Struts 2, but I'd like to make heavy use of Unit Testing to aid in the migration. In the documentation, the testability of the new actions is often mentioned. However, I have the impression that it's not that simple at all. I put some work into using the StrutsTestCase class as base class for my tests, but I've run into some problems that I can't really understand. 1. There is hardly any documentation regarding the StrutsTestCase or the XWorkTestCase base classes. Not in the documentation, not in the mail archives, not even the issue tracker. Is anyone using these classes at all ? I've found a short part in Ian Roughley's book Starting Struts 2, but the example did not work for me. 2. I did found some examples in the struts2-showcase web application, and building upon these, I succeeded in setting up my test cases. I have my base class, with the setup of request and session objects, the code of which is shown below (picked from the ExecuteAndWaitInterceptorTest class in the showcase source code). public abstract class BaseTestCase extends StrutsTestCase { protected StrutsMockHttpServletRequest request; protected HttpSession httpSession; protected Map context; protected Map params; protected Map session; protected ServletContext servletContext; protected void setUp() throws Exception { //super.setUp(); <- Does not work ! loadConfigurationProviders(new LocationConfigurationProvider()); session = new HashMap(); params = new HashMap(); context = new HashMap(); context.put(ActionContext.SESSION, session); context.put(ActionContext.PARAMETERS, params); request = new StrutsMockHttpServletRequest(); request.setParameterMap(params); context.put(ServletActionContext.HTTP_REQUEST, request); servletContext = new MockServletContext(); servletContext.setAttribute(DaoPlugIn.DAOMANAGER, DaoConfig.getDaoManager()); context.put(ServletActionContext.SERVLET_CONTEXT, servletContext); UserInfo userInfo = .. ... session.put(AppConstants.APP_USER_INFO_KEY, userInfo); } // can be overridden by subclasses public List getInterceptors() { List interceptors = new ArrayList(); interceptors.add(new InterceptorMapping("servlet", new ServletConfigInterceptor())); interceptors.add(new InterceptorMapping("params", new ParametersInterceptor())); interceptors.add(new InterceptorMapping("prepare", new PrepareInterceptor())); interceptors.add(new InterceptorMapping("params", new ParametersInterceptor())); return interceptors; } // can be overridden by subclasses public Map getResultConfig() { Map results = new HashMapResultConfig>(); results.put(Action.SUCCESS, new ResultConfig(Action.SUCCESS, MockResult.class.getName(), null)); return results; } // every test class will test a particular action class public abstract Class getActionClass(); // add package configurations, containing action names, method names, ... // this is specific for each test class, so here's only an abstract method public abstract void getPackageConfigs(Configuration configuration); private class LocationConfigurationProvider implements ConfigurationProvider { Configuration configuration; public void destroy() { //waitInterceptor.destroy(); } public boolean needsReload() { return false; } public void init(Configuration configuration) throws ConfigurationException { this.configuration = configuration; } public void loadPackages() throws ConfigurationException { getPackageConfigs(configuration); } public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { builder.factory(ObjectFactory.class); builder.factory(ActionProxyFactory.class, DefaultActionProxyFactory.class); } } } The problem I've found is that it is not possible to execute super.setUp() When adding or uncommenting this line, I get an error 17 Jul 2007 18:42:01,589 - FATAL org.apache.struts2.spring.StrutsSpringObjectFactory - ** FATAL ERROR STARTING UP SPRING-STRUTS INTEGRATION ** Looks like the Spring listener was not configured for your web app! Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext. You might need to add the following to web.xml: org.springframework.web.context.ContextLoaderListener The Spring listener IS configured in my web.xml, but it seems that the test case cannot find the web.xml file itself, even
Struts/Spring/Tiles/StrutsTestCase
I have struts application that works with spring. I do have few questions my struts-config.xml looks like this... .. what should I setup controller as: processorClass="org.springframework.web.struts.DelegatingTilesRequestProcessor" nocache="true" locale="true" /> or processorClass="org.apache.struts.tiles.TilesRequestProcessor" nocache="true" locale="true" /> what is the difference?? I got strutsTestcase almost working with spring wired actions. On that front I have one question: How do I find forward name and path from programetically: TilesRequestProcessor tilesProcessor = (TilesRequestProcessor)this.context.getAttribute("org.apache.struts.action.REQUEST_PROCESSOR"); does return null . what I want to do is given the forward name, find the path. basically get the struts-config.xml thanks rukka - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FW: StrutsTestCase & Hibernate
I think unit tests on everything are always a good idea - the problem comes if you start making them 'more' than just unit tests. Ideally you should be able to unit test action classes quickly with mock objects or stubs for both the business tier below and the MVC controller tier above. StrutsTestCase offers alot. I haven't used it but I believe it's easy enough to set up and run to mock the MVC part. Then something like Spring could instantiate stubbed business objects instead of real ones, so that the actions can run happily against a back end. For that of course you'd need interface-based business objects. It would be best to limit your tests to keep them fast and simple, but you could do any or all of the following tests: (1) good input params result in the action forward you want (2) bad input params result in an 'error' action forward (3) a business exception in the business tier is handled ok (4) a system exception in business tier results in an 'error' action forward I wouldn't do any unit testing here that involved input parameter validation routines - i.e. i use Validator - I think that requires too much effort setting up the correct params for each unit test. On a related note, I find it useful to run the ant or maven build with JSP compilation as well (by default it happens only in the container) just to make sure you don't get any ugly surprises after deploy. Jakub Milkiewicz on 06/05/06 11:03, wrote: Hi If you are thinking of unit tests for action i do not think it is great idea. For me actions should be as dumb as possible and just delegate business processing to another layer. 2006/5/5, Stasica, Grzegorz <[EMAIL PROTECTED]>: Basically I'm interested in testing struts actions (forwards, messages etc). Most of the actions perform some actions on my database which I'd like to speed up. My idea is to isolate database tests from struts action test. There is only one way to achieve it which I see at the moment (mock objects). If I substitute my persistence layer in tests on mocks not only tests will run faster but I'll not have to prepopulate database for each test (even in memory datatabase needs some configuration prior to tests). Unfortunately except idea I've nothing. I've no idea on how to achieve it. Any idea or sample code ? I think the problem is not open and many of you've solved it in one way or another - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FW: StrutsTestCase & Hibernate
Hi If you are thinking of unit tests for action i do not think it is great idea. For me actions should be as dumb as possible and just delegate business processing to another layer. 2006/5/5, Stasica, Grzegorz <[EMAIL PROTECTED]>: hi, Basically I'm interested in testing struts actions (forwards, messages etc). Most of the actions perform some actions on my database which I'd like to speed up. My idea is to isolate database tests from struts action test. There is only one way to achieve it which I see at the moment (mock objects). If I substitute my persistence layer in tests on mocks not only tests will run faster but I'll not have to prepopulate database for each test (even in memory datatabase needs some configuration prior to tests). Unfortunately except idea I've nothing. I've no idea on how to achieve it. Any idea or sample code ? I think the problem is not open and many of you've solved it in one way or another Note: If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you.
FW: StrutsTestCase & Hibernate
hi, Basically I'm interested in testing struts actions (forwards, messages etc). Most of the actions perform some actions on my database which I'd like to speed up. My idea is to isolate database tests from struts action test. There is only one way to achieve it which I see at the moment (mock objects). If I substitute my persistence layer in tests on mocks not only tests will run faster but I'll not have to prepopulate database for each test (even in memory datatabase needs some configuration prior to tests). Unfortunately except idea I've nothing. I've no idea on how to achieve it. Any idea or sample code ? I think the problem is not open and many of you've solved it in one way or another Note: If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you.
StrutsTestCase and Struts Validator PlugIn
Does anyone know if StrutsTestCase works with the Struts Validator? ie. If I make a test case and set up the request parameters for a FormBean, will the FormBean be validated using the Validator Configuration in my struts-config.xml file. Thanks, Richard - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Cactus testing for StrutsTestCase
Brett, you were right, and I thought I had added the jar. I had mistyped it, however. Once I got the name right (cactus-ant-1.7.jar instead of cactus-ant.jar), it worked. Funny how computers only do what you said, not what you meant. Thanks for taking the time to reply. Much appreciated. Hyrum --- Begin Message --- Hyrum wrote: >I am trying to use the Ant 'cactus' optional task in my build.xml. This >fails because Eclipse must have the optional task set in the preferences, >but I can't figure out how to do this. > If I have understood your issue correctly, you need add the jar with the optional task to the classpath for the build.xml external tool. From the 'external tools' menu / toolbar button the "external tools..." option allows you to set environment variables, classpath, refresh etc for each tool / build script. If I haven't understood your question, my appologies for a useless answer. Brett - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- End Message --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Cactus testing for StrutsTestCase
Brett, you were right, and I thought I had added the jar. I had mistyped it, however. Once I got the name right (cactus-ant-1.7.jar instead of cactus-ant.jar), it worked. Funny how computers only do what you said, not what you meant. Thanks for taking the time to reply. Much appreciated. Hyrum --- Begin Message --- Hyrum wrote: >I am trying to use the Ant 'cactus' optional task in my build.xml. This >fails because Eclipse must have the optional task set in the preferences, >but I can't figure out how to do this. > If I have understood your issue correctly, you need add the jar with the optional task to the classpath for the build.xml external tool. From the 'external tools' menu / toolbar button the "external tools..." option allows you to set environment variables, classpath, refresh etc for each tool / build script. If I haven't understood your question, my appologies for a useless answer. Brett - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- End Message --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cactus testing for StrutsTestCase
Hyrum wrote: I am trying to use the Ant 'cactus' optional task in my build.xml. This fails because Eclipse must have the optional task set in the preferences, but I can't figure out how to do this. If I have understood your issue correctly, you need add the jar with the optional task to the classpath for the build.xml external tool. From the 'external tools' menu / toolbar button the "external tools..." option allows you to set environment variables, classpath, refresh etc for each tool / build script. If I haven't understood your question, my appologies for a useless answer. Brett - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Cactus testing for StrutsTestCase
I'm trying to do some in-container testing of my Actions using CactusStrutsTestCase. I realize this may be a bit off topic, since it deals with Ant, the Eclipse IDE, JUnit, and Struts, but I'm hoping there is a Struts user who has experience something like this and can point me in the right direction. I am trying to use the Ant 'cactus' optional task in my build.xml. This fails because Eclipse must have the optional task set in the preferences, but I can't figure out how to do this. I've already submitted this question to a MyEclipse forum. In the meantime, I'm wondering if someone has run these kinds of tests with Eclipse before, and if so, what tasks does your ant file use?? Once again, I apologize if it's a little vague and off topic, but can someone throw me a bone here?
Cactus testing for StrutsTestCase
I'm trying to do some in-container testing of my Actions using CactusStrutsTestCase. I realize this may be a bit off topic, since it deals with Ant, the Eclipse IDE, JUnit, and Struts, but I'm hoping there is a Struts user who has experience something like this and can point me in the right direction. I am trying to use the Ant 'cactus' optional task in my build.xml. This fails because Eclipse must have the optional task set in the preferences, but I can't figure out how to do this. I've already submitted this question to a MyEclipse forum. In the meantime, I'm wondering if someone has run these kinds of tests with Eclipse before, and if so, what tasks does your ant file use?? Once again, I apologize if it's a little vague and off topic, but can someone throw me a bone here?
StrutsTestCase
Thanks to this list I just found the StrutsTestCase package. I think its a great tool. Testing my forms and actions OUTSIDE the container has increased my velocity 10 fold. But it seems that not many Struts people talk about this package (aside from page 510 of J.B.'s book). Is there something wrong with it? Seems to me that StrutsTestCase really allows you to do TDD and Struts, a very powerful combination. Am I missing some major negative about StrutsTestCase? Thanks. --Marty - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using StrutsTestCase with 1.2, wildcards and MappingDispatchAction
Bill Siggelkow wrote: Laurent Duperval wrote: Hello, Does anyone have experience using (Mock)StrutsTestCase to test wildcard actions (actions that end in *) and MappingDispatchActions? Does it work? Are there any particular issues to be aware of? Thanks, L I haven't tested mapping dispatch action with StrutsTestCase, but I have tested wildcard mappings without any problems. -Bill Siggelkow I don't use StrutsTestCase, but, since you can set the struts-config.xml, there is no reason to think it would not work that I know of. Michael McGrady - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using StrutsTestCase with 1.2, wildcards and MappingDispatchAction
Laurent Duperval wrote: Hello, Does anyone have experience using (Mock)StrutsTestCase to test wildcard actions (actions that end in *) and MappingDispatchActions? Does it work? Are there any particular issues to be aware of? Thanks, L I haven't tested mapping dispatch action with StrutsTestCase, but I have tested wildcard mappings without any problems. -Bill Siggelkow - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Using StrutsTestCase with 1.2, wildcards and MappingDispatchAction
Hello, Does anyone have experience using (Mock)StrutsTestCase to test wildcard actions (actions that end in *) and MappingDispatchActions? Does it work? Are there any particular issues to be aware of? Thanks, L - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help with Cactus StrutsTestCase
Thanks Duncan, i`ll check it out! --- Duncan Mills <[EMAIL PROTECTED]> escreveu: > Leandro - a good article has just been published on > the Oracle > Technology Network on using JUnit, Cactus and > StrutsTestCase - the setup > portions relate to setting up these up with > JDeveloper, but the basic > flow and tutorial portions provide a good kickstart > even if you use > another IDE - check it out: > http://www.oracle.com/technology/pub/articles/server_side_unit_tests.html > > Regards > > Duncan Mills > http://www.groundside.com/blog > > > > Leandro Melo wrote: > > >Doesn`t know the answer, where can i find a good > >tutorial do test struts applications? > >Is it true that for good testing the actions must > >delegate their work to POJOs ?? > > > > > > > > --- [EMAIL PROTECTED] escreveu: > > > > > >>I am trying to write test cases for my Struts app, > >>but can't seem to figure it out. > >>I have used the examples, but I don't seem to get > >>the correct outcome when I run them. > >> > >>I am using LookupDispatchAction's exclusively. > >> > >>So here is the method I am testing: > >>== > >>public void productSelectionAction( > >>ActionMapping mapping > >>, > ActionForm > >>form > >>, > >>HttpServletRequest request > >>, > >>HttpServletResponse response ) { > >>log.info( "Process > CreditApplicationActions > >>productSelectionAction(...)" ); > >> > >>NavigationBean navigationBean = ( > >>NavigationBean )request.getSession().getAttribute( > >>"navigationBean" ); > >>if( navigationBean == null ) { > >>navigationBean = new NavigationBean(); > >>} > >> > >>if( Constants.TRUE.equals( > >>request.getParameter( Constants.BUS_LINE_SELECTED > ) > >>) ) { > >>navigationBean.setHasBusinessLine( > true > >>); > >>} else { > >>request.getSession().setAttribute( > >>"businessLineForm", null ); > >>navigationBean.setHasBusinessLine( > false > >>); > >>} > >> > >>if( Constants.TRUE.equals( > >>request.getParameter( Constants.BUS_CARD_SELECTED > ) > >>) ) { > >>navigationBean.setHasBusinessCard( > true > >>); > >>} else { > >>request.getSession().setAttribute( > >>"businessCardForm", null ); > >>navigationBean.setHasBusinessCard( > false > >>); > >>} > >> > >>if( Constants.TRUE.equals( > >>request.getParameter( > >>Constants.BUS_SEC_CARD_SELECTED ) ) ) { > >>navigationBean.setHasSecuredCard( true > >>); > >>} else { > >>request.getSession().setAttribute( > >>"securedCardForm", null ); > >>navigationBean.setHasSecuredCard( > false > >>); > >>} > >> > >>if( Constants.TRUE.equals( > >>request.getParameter( > >>Constants.EQUIP_EXPRESS_SELECTED ) ) ) { > >>navigationBean.setHasEquipExpress( > true > >>); > >>} else { > >>request.getSession().setAttribute( > >>"equipExpressForm", null ); > >>navigationBean.setHasEquipExpress( > false > >>); > >>} > >> > >>request.getSession().setAttribute( > >>"navigationBean", navigationBean ); > >>}; > >> > >> > >> > >> > >>Here is the action in the struts-config.xml: > >>=== > >> > >> >>input=".productSelection" > >>name="productSelectionForm" > >>parameter="action" > >>scope="session" > >> > >> > >> > >> > >type="com.wf.bd.ice.creditapplication.CreditApplicationActions" > > > > > >>validate="true"> > >>
Re: Help with Cactus StrutsTestCase
Leandro - a good article has just been published on the Oracle Technology Network on using JUnit, Cactus and StrutsTestCase - the setup portions relate to setting up these up with JDeveloper, but the basic flow and tutorial portions provide a good kickstart even if you use another IDE - check it out: http://www.oracle.com/technology/pub/articles/server_side_unit_tests.html Regards Duncan Mills http://www.groundside.com/blog Leandro Melo wrote: Doesn`t know the answer, where can i find a good tutorial do test struts applications? Is it true that for good testing the actions must delegate their work to POJOs ?? --- [EMAIL PROTECTED] escreveu: I am trying to write test cases for my Struts app, but can't seem to figure it out. I have used the examples, but I don't seem to get the correct outcome when I run them. I am using LookupDispatchAction's exclusively. So here is the method I am testing: == public void productSelectionAction( ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response ) { log.info( "Process CreditApplicationActions productSelectionAction(...)" ); NavigationBean navigationBean = ( NavigationBean )request.getSession().getAttribute( "navigationBean" ); if( navigationBean == null ) { navigationBean = new NavigationBean(); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_LINE_SELECTED ) ) ) { navigationBean.setHasBusinessLine( true ); } else { request.getSession().setAttribute( "businessLineForm", null ); navigationBean.setHasBusinessLine( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_CARD_SELECTED ) ) ) { navigationBean.setHasBusinessCard( true ); } else { request.getSession().setAttribute( "businessCardForm", null ); navigationBean.setHasBusinessCard( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_SEC_CARD_SELECTED ) ) ) { navigationBean.setHasSecuredCard( true ); } else { request.getSession().setAttribute( "securedCardForm", null ); navigationBean.setHasSecuredCard( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.EQUIP_EXPRESS_SELECTED ) ) ) { navigationBean.setHasEquipExpress( true ); } else { request.getSession().setAttribute( "equipExpressForm", null ); navigationBean.setHasEquipExpress( false ); } request.getSession().setAttribute( "navigationBean", navigationBean ); }; Here is the action in the struts-config.xml: === input=".productSelection" name="productSelectionForm" parameter="action" scope="session" type="com.wf.bd.ice.creditapplication.CreditApplicationActions" validate="true"> Here is the test method: == public void testProductSelection() throws Exception { // JUnitDoclet begin method productSelection setRequestPathInfo( "/productSelection" ); addRequestParameter( "action", "nextPage" ); addRequestParameter( "businessLineSelected", "true" ); addRequestParameter( "businessCardSelected", "true" ); addRequestParameter( "businessSecuredCardSelected", "true" ); addRequestParameter( "equipmentExpressSelected", "true" ); actionPerform(); verifyForward( Constants.ERROR_FWD ); verifyForward( Constants.PRODUCTSELECTION_FWD ); //verifyActionErrors(new String[] {"error.nodefault.implementation" } ); //verifyActionErrors(new String[] { "error.noaction.specified"} ); //NavigationBean navigationBean = (NavigationBean)getSession().getAttribute( "navigationBean" ); //assertTrue( "NavigationBean is null", navigationBean == null); verifyNoActionErrors(); // JUnitDoclet end method productSelection } And I get zero errors at all... --- Thanks... Mick Knutson 525 Market Street, SF, CA 94103 (415) 222-1020 [EMAIL PROTECTED] MAC A0103-223 --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additi
Re: Help with Cactus StrutsTestCase
Mick, I don't think I have explicitly tested LookupDispatchAction under CactusStrutsTestCase but I see no reason why it shouldn't work -- Here are some suggestions: - Check the log files, etc. - Determine if you can test a conventional action (just dummy one up if you don't have one) - Get out your trusty debugger. [EMAIL PROTECTED] wrote: Yes: /** * This is the method that defines the different button text items in a hashMap * for the BaseLookupDispatchAction to use. * * TODO: Need to externalize this, so these are not hard coded. */ protected Map getKeyMethodMap() { log.info( "getKeyMethodMap..." ); Map map = new HashMap(); ResourceBundle methods = ResourceBundle.getBundle( Constants.LOOKUP_METHOD_MESSAGE_RESOURCES ); Enumeration keys = methods.getKeys(); while( keys.hasMoreElements() ) { String key = ( String )keys.nextElement(); map.put( key, methods.getString( key ) ); } return map; } -Original Message- From: news [mailto:[EMAIL PROTECTED] Behalf Of Bill Siggelkow Sent: Thursday, August 26, 2004 10:53 AM To: [EMAIL PROTECTED] Subject: Re: Help with Cactus StrutsTestCase Is your LookupDispatchAction implementing getKeyMethodMap()? [EMAIL PROTECTED] wrote: I am trying to write test cases for my Struts app, but can't seem to figure it out. I have used the examples, but I don't seem to get the correct outcome when I run them. I am using LookupDispatchAction's exclusively. So here is the method I am testing: == public void productSelectionAction( ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response ) { log.info( "Process CreditApplicationActions productSelectionAction(...)" ); NavigationBean navigationBean = ( NavigationBean )request.getSession().getAttribute( "navigationBean" ); if( navigationBean == null ) { navigationBean = new NavigationBean(); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_LINE_SELECTED ) ) ) { navigationBean.setHasBusinessLine( true ); } else { request.getSession().setAttribute( "businessLineForm", null ); navigationBean.setHasBusinessLine( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_CARD_SELECTED ) ) ) { navigationBean.setHasBusinessCard( true ); } else { request.getSession().setAttribute( "businessCardForm", null ); navigationBean.setHasBusinessCard( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_SEC_CARD_SELECTED ) ) ) { navigationBean.setHasSecuredCard( true ); } else { request.getSession().setAttribute( "securedCardForm", null ); navigationBean.setHasSecuredCard( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.EQUIP_EXPRESS_SELECTED ) ) ) { navigationBean.setHasEquipExpress( true ); } else { request.getSession().setAttribute( "equipExpressForm", null ); navigationBean.setHasEquipExpress( false ); } request.getSession().setAttribute( "navigationBean", navigationBean ); }; Here is the action in the struts-config.xml: === input=".productSelection" name="productSelectionForm" parameter="action" scope="session" type="com.wf.bd.ice.creditapplication.CreditApplicationActions" validate="true"> Here is the test method: == public void testProductSelection() throws Exception { // JUnitDoclet begin method productSelection setRequestPathInfo( "/productSelection" ); addRequestParameter( "action", "nextPage" ); addRequestParameter( "businessLineSelected", "true" ); addRequestParameter( "businessCardSelected", "true" ); addRequestParameter( "businessSecuredCardSelected", "true" ); addRequestParameter( "equipmentExpressSelected", "true" ); actionPerform(); verifyForward( Constants.ERROR_FWD ); verifyForward( Constants.PRODUCTSELECTION_FWD ); //verifyActionErrors(new String[] {&qu
RE: Help with Cactus StrutsTestCase
Yes: /** * This is the method that defines the different button text items in a hashMap * for the BaseLookupDispatchAction to use. * * TODO: Need to externalize this, so these are not hard coded. */ protected Map getKeyMethodMap() { log.info( "getKeyMethodMap..." ); Map map = new HashMap(); ResourceBundle methods = ResourceBundle.getBundle( Constants.LOOKUP_METHOD_MESSAGE_RESOURCES ); Enumeration keys = methods.getKeys(); while( keys.hasMoreElements() ) { String key = ( String )keys.nextElement(); map.put( key, methods.getString( key ) ); } return map; } -Original Message- From: news [mailto:[EMAIL PROTECTED] Behalf Of Bill Siggelkow Sent: Thursday, August 26, 2004 10:53 AM To: [EMAIL PROTECTED] Subject: Re: Help with Cactus StrutsTestCase Is your LookupDispatchAction implementing getKeyMethodMap()? [EMAIL PROTECTED] wrote: > I am trying to write test cases for my Struts app, but can't seem to figure it out. > I have used the examples, but I don't seem to get the correct outcome when I run > them. > > I am using LookupDispatchAction's exclusively. > > So here is the method I am testing: > == > public void productSelectionAction( ActionMapping mapping > , ActionForm form > , HttpServletRequest request > , HttpServletResponse response ) { > log.info( "Process CreditApplicationActions productSelectionAction(...)" ); > > NavigationBean navigationBean = ( NavigationBean > )request.getSession().getAttribute( "navigationBean" ); > if( navigationBean == null ) { > navigationBean = new NavigationBean(); > } > > if( Constants.TRUE.equals( request.getParameter( Constants.BUS_LINE_SELECTED > ) ) ) { > navigationBean.setHasBusinessLine( true ); > } else { > request.getSession().setAttribute( "businessLineForm", null ); > navigationBean.setHasBusinessLine( false ); > } > > if( Constants.TRUE.equals( request.getParameter( Constants.BUS_CARD_SELECTED > ) ) ) { > navigationBean.setHasBusinessCard( true ); > } else { > request.getSession().setAttribute( "businessCardForm", null ); > navigationBean.setHasBusinessCard( false ); > } > > if( Constants.TRUE.equals( request.getParameter( > Constants.BUS_SEC_CARD_SELECTED ) ) ) { > navigationBean.setHasSecuredCard( true ); > } else { > request.getSession().setAttribute( "securedCardForm", null ); > navigationBean.setHasSecuredCard( false ); > } > > if( Constants.TRUE.equals( request.getParameter( > Constants.EQUIP_EXPRESS_SELECTED ) ) ) { > navigationBean.setHasEquipExpress( true ); > } else { > request.getSession().setAttribute( "equipExpressForm", null ); > navigationBean.setHasEquipExpress( false ); > } > > request.getSession().setAttribute( "navigationBean", navigationBean ); > }; > > > > > Here is the action in the struts-config.xml: > === > > input=".productSelection" > name="productSelectionForm" > parameter="action" > scope="session" > type="com.wf.bd.ice.creditapplication.CreditApplicationActions" > validate="true"> > > > redirect="true" /> > > > > > > > > > > > > > > > > > > > > Here is the test method: > == > public void testProductSelection() throws Exception { > // JUnitDoclet begin method productSelection > > setRequestPathInfo( "/productSelection" ); > > addRequestParameter( "action", "nextPage" ); > > addRequestParameter( "businessLineSelected", "true" ); > addRequestParameter( "businessCardSelected", "true" ); > addRequestParameter( "businessSecuredCardSelected", "true&qu
Re: Help with Cactus StrutsTestCase
Is your LookupDispatchAction implementing getKeyMethodMap()? [EMAIL PROTECTED] wrote: I am trying to write test cases for my Struts app, but can't seem to figure it out. I have used the examples, but I don't seem to get the correct outcome when I run them. I am using LookupDispatchAction's exclusively. So here is the method I am testing: == public void productSelectionAction( ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response ) { log.info( "Process CreditApplicationActions productSelectionAction(...)" ); NavigationBean navigationBean = ( NavigationBean )request.getSession().getAttribute( "navigationBean" ); if( navigationBean == null ) { navigationBean = new NavigationBean(); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_LINE_SELECTED ) ) ) { navigationBean.setHasBusinessLine( true ); } else { request.getSession().setAttribute( "businessLineForm", null ); navigationBean.setHasBusinessLine( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_CARD_SELECTED ) ) ) { navigationBean.setHasBusinessCard( true ); } else { request.getSession().setAttribute( "businessCardForm", null ); navigationBean.setHasBusinessCard( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_SEC_CARD_SELECTED ) ) ) { navigationBean.setHasSecuredCard( true ); } else { request.getSession().setAttribute( "securedCardForm", null ); navigationBean.setHasSecuredCard( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.EQUIP_EXPRESS_SELECTED ) ) ) { navigationBean.setHasEquipExpress( true ); } else { request.getSession().setAttribute( "equipExpressForm", null ); navigationBean.setHasEquipExpress( false ); } request.getSession().setAttribute( "navigationBean", navigationBean ); }; Here is the action in the struts-config.xml: === input=".productSelection" name="productSelectionForm" parameter="action" scope="session" type="com.wf.bd.ice.creditapplication.CreditApplicationActions" validate="true"> Here is the test method: == public void testProductSelection() throws Exception { // JUnitDoclet begin method productSelection setRequestPathInfo( "/productSelection" ); addRequestParameter( "action", "nextPage" ); addRequestParameter( "businessLineSelected", "true" ); addRequestParameter( "businessCardSelected", "true" ); addRequestParameter( "businessSecuredCardSelected", "true" ); addRequestParameter( "equipmentExpressSelected", "true" ); actionPerform(); verifyForward( Constants.ERROR_FWD ); verifyForward( Constants.PRODUCTSELECTION_FWD ); //verifyActionErrors(new String[] {"error.nodefault.implementation" } ); //verifyActionErrors(new String[] { "error.noaction.specified"} ); //NavigationBean navigationBean = (NavigationBean)getSession().getAttribute( "navigationBean" ); //assertTrue( "NavigationBean is null", navigationBean == null); verifyNoActionErrors(); // JUnitDoclet end method productSelection } And I get zero errors at all... --- Thanks... Mick Knutson 525 Market Street, SF, CA 94103 (415) 222-1020 [EMAIL PROTECTED] MAC A0103-223 --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help with Cactus StrutsTestCase
Check out "Struts The Complete Reference" by James Holmes -- I hear the chapter on Testing absolutely ROCKS ;) Bill Siggelkow Leandro Melo wrote: Sorry for the confusing sentence. I meant to say that i don`t know the answer, but i`d like to use the opportunity and also ask a basic question. Where can i find a good tutorial do test struts applications? Is it true that for good testing the actions must delegate their work to POJOs ?? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Help with Cactus StrutsTestCase
I have a Delegate pattern layer that all actions communicate with. But this action in particular, does not need anything except to create a POJO and add it to session. -Original Message- From: Leandro Melo [mailto:[EMAIL PROTECTED] Sent: Thursday, August 26, 2004 9:23 AM To: Struts Users Mailing List Subject: Re: Help with Cactus StrutsTestCase Doesn`t know the answer, where can i find a good tutorial do test struts applications? Is it true that for good testing the actions must delegate their work to POJOs ?? --- [EMAIL PROTECTED] escreveu: > I am trying to write test cases for my Struts app, > but can't seem to figure it out. > I have used the examples, but I don't seem to get > the correct outcome when I run them. > > I am using LookupDispatchAction's exclusively. > > So here is the method I am testing: > == > public void productSelectionAction( > ActionMapping mapping > , ActionForm > form > , > HttpServletRequest request > , > HttpServletResponse response ) { > log.info( "Process CreditApplicationActions > productSelectionAction(...)" ); > > NavigationBean navigationBean = ( > NavigationBean )request.getSession().getAttribute( > "navigationBean" ); > if( navigationBean == null ) { > navigationBean = new NavigationBean(); > } > > if( Constants.TRUE.equals( > request.getParameter( Constants.BUS_LINE_SELECTED ) > ) ) { > navigationBean.setHasBusinessLine( true > ); > } else { > request.getSession().setAttribute( > "businessLineForm", null ); > navigationBean.setHasBusinessLine( false > ); > } > > if( Constants.TRUE.equals( > request.getParameter( Constants.BUS_CARD_SELECTED ) > ) ) { > navigationBean.setHasBusinessCard( true > ); > } else { > request.getSession().setAttribute( > "businessCardForm", null ); > navigationBean.setHasBusinessCard( false > ); > } > > if( Constants.TRUE.equals( > request.getParameter( > Constants.BUS_SEC_CARD_SELECTED ) ) ) { > navigationBean.setHasSecuredCard( true > ); > } else { > request.getSession().setAttribute( > "securedCardForm", null ); > navigationBean.setHasSecuredCard( false > ); > } > > if( Constants.TRUE.equals( > request.getParameter( > Constants.EQUIP_EXPRESS_SELECTED ) ) ) { > navigationBean.setHasEquipExpress( true > ); > } else { > request.getSession().setAttribute( > "equipExpressForm", null ); > navigationBean.setHasEquipExpress( false > ); > } > > request.getSession().setAttribute( > "navigationBean", navigationBean ); > }; > > > > > Here is the action in the struts-config.xml: > === > > input=".productSelection" > name="productSelectionForm" > parameter="action" > scope="session" > > type="com.wf.bd.ice.creditapplication.CreditApplicationActions" > > validate="true"> > path=".productSelection" redirect="true" /> > path=".business" redirect="true" /> > path=".productSelection" redirect="true" /> > path=".business" redirect="true" /> > path=".firstOwner" redirect="true" /> > path=".secondOwner" redirect="true" /> > path=".businessLine" redirect="true" /> > path=".businessCard" redirect="true" /> > path=".securedCard" redirect="true" /> > path=".equipExpress" redirect="true" /> > path=".noSecondOwner" redirect="true" /> > path=".noBusinessLine" redirect="true" /> > path=".noBusinessCard" redirect="true" /> > path=".noSecuredCard" redirect="true" /> > path=".noEquipExpress" redirect="true" /> > path=".acceptanceAgreement
Re: Help with Cactus StrutsTestCase
Sorry for the confusing sentence. I meant to say that i don`t know the answer, but i`d like to use the opportunity and also ask a basic question. Where can i find a good tutorial do test struts applications? Is it true that for good testing the actions must delegate their work to POJOs ?? --- Leandro Melo <[EMAIL PROTECTED]> escreveu: > Doesn`t know the answer, where can i find a good > tutorial do test struts applications? > Is it true that for good testing the actions must > delegate their work to POJOs ?? > > > > --- [EMAIL PROTECTED] escreveu: > > I am trying to write test cases for my Struts app, > > but can't seem to figure it out. > > I have used the examples, but I don't seem to get > > the correct outcome when I run them. > > > > I am using LookupDispatchAction's exclusively. > > > > So here is the method I am testing: > > == > > public void productSelectionAction( > > ActionMapping mapping > > , > ActionForm > > form > > , > > HttpServletRequest request > > , > > HttpServletResponse response ) { > > log.info( "Process > CreditApplicationActions > > productSelectionAction(...)" ); > > > > NavigationBean navigationBean = ( > > NavigationBean )request.getSession().getAttribute( > > "navigationBean" ); > > if( navigationBean == null ) { > > navigationBean = new NavigationBean(); > > } > > > > if( Constants.TRUE.equals( > > request.getParameter( Constants.BUS_LINE_SELECTED > ) > > ) ) { > > navigationBean.setHasBusinessLine( > true > > ); > > } else { > > request.getSession().setAttribute( > > "businessLineForm", null ); > > navigationBean.setHasBusinessLine( > false > > ); > > } > > > > if( Constants.TRUE.equals( > > request.getParameter( Constants.BUS_CARD_SELECTED > ) > > ) ) { > > navigationBean.setHasBusinessCard( > true > > ); > > } else { > > request.getSession().setAttribute( > > "businessCardForm", null ); > > navigationBean.setHasBusinessCard( > false > > ); > > } > > > > if( Constants.TRUE.equals( > > request.getParameter( > > Constants.BUS_SEC_CARD_SELECTED ) ) ) { > > navigationBean.setHasSecuredCard( true > > ); > > } else { > > request.getSession().setAttribute( > > "securedCardForm", null ); > > navigationBean.setHasSecuredCard( > false > > ); > > } > > > > if( Constants.TRUE.equals( > > request.getParameter( > > Constants.EQUIP_EXPRESS_SELECTED ) ) ) { > > navigationBean.setHasEquipExpress( > true > > ); > > } else { > > request.getSession().setAttribute( > > "equipExpressForm", null ); > > navigationBean.setHasEquipExpress( > false > > ); > > } > > > > request.getSession().setAttribute( > > "navigationBean", navigationBean ); > > }; > > > > > > > > > > Here is the action in the struts-config.xml: > > === > > > > > input=".productSelection" > > name="productSelectionForm" > > parameter="action" > > scope="session" > > > > > type="com.wf.bd.ice.creditapplication.CreditApplicationActions" > > > > validate="true"> > > > path=".productSelection" redirect="true" /> > > > path=".business" redirect="true" /> > > > path=".productSelection" redirect="true" /> > > > path=".business" redirect="true" /> > > > path=".firstOwner" redirect="true" /> > > > path=".secondOwner" redirect="true" /> > > > path=".businessLine" redirect="true" /> > > > path=".businessCard" redirect="true" /> > > > path=".securedCard" redirect="true" /> > > > path=".equipExpress" redirect="true" /> > > > path=".noSecondOwner" redirect="true" /> > > > path=".noBusinessLine" redirect="true" /> > > > path=".noBusinessCard" redirect="true" /> > > > path=".noSecuredCard" redirect="true" /> > > > path=".noEquipExpress" redirect="true" /> > > > path=".acceptanceAgreement" redirect="true" /> > > > > > > > > > > > > > > Here is the test method: > > == > > public void testProductSelection() throws > > Exception { > > // JUnitDoclet begin method productSelection > > > > setRequestPathInfo( "/productSelection" ); > > > > addRequestParameter( "action", "nextPage" > ); > > > > addRequestParameter( > "businessLineSelected", > > "true" ); > > addRequestParameter( > "businessCardSelected", > > "true" ); > > addRequestParameter( > > "businessSecu
Re: Help with Cactus StrutsTestCase
Doesn`t know the answer, where can i find a good tutorial do test struts applications? Is it true that for good testing the actions must delegate their work to POJOs ?? --- [EMAIL PROTECTED] escreveu: > I am trying to write test cases for my Struts app, > but can't seem to figure it out. > I have used the examples, but I don't seem to get > the correct outcome when I run them. > > I am using LookupDispatchAction's exclusively. > > So here is the method I am testing: > == > public void productSelectionAction( > ActionMapping mapping > , ActionForm > form > , > HttpServletRequest request > , > HttpServletResponse response ) { > log.info( "Process CreditApplicationActions > productSelectionAction(...)" ); > > NavigationBean navigationBean = ( > NavigationBean )request.getSession().getAttribute( > "navigationBean" ); > if( navigationBean == null ) { > navigationBean = new NavigationBean(); > } > > if( Constants.TRUE.equals( > request.getParameter( Constants.BUS_LINE_SELECTED ) > ) ) { > navigationBean.setHasBusinessLine( true > ); > } else { > request.getSession().setAttribute( > "businessLineForm", null ); > navigationBean.setHasBusinessLine( false > ); > } > > if( Constants.TRUE.equals( > request.getParameter( Constants.BUS_CARD_SELECTED ) > ) ) { > navigationBean.setHasBusinessCard( true > ); > } else { > request.getSession().setAttribute( > "businessCardForm", null ); > navigationBean.setHasBusinessCard( false > ); > } > > if( Constants.TRUE.equals( > request.getParameter( > Constants.BUS_SEC_CARD_SELECTED ) ) ) { > navigationBean.setHasSecuredCard( true > ); > } else { > request.getSession().setAttribute( > "securedCardForm", null ); > navigationBean.setHasSecuredCard( false > ); > } > > if( Constants.TRUE.equals( > request.getParameter( > Constants.EQUIP_EXPRESS_SELECTED ) ) ) { > navigationBean.setHasEquipExpress( true > ); > } else { > request.getSession().setAttribute( > "equipExpressForm", null ); > navigationBean.setHasEquipExpress( false > ); > } > > request.getSession().setAttribute( > "navigationBean", navigationBean ); > }; > > > > > Here is the action in the struts-config.xml: > === > > input=".productSelection" > name="productSelectionForm" > parameter="action" > scope="session" > > type="com.wf.bd.ice.creditapplication.CreditApplicationActions" > > validate="true"> > path=".productSelection" redirect="true" /> > path=".business" redirect="true" /> > path=".productSelection" redirect="true" /> > path=".business" redirect="true" /> > path=".firstOwner" redirect="true" /> > path=".secondOwner" redirect="true" /> > path=".businessLine" redirect="true" /> > path=".businessCard" redirect="true" /> > path=".securedCard" redirect="true" /> > path=".equipExpress" redirect="true" /> > path=".noSecondOwner" redirect="true" /> > path=".noBusinessLine" redirect="true" /> > path=".noBusinessCard" redirect="true" /> > path=".noSecuredCard" redirect="true" /> > path=".noEquipExpress" redirect="true" /> > path=".acceptanceAgreement" redirect="true" /> > > > > > > > Here is the test method: > == > public void testProductSelection() throws > Exception { > // JUnitDoclet begin method productSelection > > setRequestPathInfo( "/productSelection" ); > > addRequestParameter( "action", "nextPage" ); > > addRequestParameter( "businessLineSelected", > "true" ); > addRequestParameter( "businessCardSelected", > "true" ); > addRequestParameter( > "businessSecuredCardSelected", "true" ); > addRequestParameter( > "equipmentExpressSelected", "true" ); > > actionPerform(); > > verifyForward( Constants.ERROR_FWD ); > verifyForward( > Constants.PRODUCTSELECTION_FWD ); > > //verifyActionErrors(new String[] > {"error.nodefault.implementation" } ); > //verifyActionErrors(new String[] { > "error.noaction.specified"} ); > > //NavigationBean navigationBean = > (NavigationBean)getSession().getAttribute( > "navigationBean" ); > //assertTrue( "NavigationBean is null", > navigationBean == null); > verifyNoActionErrors(); > > // JUnitDoclet end method productSelection >
Help with Cactus StrutsTestCase
I am trying to write test cases for my Struts app, but can't seem to figure it out. I have used the examples, but I don't seem to get the correct outcome when I run them. I am using LookupDispatchAction's exclusively. So here is the method I am testing: == public void productSelectionAction( ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response ) { log.info( "Process CreditApplicationActions productSelectionAction(...)" ); NavigationBean navigationBean = ( NavigationBean )request.getSession().getAttribute( "navigationBean" ); if( navigationBean == null ) { navigationBean = new NavigationBean(); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_LINE_SELECTED ) ) ) { navigationBean.setHasBusinessLine( true ); } else { request.getSession().setAttribute( "businessLineForm", null ); navigationBean.setHasBusinessLine( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_CARD_SELECTED ) ) ) { navigationBean.setHasBusinessCard( true ); } else { request.getSession().setAttribute( "businessCardForm", null ); navigationBean.setHasBusinessCard( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.BUS_SEC_CARD_SELECTED ) ) ) { navigationBean.setHasSecuredCard( true ); } else { request.getSession().setAttribute( "securedCardForm", null ); navigationBean.setHasSecuredCard( false ); } if( Constants.TRUE.equals( request.getParameter( Constants.EQUIP_EXPRESS_SELECTED ) ) ) { navigationBean.setHasEquipExpress( true ); } else { request.getSession().setAttribute( "equipExpressForm", null ); navigationBean.setHasEquipExpress( false ); } request.getSession().setAttribute( "navigationBean", navigationBean ); }; Here is the action in the struts-config.xml: === Here is the test method: == public void testProductSelection() throws Exception { // JUnitDoclet begin method productSelection setRequestPathInfo( "/productSelection" ); addRequestParameter( "action", "nextPage" ); addRequestParameter( "businessLineSelected", "true" ); addRequestParameter( "businessCardSelected", "true" ); addRequestParameter( "businessSecuredCardSelected", "true" ); addRequestParameter( "equipmentExpressSelected", "true" ); actionPerform(); verifyForward( Constants.ERROR_FWD ); verifyForward( Constants.PRODUCTSELECTION_FWD ); //verifyActionErrors(new String[] {"error.nodefault.implementation" } ); //verifyActionErrors(new String[] { "error.noaction.specified"} ); //NavigationBean navigationBean = (NavigationBean)getSession().getAttribute( "navigationBean" ); //assertTrue( "NavigationBean is null", navigationBean == null); verifyNoActionErrors(); // JUnitDoclet end method productSelection } And I get zero errors at all... --- > Thanks... > Mick Knutson > > 525 Market Street, SF, CA 94103 > (415) 222-1020 > [EMAIL PROTECTED] > MAC A0103-223 --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
StrutsTestCase servlet api 2.4
Is there a way to get strutstestcase (mock) to work with the new 2.4 web.xml. Currently when we try this it bombs on the digesting of the web.xml file with this: Digester.error(1439) | Parse Error at line 6 column 104: Document root element "web-app", must match DOCTYPE root "null". org.xml.sax.SAXParseException: Document root element "web-app", must match DOCTYPE root "null". Any help is greatly appreciated. I tried asking on the strutstestcase forum, but got no answer. -warner - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]