Announcement Announcement Module
Collapse
No announcement yet.
MockStrutsTestoes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MockStrutsTestoes

    Hi all,
    Am having some grief wuth MockStrutsTestCase at themoment. We recently uodated our Hibernate app to use lazy loading. Now whenever we try and run any struts web tests we get the following exceptions:

    An uncaught exception was thrown during actionExecute()

    servletunit.struts.ExceptionDuringTestError: An uncaught exception was thrown during actionExecute()
    at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:409)
    at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:28)
    ------------
    Root Cause:
    ------------
    javax.servlet.ServletException
    at org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:527)
    at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:423)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
    at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
    at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:394)
    at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:28)
    ------------
    Root Cause:
    ------------
    java.lang.NullPointerException
    at com.cis.cistrs.webapp.action.ActionExceptionHandle r.execute(ActionExceptionHandler.java:87)
    at org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:524)
    at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:423)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
    at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
    at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:394)
    at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:28)

    I am at a loss as to the cause of this problem and any help would be appreciated. These errors occur on every test of the classes we set lazy="true" on.

    we are using xDoclet, Spring, Struts and Hibernate.

    regards,
    Simon Ward

  • #2
    Well, it looks like the exception occurs prior to actually calling your action.

    What are some things that could cause that?

    Have you stepped through the code using a debugger to see exactly when the exception occurs? For example, what object is null that throws the NullPointerException?


    I've dealt with a lot of different StrutsTestCase of Cactus and Mock variety. Throw some more info on here.

    Comment


    • #3
      An uncaught exception was thrown during actionExecute()

      servletunit.struts.ExceptionDuringTestError: An uncaught exception was thrown during actionExecute()
      at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:409)
      at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:2
      The actionExecute() method is the surface method in my app where these errors originate. My debugger gets to this and then the app moves into the spring org.springframework.mock.web.MockServletContext tree. This tree is not part of the app build path, but in the server lib dir, which we are using for development, rather the app we are developing. So the debugger cannot step into this method from Eclipse. As this appears to be more like an internal spring error, i was hoping someone here could clarrify this.

      Well, it looks like the exception occurs prior to actually calling your action
      as you can see from the stack trace, the actionExecute() method throws the exception. You dont get more into an action than that! :wink:

      As for what object is null...seeing as nothing is actually passed to this method it beats the hell outta me. :?:

      I am considering reverting to Cactus but am reluctant...is about%50 slower testing than the current method.

      Comment


      • #4
        heres some cod ethat make up the web tests:


        BaseStrutsTestCase.java
        Code:
        public abstract class BaseStrutsTestCase extends MockStrutsTestCase {
            //~ Instance fields ========================================================
        
            protected transient final Log log = LogFactory.getLog(getClass());
            protected User user = null;
            protected ResourceBundle rb = null;
            protected WebApplicationContext ctx = null;
            protected SessionFactory sessionFactory;
            protected Session session;
            
            //~ Constructors ===========================================================
        
            public BaseStrutsTestCase(String name) {
                super(name);
                // Since a ResourceBundle is not required for each class, just
                // do a simple check to see if one exists
                String className = this.getClass().getName();
        
                try {
                    rb = ResourceBundle.getBundle(className);
                } catch (MissingResourceException mre) {
                    //log.warn("No resource bundle found for: " + className);
                }
            }
        
            //~ Methods ================================================================
        
            protected void setUp() throws Exception {
                super.setUp();       
                
                // initialize Spring
                String pkg = ClassUtils.classPackageAsResourcePath(Constants.class);
                MockServletContext sc = new MockServletContext("");
                sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "classpath*:/" + pkg + "/dao/applicationContext-*.xml," + "classpath*:META-INF/applicationContext-*.xml");
                
                ServletContextListener contextListener = new ContextLoaderListener();
                ServletContextEvent event = new ServletContextEvent(sc);
                contextListener.contextInitialized(event);
                
                // magic bridge to make StrutsTestCase aware of Spring's Context
                getSession().getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
                
                ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getSession().getServletContext());
                
                // populate the userForm and place into session
                UserManager userMgr = (UserManager) ctx.getBean("userManager");
                user = userMgr.getUser("medwards");
                getSession().setAttribute(Constants.USER_KEY, user);
        
                // change the port on the mailSender so it doesn't conflict with an 
                // existing SMTP server on localhost
                JavaMailSenderImpl mailSender = (JavaMailSenderImpl) ctx.getBean("mailSender");
                mailSender.setPort(2525);
                mailSender.setHost("localhost");
            }
            
            public void tearDown() throws Exception {
                super.tearDown();
                ctx = null;
            }
        }
        FacultyActionTest.java
        Code:
        public class FacultyActionTest extends BaseStrutsTestCase{
            
            public FacultyActionTest(String name) {
                super(name);
            }
            
            public void testCancel() throws Exception {
                setRequestPathInfo("/editFaculty");
                addRequestParameter("method", "Cancel");
                actionPerform();
        
                verifyForward("mainMenu");
                verifyNoActionErrors();
            }
            
            public void testEdit() throws Exception {
                setRequestPathInfo("/editFaculty");
                addRequestParameter("method", "Edit");
                addRequestParameter("partyRoleCode", "F2");
        
                actionPerform();
        
                verifyForward("edit");
                assertTrue(request.getAttribute(Constants.FACULTY_KEY) != null);
                verifyNoActionErrors();
            }
        
            public void testSave() throws Exception {
                setRequestPathInfo("/editFaculty");
                addRequestParameter("method", "Edit");
                addRequestParameter("partyRoleCode", "F2");
        
                actionPerform();
        
                FacultyForm facultyForm = (FacultyForm) request.getAttribute(Constants.FACULTY_KEY);
                assertTrue(facultyForm != null);
                
                setRequestPathInfo("/saveFaculty");
                addRequestParameter("method", "Save");
        
                // update the form from the edit and add it back to the request
                facultyForm.setFacultyName("testFacultyActionSave");
                request.setAttribute(Constants.FACULTY_KEY, facultyForm);
        
                actionPerform();
        
                verifyForward("viewFaculties");
                verifyNoActionErrors();
            }
        
            public void testRemove() throws Exception {
                setRequestPathInfo("/editFaculty");
                addRequestParameter("method", "Delete");
                addRequestParameter("partyRoleCode", "F3");
                actionPerform();
        
                verifyForward("viewFaculties");
                verifyNoActionErrors();
            }
            public void testSearch() {  
                setRequestPathInfo("/editFaculty");  
                addRequestParameter("method", "Search");  
                actionPerform();  
          
                verifyForward("list");  
          
                assertNotNull(getRequest().getAttribute(Constants.FACULTY_LIST));  
                verifyNoActionErrors();  
            } 
            
            public void testSearchActive() {  
                setRequestPathInfo("/editFaculty");
                addRequestParameter("method", "SearchActive");  
                actionPerform();  
          
                verifyForward("list");  
          
                assertNotNull(getRequest().getAttribute(Constants.FACULTY_LIST));  
                verifyNoActionErrors();  
            } 
            
            public void testSearchInactive() {  
                setRequestPathInfo("/editFaculty");  
                addRequestParameter("method", "SearchInactive");  
                actionPerform();  
          
                verifyForward("list");  
          
                assertNotNull(getRequest().getAttribute(Constants.FACULTY_LIST));  
                verifyNoActionErrors();  
            } 
        }
        which produces the folowing error
        Code:
        testEdit Error An uncaught exception was thrown during actionExecute()
        
        servletunit.struts.ExceptionDuringTestError: An uncaught exception was thrown during actionExecute() 
        at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:409) 
        at com.cis.cistrs.webapp.action.FacultyActionTest.testEdit(FacultyActionTest.java:36)
        ------------
        Root Cause:
        ------------
        javax.servlet.ServletException 
        at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:527) 
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423) 
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226) 
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164) 
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415) 
        at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:394) 
        at com.cis.cistrs.webapp.action.FacultyActionTest.testEdit(FacultyActionTest.java:36)
        ------------
        Root Cause:
        ------------
        java.lang.NullPointerException 
        at com.cis.cistrs.webapp.action.ActionExceptionHandler.execute(ActionExceptionHandler.java:87) 
        at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:524) 
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423) 
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226) 
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164) 
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415) 
        at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:394) 
        at com.cis.cistrs.webapp.action.FacultyActionTest.testEdit(FacultyActionTest.java:36)
        lemme know if you need anything else

        Simon

        Comment


        • #5
          Arghh

          Ok, we have narrowed it down to a closed lazy loading session. see below:
          Code:
          [junit] ------------- Standard Output ---------------
          [junit] Faculty name: Science And Agriculture
          [junit] Error: java.lang.reflect.InvocationTargetException
          [junit] Faculty Form Name: null
          [junit] Faculty name: Science And Agriculture
          [junit] Error: java.lang.reflect.InvocationTargetException
          [junit] Faculty Form Name: null
          [junit] ------------- ---------------- ---------------
          [junit] ------------- Standard Error -----------------
          [junit] java.lang.reflect.InvocationTargetException
          [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          [junit]     at java.lang.reflect.Method.invoke(Method.java:585)
          [junit]     at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1773)
          [junit]     at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759)
          [junit]     at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:447)
          [junit]     at org.apache.commons.beanutils.BeanUtilsBean.copyProperties(BeanUtilsBean.java:261)
          [junit]     at org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:114)
          [junit]     at com.cis.cistrs.util.ConvertUtil.convert(ConvertUtil.java:155)
          [junit]     at com.cis.cistrs.webapp.action.BaseAction.convert(BaseAction.java:113)
          [junit]     at com.cis.cistrs.webapp.action.FacultyAction.edit(FacultyAction.java:119)
          [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          [junit]     at java.lang.reflect.Method.invoke(Method.java:585)
          [junit]     at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)
          [junit]     at com.cis.cistrs.webapp.action.BaseAction.execute(BaseAction.java:220)
          [junit]     at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
          [junit]     at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
          [junit]     at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
          [junit]     at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
          [junit]     at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:394)
          [junit]     at com.cis.cistrs.webapp.action.FacultyActionTest.testEdit(FacultyActionTest.java:36)
          [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          [junit]     at java.lang.reflect.Method.invoke(Method.java:585)
          [junit]     at junit.framework.TestCase.runTest(TestCase.java:154)
          [junit]     at junit.framework.TestCase.runBare(TestCase.java:127)
          [junit]     at junit.framework.TestResult$1.protect(TestResult.java:106)
          [junit]     at junit.framework.TestResult.runProtected(TestResult.java:124)
          [junit]     at junit.framework.TestResult.run(TestResult.java:109)
          [junit]     at junit.framework.TestCase.run(TestCase.java:118)
          [junit]     at junit.framework.TestSuite.runTest(TestSuite.java:208)
          [junit]     at junit.framework.TestSuite.run(TestSuite.java:203)
          [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:297)
          [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:672)
          [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:546)
          [junit] Caused by: java.lang.reflect.InvocationTargetException
          [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          [junit]     at java.lang.reflect.Method.invoke(Method.java:585)
          [junit]     at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1773)
          [junit]     at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1132)
          [junit]     at org.apache.commons.beanutils.BeanUtilsBean.copyProperties(BeanUtilsBean.java:259)
          [junit]     at org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:114)
          [junit]     at com.cis.cistrs.util.ConvertUtil.convert(ConvertUtil.java:155)
          [junit]     at com.cis.cistrs.webapp.form.FacultyForm.setAcademicInstitution(FacultyForm.java:82)
          [junit]     ... 39 more
          [junit] Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
          [junit]     at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
          [junit]     at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
          [junit]     at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
          &#91;junit&#93;     at com.cis.cistrs.model.AcademicInstitution$$EnhancerByCGLIB$$b7aa3a4f.getEnabled&#40;<generated>&#41;
          &#91;junit&#93;     ... 49 more
          &#91;junit&#93; java.lang.reflect.InvocationTargetException
          &#91;junit&#93;     at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
          &#91;junit&#93;     at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
          &#91;junit&#93;     at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
          &#91;junit&#93;     at java.lang.reflect.Method.invoke&#40;Method.java&#58;585&#41;
          &#91;junit&#93;     at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod&#40;PropertyUtilsBean.java&#58;1773&#41;
          &#91;junit&#93;     at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty&#40;PropertyUtilsBean.java&#58;1759&#41;
          &#91;junit&#93;     at org.apache.commons.beanutils.BeanUtilsBean.copyProperty&#40;BeanUtilsBean.java&#58;447&#41;
          &#91;junit&#93;     at org.apache.commons.beanutils.BeanUtilsBean.copyProperties&#40;BeanUtilsBean.java&#58;261&#41;
          &#91;junit&#93;     at org.apache.commons.beanutils.BeanUtils.copyProperties&#40;BeanUtils.java&#58;114&#41;
          &#91;junit&#93;     at com.cis.cistrs.util.ConvertUtil.convert&#40;ConvertUtil.java&#58;155&#41;
          &#91;junit&#93;     at com.cis.cistrs.webapp.action.BaseAction.convert&#40;BaseAction.java&#58;113&#41;
          &#91;junit&#93;     at com.cis.cistrs.webapp.action.FacultyAction.edit&#40;FacultyAction.java&#58;119&#41;
          &#91;junit&#93;     at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
          &#91;junit&#93;     at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
          &#91;junit&#93;     at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
          &#91;junit&#93;     at java.lang.reflect.Method.invoke&#40;Method.java&#58;585&#41;
          &#91;junit&#93;     at org.apache.struts.actions.DispatchAction.dispatchMethod&#40;DispatchAction.java&#58;276&#41;
          &#91;junit&#93;     at com.cis.cistrs.webapp.action.BaseAction.execute&#40;BaseAction.java&#58;220&#41;
          &#91;junit&#93;     at org.apache.struts.action.RequestProcessor.processActionPerform&#40;RequestProcessor.java&#58;421&#41;
          &#91;junit&#93;     at org.apache.struts.action.RequestProcessor.process&#40;RequestProcessor.java&#58;226&#41;
          &#91;junit&#93;     at org.apache.struts.action.ActionServlet.process&#40;ActionServlet.java&#58;1164&#41;
          &#91;junit&#93;     at org.apache.struts.action.ActionServlet.doPost&#40;ActionServlet.java&#58;415&#41;
          &#91;junit&#93;     at servletunit.struts.MockStrutsTestCase.actionPerform&#40;MockStrutsTestCase.java&#58;394&#41;
          &#91;junit&#93;     at com.cis.cistrs.webapp.action.FacultyActionTest.testSave&#40;FacultyActionTest.java&#58;48&#41;
          &#91;junit&#93;     at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
          &#91;junit&#93;     at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
          &#91;junit&#93;     at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
          &#91;junit&#93;     at java.lang.reflect.Method.invoke&#40;Method.java&#58;585&#41;
          &#91;junit&#93;     at junit.framework.TestCase.runTest&#40;TestCase.java&#58;154&#41;
          &#91;junit&#93;     at junit.framework.TestCase.runBare&#40;TestCase.java&#58;127&#41;
          &#91;junit&#93;     at junit.framework.TestResult$1.protect&#40;TestResult.java&#58;106&#41;
          &#91;junit&#93;     at junit.framework.TestResult.runProtected&#40;TestResult.java&#58;124&#41;
          &#91;junit&#93;     at junit.framework.TestResult.run&#40;TestResult.java&#58;109&#41;
          &#91;junit&#93;     at junit.framework.TestCase.run&#40;TestCase.java&#58;118&#41;
          &#91;junit&#93;     at junit.framework.TestSuite.runTest&#40;TestSuite.java&#58;208&#41;
          &#91;junit&#93;     at junit.framework.TestSuite.run&#40;TestSuite.java&#58;203&#41;
          &#91;junit&#93;     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run&#40;JUnitTestRunner.java&#58;297&#41;
          &#91;junit&#93;     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch&#40;JUnitTestRunner.java&#58;672&#41;
          &#91;junit&#93;     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main&#40;JUnitTestRunner.java&#58;546&#41;
          &#91;junit&#93; Caused by&#58; java.lang.reflect.InvocationTargetException
          &#91;junit&#93;     at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
          &#91;junit&#93;     at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
          &#91;junit&#93;     at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
          &#91;junit&#93;     at java.lang.reflect.Method.invoke&#40;Method.java&#58;585&#41;
          &#91;junit&#93;     at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod&#40;PropertyUtilsBean.java&#58;1773&#41;
          &#91;junit&#93;     at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty&#40;PropertyUtilsBean.java&#58;1132&#41;
          &#91;junit&#93;     at org.apache.commons.beanutils.BeanUtilsBean.copyProperties&#40;BeanUtilsBean.java&#58;259&#41;
          &#91;junit&#93;     at org.apache.commons.beanutils.BeanUtils.copyProperties&#40;BeanUtils.java&#58;114&#41;
          &#91;junit&#93;     at com.cis.cistrs.util.ConvertUtil.convert&#40;ConvertUtil.java&#58;155&#41;
          &#91;junit&#93;     at com.cis.cistrs.webapp.form.FacultyForm.setAcademicInstitution&#40;FacultyForm.java&#58;82&#41;
          &#91;junit&#93;     ... 39 more
          &#91;junit&#93; Caused by&#58; org.hibernate.LazyInitializationException&#58; could not initialize proxy - the owning Session was closed
          &#91;junit&#93;     at org.hibernate.proxy.AbstractLazyInitializer.initialize&#40;AbstractLazyInitializer.java&#58;53&#41;
          &#91;junit&#93;     at org.hibernate.proxy.AbstractLazyInitializer.getImplementation&#40;AbstractLazyInitializer.java&#58;84&#41;
          &#91;junit&#93;     at org.hibernate.proxy.CGLIBLazyInitializer.intercept&#40;CGLIBLazyInitializer.java&#58;134&#41;
          &#91;junit&#93;     at com.cis.cistrs.model.AcademicInstitution$$EnhancerByCGLIB$$b7aa3a4f.getEnabled&#40;<generated>&#41;
          &#91;junit&#93;     ... 49 more
          &#91;junit&#93; ------------- ---------------- ---------------
          &#91;junit&#93; Testcase&#58; testSave&#40;com.cis.cistrs.webapp.action.FacultyActionTest&#41;&#58; FAILED
          &#91;junit&#93; was expecting '/editFaculty.html?method=Search' but received '/WEB-INF/pages/facultyForm.jsp'
          &#91;junit&#93; junit.framework.AssertionFailedError&#58; was expecting '/editFaculty.html?method=Search' but received '/WEB-INF/pages/facultyForm.jsp'
          &#91;junit&#93;     at servletunit.struts.Common.verifyForwardPath&#40;Common.java&#58;339&#41;
          &#91;junit&#93;     at servletunit.struts.MockStrutsTestCase.verifyForward&#40;MockStrutsTestCase.java&#58;675&#41;
          &#91;junit&#93;     at com.cis.cistrs.webapp.action.FacultyActionTest.testSave&#40;FacultyActionTest.java&#58;62&#41;
          Any ideas on what ...where i need to integrate a Hibernate session to keep this going? keep in mind we are testing outside the container so there is no server availiable.

          thanx
          Simon

          Comment


          • #6
            ...

            Comment


            • #7
              First things first:

              My interpretation of your original posting.....

              An uncaught exception was thrown during actionExecute()

              servletunit.struts.ExceptionDuringTestError: An uncaught exception was thrown during actionExecute()
              at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:409)
              at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:2
              ------------
              Root Cause:
              ------------
              javax.servlet.ServletException
              at org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:527)
              at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:423)
              at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
              at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
              at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
              at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:394)
              at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:2
              ------------
              Root Cause:
              ------------
              java.lang.NullPointerException
              at com.cis.cistrs.webapp.action.ActionExceptionHandle r.execute(ActionExceptionHandler.java:87)
              at org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:524)
              at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:423)
              at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
              at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
              at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
              at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:394)
              at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:2
              The bottom section:

              ------------
              Root Cause:
              ------------
              java.lang.NullPointerException
              at com.cis.cistrs.webapp.action.ActionExceptionHandle r.execute(ActionExceptionHandler.java:87)
              at org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:524)
              at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:423)
              at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
              at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
              at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
              at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:394)
              at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:2
              ...means that a NullPointerException occurred in your code at ActionExceptionHandler.java:87

              The next block....:
              ------------
              Root Cause:
              ------------
              javax.servlet.ServletException
              at org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:527)
              at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:423)
              at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
              at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
              at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
              at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:394)
              at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:36)
              ...this means Struts caught the NullPointerException that originated in your code via Strut's processActionPerform method of the RequestProcessor.

              The next block ...:

              servletunit.struts.ExceptionDuringTestError: An uncaught exception was thrown during actionExecute()
              at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:409)
              at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:36)
              ------------
              Root Cause:
              ------------
              javax.servlet.ServletException
              at org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:527)
              at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:423)
              at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
              at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
              at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
              at servletunit.struts.MockStrutsTestCase.actionPerfor m(MockStrutsTestCase.java:394)
              at com.cis.cistrs.webapp.action.FacultyActionTest.tes tEdit(FacultyActionTest.java:36)
              This means that MockStrutsTestCase caught the exception and logged it again. The fact that it says:

              An uncaught exception was thrown during actionExecute()
              ...simply means that MockStrutsTestCase caught an exception in the "actionPerform" method. They changed the name of the log output to say "actionExecute" to be more in-line with the latest Struts terms but probably left the actual method name to be "actionPeform" because it is then more backwards compatible for their own library. (just a worthless guess).

              NOW, all that said:

              You mentioned:

              as you can see from the stack trace, the actionExecute() method throws the exception. You dont get more into an action than that!
              Actually, you can get a LOT more in the action than that. The fact that actionExecute occurred doesn't mean your action's execute method was called. Much magic occurs before that happens.

              Now, your latest posting shows a completely different stack dump which means you probably figured out what was causing your original problem?

              Let me know more about where you are at now because it seems to me as though the problem here has shifted.

              Comment


              • #8
                No, its the same problem, the latest dump is the actual errors that are thrown....not the null pointer or the Servlet exception. Consider it a "caused by" dump.

                The problem which is calling all the errors is that the Hibernate session is closed when the servlet tried to convert a Faculty object to a FacultyForm Object.

                So a lypical "edit" action from facultyAction.java looks like
                Code:
                public ActionForward edit&#40;ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response&#41; throws Exception &#123;
                        if &#40;log.isDebugEnabled&#40;&#41;&#41; &#123;
                            log.debug&#40;"Entering 'edit' method"&#41;;
                        &#125;
                
                        FacultyForm facultyForm = &#40;FacultyForm&#41; form;
                        
                        // if an id is passed in, look up the user - otherwise
                        // don't do anything - user is doing an add
                        if &#40;facultyForm.getPartyRoleCode&#40;&#41; != null&#41; &#123;
                            FacultyManager mgr = &#40;FacultyManager&#41; getBean&#40;"facultyManager"&#41;;
                            Faculty faculty = mgr.getFaculty&#40;facultyForm.getPartyRoleCode&#40;&#41;&#41;;
                            
                            try&#123;
                            facultyForm = &#40;FacultyForm&#41; convert&#40;faculty&#41;;
                           
                            &#125;catch&#40;Exception e&#41;&#123;
                            	System.out.println&#40;"Error&#58; " + e&#41;;
                            	e.printStackTrace&#40;&#41;;
                            &#125;
                            
                            updateFormBean&#40;mapping, request, facultyForm&#41;;
                        &#125;
                        return mapping.findForward&#40;"edit"&#41;;
                    &#125;
                So what happens is when the test runs, it calls actionEecute(); this then runs this method passing a partyRoleCode of F2 to the edit method.

                we then get an instance of a faculty manager which will fetch a faculty for us.

                This is where the problems start. using lazy loadin it will fetch the faculty but the object will not be populated.

                Next we call the convert method and this is where it crashes. You see there is no persistant hibernate session for the convert method to fecth all of the faculty data, hence the servlet exception

                This in turn means that the convert method cant return the facultyForm...hence the Null pointer exception.

                That about sums it up I think.

                TIA,
                Simon

                Comment


                • #9
                  sorry about the poor english. I am using the worlds smallest keyboard. very frustrating.

                  Comment

                  Working...
                  X