I have used this testing code to a certain extend, and seems to work fine. So I am interested in making it work against a complete test case scenario.
So, when trying to load a child entity after the parent is retrieved, I get a LazyInitializationException Error. Sure enough, when the system tries to load the dependent collection, it doesn't find a session or thinks the session was closed. During development this is solved by the org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter filter declared in the web.xml file. So, I tried adding that file in the BaseStrutsTestCase in the CONFIG_LOCATIONS String: private static final String CONFIG_LOCATIONS = "..../WEB-INF/applicationContext.xml," + ".../WEB-INF/web.xml"; This time the error is: ERROR ContextLoader:215 - Context initialization failed org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://java.sun.com/xml/ns/j2ee] Offending resource: URL [file:/C:/...../WebContent/WEB-INF/web.xml] The CONFIG_LOCATIONS is used to initialize the servletContext which in turn is used to initialize the applicationContext, right? So, I am not sure where is the correct place to add the web.xml file, or how to tell BaseStrutsTestCase to include OpenEntityManagerInViewFilter during the recreation of the framework. Is that a limitation of this test class, or I am trying to include my web.xml file the wrong way? I am not sure if other folks using this example code dealt with something like this in the past and solved it. Haroon, I hope you don't mind my asking you again about this :) Also, a more general question: Can the proxy class be used to create and run two actions sequentially? Let's say I want to test an action in my secure namespace, meaning that some sort of login or registration action comes first. So, could I do something like this in my test method?: @Test public void testExecute() throws Exception{ Login testLogin = createAction(Login.class, "/", "Login"); //set my fields testLogin.setPassword("..."); //execute proxy once proxy.execute(); //Then create my secure action UpdateProfile testUpdateProfile = createAction(UpdateProfile.class, "/secure", "UpdateProfile"); //and then execute proxy again proxy.execute(); } This doesn't seem to work when I tried it. Could that be a violation of the ActionProxy rules? Before digging any deeper I just thought to ask this, in case there is another way to link and execute several sequential actions within the same test? Up until now I manually created mock objects to satisfy any dependencies of the class under test: Created a user object and put in on a Session map manually to simulate a successful login action. So the motive here was to use this example test code to actually create and execute a successful test of the predecessor action (so the login action itself could add the logged in user to the session) before the actual action that I am primarily testing (updateProfile). Anyway, I sure hope I am not stretching this conversation too far by experimenting a bit further with this example. Any suggestions are appreciated. Regards. On Mon, Jul 20, 2009 at 5:02 PM, Haroon Rafique<haroon.rafi...@utoronto.ca> wrote: > On Today at 4:32pm, DC=>Dimitrios Christodoulakis <dimi....@gmail.com> wrote: > > DC> Thanks Haroon for the handy advice. That seems to do the trick as far > DC> as the session object is concerned. The test passes now. > DC> > > Glad it worked out. > > DC> > DC> Would it be easy for someone to extend your code to include actions > DC> that implement the -aware interfaces? If I wanted to take a shot at > DC> that, is there a particular point you would suggest I start with? > DC> > > Did you add that code in your Test class? I was actually suggesting that > you modify the code inside BaseStrutsTestCase. So, I would recommend > adding a private static HashMap variable called sessionMap in > BaseStrutsTestCase. And then in the createAction method, issue the > statement: > proxy.getInvocation().getInvocationContext().setSession(sessionMap); > > Hope that helps. > > The only other fringe case that I have dealth with in our code, is when we > have actions that implement Preparable and are used with a > ParamsPrepareParams interceptor. I created a method to allow action > parameters to be set. > > /** > * Sets the action parameters > * @param parameters Parameters to set > */ > protected void setActionParameters(Map<String, String> > parameters) { > proxy.getInvocation().getInvocationContext(). > setParameters(parameters); > } > > Then inside my Action Test class, I can issue: > proxy.setActionParameters(...); > before: > proxy.execute(); > > Cheers, > -- > Haroon Rafique > <haroon.rafi...@utoronto.ca> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org