Struts 2
  1. Struts 2
  2. WW-3442

StrutsTestCase does not initialise session map

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.8.1
    • Fix Version/s: 2.3.3
    • Component/s: None
    • Labels:
      None

      Description

      In our unit tests we were setting http session object attributes but these we never getting copied into the action session map as it was not being initialised correctly in the getActionProxy method.

      By adding the following code at the end of the method test worked correctly

      ActionContext.getContext().setSession(new HashMap<String, Object>());

        Activity

        Paul Grove created issue -
        Lukasz Lenart made changes -
        Field Original Value New Value
        Fix Version/s 2.3.x [ 12319176 ]
        Maurizio Cucchiara made changes -
        Assignee Maurizio Cucchiara [ maurizio.cucchiara ]
        Lukasz Lenart made changes -
        Fix Version/s 2.3.3 [ 12320642 ]
        Fix Version/s 2.3.x [ 12319176 ]
        Hide
        Lukasz Lenart added a comment - - edited

        Added additional initSession() method to StrutsTestCase, is it sufficient ?

        protected void initActionContext(ActionContext actionContext) {
            actionContext.setParameters(new HashMap<String, Object>(request.getParameterMap()));
            initSession(actionContext);
            initPortletContext(actionContext);
            applyAdditionalParams(actionContext);
            // set the action context to the one used by the proxy
            ActionContext.setContext(actionContext);
        }
        
        protected void initSession(ActionContext actionContext) {
            Map<String, Object> session = actionContext.getSession();
            if (session == null) {
                actionContext.setSession(new HashMap<String, Object>());
            }
        }
        
        Show
        Lukasz Lenart added a comment - - edited Added additional initSession() method to StrutsTestCase, is it sufficient ? protected void initActionContext(ActionContext actionContext) { actionContext.setParameters( new HashMap< String , Object >(request.getParameterMap())); initSession(actionContext); initPortletContext(actionContext); applyAdditionalParams(actionContext); // set the action context to the one used by the proxy ActionContext.setContext(actionContext); } protected void initSession(ActionContext actionContext) { Map< String , Object > session = actionContext.getSession(); if (session == null ) { actionContext.setSession( new HashMap< String , Object >()); } }
        Lukasz Lenart made changes -
        Assignee Maurizio Cucchiara [ maurizio.cucchiara ] Lukasz Lenart [ lukaszlenart ]
        Hide
        Lukasz Lenart added a comment -

        Solved, thanks for reporting!

        Show
        Lukasz Lenart added a comment - Solved, thanks for reporting!
        Lukasz Lenart made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Hudson added a comment -

        Integrated in Struts2 #452 (See https://builds.apache.org/job/Struts2/452/)
        WW-3442 adds Session initialisation method to solve problem with missing session and allow to initialise session on its own in test cases (Revision 1311951)

        Result = SUCCESS
        lukaszlenart :
        Files :

        • /struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
        Show
        Hudson added a comment - Integrated in Struts2 #452 (See https://builds.apache.org/job/Struts2/452/ ) WW-3442 adds Session initialisation method to solve problem with missing session and allow to initialise session on its own in test cases (Revision 1311951) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
        Hide
        Hudson added a comment -

        Integrated in Struts2 #454 (See https://builds.apache.org/job/Struts2/454/)
        WW-3442 adds additional initialisation of HttpSession (Revision 1324893)

        Result = SUCCESS
        lukaszlenart :
        Files :

        • /struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
        Show
        Hudson added a comment - Integrated in Struts2 #454 (See https://builds.apache.org/job/Struts2/454/ ) WW-3442 adds additional initialisation of HttpSession (Revision 1324893) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
        Lukasz Lenart made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        722d 6h 5m 1 Lukasz Lenart 10/Apr/12 20:34
        Resolved Resolved Closed Closed
        3d 11h 41m 1 Lukasz Lenart 14/Apr/12 08:15

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            Paul Grove
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development