[JIRA] Created: (STS-494) MockServletContext needs ServletContextListener add/remove methods

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[JIRA] Created: (STS-494) MockServletContext needs ServletContextListener add/remove methods

JIRA jira@stripesframework.org
MockServletContext needs  ServletContextListener add/remove methods
-------------------------------------------------------------------

                 Key: STS-494
                 URL: http://www.stripesframework.org/jira/browse/STS-494
             Project: Stripes
          Issue Type: New Feature
          Components: Context Management
    Affects Versions: Release 1.5
            Reporter: David G. Friedman
            Assignee: Tim Fennell


I have modified my copy of the Trunk to allow for adding and removing ServletContextListeners to be Mock tested.  I have included my code for your consideration.  To  allow for easier testing I pass in new()d class instances. This also avoids possible typing errors by passing in Strings as in a standard web.xml file This also allows for simpler testing (see my example test class below).

>From MockServletContext.java

 private List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();

    public void removeListeners() {
        ServletContextEvent e = new ServletContextEvent(this);

        if (listeners == null || listeners.size() == 0) {
           return;
        }

        for (ServletContextListener l : listeners) {
            l.contextDestroyed(e);
       }
        listeners.clear();
 }

    public void addListener(ServletContextListener listener) {
        ServletContextEvent e = new ServletContextEvent(this);
        listener.contextInitialized(e);
        listeners.add(listener);
    }

    public void addListeners(List<ServletContextListener> l) {
        for (ServletContextListener s : l) {
            addListener(s);
        }
    }

>From my test class:

public class ListenerT {

    private MockServletContext context = MockTestFixture.getServletContext();

    @Test
    public void addListeners() {
        List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();
        listeners.add(new ServletContextListener() {
            public void contextDestroyed(ServletContextEvent event) {
                event.getServletContext().removeAttribute("ListenerOne");
            }

            public void contextInitialized(ServletContextEvent event) {
                event.getServletContext().setAttribute("ListenerOne", "ListenerOneMessage");
            }
        });
        listeners.add(new ServletContextListener() {
            public void contextDestroyed(ServletContextEvent event) {
                event.getServletContext().removeAttribute("ListenerOne");
            }

            public void contextInitialized(ServletContextEvent event) {
                event.getServletContext().setAttribute("ListenerTwo", "ListenerTwoMessage");
            }
        });
        context.addListeners(listeners);
        assertEquals("ListenerOneMessage", (String) context.getAttribute("ListenerOne"));
        assertEquals("ListenerTwoMessage", (String) context.getAttribute("ListenerTwo"));
    }

    @Test(dependsOnMethods = "addListeners")
    public void removeListeners() {
        context.removeListeners();
    }

}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://www.stripesframework.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Updated: (STS-494) MockServletContext needs ServletContextListener add/remove methods

JIRA jira@stripesframework.org

     [ http://www.stripesframework.org/jira/browse/STS-494?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Fennell updated STS-494:
----------------------------

    Fix Version/s: Release 1.5.1

> MockServletContext needs  ServletContextListener add/remove methods
> -------------------------------------------------------------------
>
>                 Key: STS-494
>                 URL: http://www.stripesframework.org/jira/browse/STS-494
>             Project: Stripes
>          Issue Type: New Feature
>          Components: Context Management
>    Affects Versions: Release 1.5
>            Reporter: David G. Friedman
>            Assignee: Tim Fennell
>             Fix For: Release 1.5.1
>
>
> I have modified my copy of the Trunk to allow for adding and removing ServletContextListeners to be Mock tested.  I have included my code for your consideration.  To  allow for easier testing I pass in new()d class instances. This also avoids possible typing errors by passing in Strings as in a standard web.xml file This also allows for simpler testing (see my example test class below).
> From MockServletContext.java
>  private List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();
>     public void removeListeners() {
>         ServletContextEvent e = new ServletContextEvent(this);
>         if (listeners == null || listeners.size() == 0) {
>            return;
>         }
>         for (ServletContextListener l : listeners) {
>             l.contextDestroyed(e);
>        }
>         listeners.clear();
>  }
>     public void addListener(ServletContextListener listener) {
>         ServletContextEvent e = new ServletContextEvent(this);
>         listener.contextInitialized(e);
>         listeners.add(listener);
>     }
>     public void addListeners(List<ServletContextListener> l) {
>         for (ServletContextListener s : l) {
>             addListener(s);
>         }
>     }
> From my test class:
> public class ListenerT {
>     private MockServletContext context = MockTestFixture.getServletContext();
>     @Test
>     public void addListeners() {
>         List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();
>         listeners.add(new ServletContextListener() {
>             public void contextDestroyed(ServletContextEvent event) {
>                 event.getServletContext().removeAttribute("ListenerOne");
>             }
>             public void contextInitialized(ServletContextEvent event) {
>                 event.getServletContext().setAttribute("ListenerOne", "ListenerOneMessage");
>             }
>         });
>         listeners.add(new ServletContextListener() {
>             public void contextDestroyed(ServletContextEvent event) {
>                 event.getServletContext().removeAttribute("ListenerOne");
>             }
>             public void contextInitialized(ServletContextEvent event) {
>                 event.getServletContext().setAttribute("ListenerTwo", "ListenerTwoMessage");
>             }
>         });
>         context.addListeners(listeners);
>         assertEquals("ListenerOneMessage", (String) context.getAttribute("ListenerOne"));
>         assertEquals("ListenerTwoMessage", (String) context.getAttribute("ListenerTwo"));
>     }
>     @Test(dependsOnMethods = "addListeners")
>     public void removeListeners() {
>         context.removeListeners();
>     }
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://www.stripesframework.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Updated: (STS-494) MockServletContext needs ServletContextListener add/remove methods

JIRA jira@stripesframework.org
In reply to this post by JIRA jira@stripesframework.org

     [ http://www.stripesframework.org/jira/browse/STS-494?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ben Gunter updated STS-494:
---------------------------

    Fix Version/s:     (was: Release 1.5.1)
                   Release 1.6
         Assignee:     (was: Tim Fennell)

> MockServletContext needs  ServletContextListener add/remove methods
> -------------------------------------------------------------------
>
>                 Key: STS-494
>                 URL: http://www.stripesframework.org/jira/browse/STS-494
>             Project: Stripes
>          Issue Type: New Feature
>          Components: Context Management
>    Affects Versions: Release 1.5
>            Reporter: David G. Friedman
>             Fix For: Release 1.6
>
>
> I have modified my copy of the Trunk to allow for adding and removing ServletContextListeners to be Mock tested.  I have included my code for your consideration.  To  allow for easier testing I pass in new()d class instances. This also avoids possible typing errors by passing in Strings as in a standard web.xml file This also allows for simpler testing (see my example test class below).
> From MockServletContext.java
>  private List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();
>     public void removeListeners() {
>         ServletContextEvent e = new ServletContextEvent(this);
>         if (listeners == null || listeners.size() == 0) {
>            return;
>         }
>         for (ServletContextListener l : listeners) {
>             l.contextDestroyed(e);
>        }
>         listeners.clear();
>  }
>     public void addListener(ServletContextListener listener) {
>         ServletContextEvent e = new ServletContextEvent(this);
>         listener.contextInitialized(e);
>         listeners.add(listener);
>     }
>     public void addListeners(List<ServletContextListener> l) {
>         for (ServletContextListener s : l) {
>             addListener(s);
>         }
>     }
> From my test class:
> public class ListenerT {
>     private MockServletContext context = MockTestFixture.getServletContext();
>     @Test
>     public void addListeners() {
>         List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();
>         listeners.add(new ServletContextListener() {
>             public void contextDestroyed(ServletContextEvent event) {
>                 event.getServletContext().removeAttribute("ListenerOne");
>             }
>             public void contextInitialized(ServletContextEvent event) {
>                 event.getServletContext().setAttribute("ListenerOne", "ListenerOneMessage");
>             }
>         });
>         listeners.add(new ServletContextListener() {
>             public void contextDestroyed(ServletContextEvent event) {
>                 event.getServletContext().removeAttribute("ListenerOne");
>             }
>             public void contextInitialized(ServletContextEvent event) {
>                 event.getServletContext().setAttribute("ListenerTwo", "ListenerTwoMessage");
>             }
>         });
>         context.addListeners(listeners);
>         assertEquals("ListenerOneMessage", (String) context.getAttribute("ListenerOne"));
>         assertEquals("ListenerTwoMessage", (String) context.getAttribute("ListenerTwo"));
>     }
>     @Test(dependsOnMethods = "addListeners")
>     public void removeListeners() {
>         context.removeListeners();
>     }
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://www.stripesframework.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Updated: (STS-494) MockServletContext needs ServletContextListener add/remove methods

JIRA jira@stripesframework.org
In reply to this post by JIRA jira@stripesframework.org

     [ http://www.stripesframework.org/jira/browse/STS-494?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Marcus KraƟmann updated STS-494:
--------------------------------

    Attachment: addedListenerSupport.diff

Attached diff / patch file so this maybe makes it into the next release. This patch does not contain the "mass adder" for listeners because it wouldn't fit in the existing class design. On the other hand, it includes a "removeFilters()" method (which I currently implement directly in the test fixture).

I really like improvements regarding unit tests :-)

> MockServletContext needs  ServletContextListener add/remove methods
> -------------------------------------------------------------------
>
>                 Key: STS-494
>                 URL: http://www.stripesframework.org/jira/browse/STS-494
>             Project: Stripes
>          Issue Type: New Feature
>          Components: Context Management
>    Affects Versions: Release 1.5
>            Reporter: David G. Friedman
>             Fix For: Release 1.6
>
>         Attachments: addedListenerSupport.diff
>
>
> I have modified my copy of the Trunk to allow for adding and removing ServletContextListeners to be Mock tested.  I have included my code for your consideration.  To  allow for easier testing I pass in new()d class instances. This also avoids possible typing errors by passing in Strings as in a standard web.xml file This also allows for simpler testing (see my example test class below).
> From MockServletContext.java
>  private List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();
>     public void removeListeners() {
>         ServletContextEvent e = new ServletContextEvent(this);
>         if (listeners == null || listeners.size() == 0) {
>            return;
>         }
>         for (ServletContextListener l : listeners) {
>             l.contextDestroyed(e);
>        }
>         listeners.clear();
>  }
>     public void addListener(ServletContextListener listener) {
>         ServletContextEvent e = new ServletContextEvent(this);
>         listener.contextInitialized(e);
>         listeners.add(listener);
>     }
>     public void addListeners(List<ServletContextListener> l) {
>         for (ServletContextListener s : l) {
>             addListener(s);
>         }
>     }
> From my test class:
> public class ListenerT {
>     private MockServletContext context = MockTestFixture.getServletContext();
>     @Test
>     public void addListeners() {
>         List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();
>         listeners.add(new ServletContextListener() {
>             public void contextDestroyed(ServletContextEvent event) {
>                 event.getServletContext().removeAttribute("ListenerOne");
>             }
>             public void contextInitialized(ServletContextEvent event) {
>                 event.getServletContext().setAttribute("ListenerOne", "ListenerOneMessage");
>             }
>         });
>         listeners.add(new ServletContextListener() {
>             public void contextDestroyed(ServletContextEvent event) {
>                 event.getServletContext().removeAttribute("ListenerOne");
>             }
>             public void contextInitialized(ServletContextEvent event) {
>                 event.getServletContext().setAttribute("ListenerTwo", "ListenerTwoMessage");
>             }
>         });
>         context.addListeners(listeners);
>         assertEquals("ListenerOneMessage", (String) context.getAttribute("ListenerOne"));
>         assertEquals("ListenerTwoMessage", (String) context.getAttribute("ListenerTwo"));
>     }
>     @Test(dependsOnMethods = "addListeners")
>     public void removeListeners() {
>         context.removeListeners();
>     }
> }

--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to
best implement a security strategy that keeps consumers' information secure
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl 
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development
Reply | Threaded
Open this post in threaded view
|

[JIRA] Resolved: (STS-494) MockServletContext needs ServletContextListener add/remove methods

JIRA jira@stripesframework.org
In reply to this post by JIRA jira@stripesframework.org

     [ http://www.stripesframework.org/jira/browse/STS-494?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remi VANKEISBELCK resolved STS-494.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: Release 1.5.8

fixed in r1521. Listeners + close().

> MockServletContext needs  ServletContextListener add/remove methods
> -------------------------------------------------------------------
>
>                 Key: STS-494
>                 URL: http://www.stripesframework.org/jira/browse/STS-494
>             Project: Stripes
>          Issue Type: New Feature
>          Components: Context Management
>    Affects Versions: Release 1.5
>            Reporter: David G. Friedman
>            Assignee: Remi VANKEISBELCK
>             Fix For: Release 1.5.8, Release 1.6
>
>         Attachments: addedListenerSupport.diff
>
>
> I have modified my copy of the Trunk to allow for adding and removing ServletContextListeners to be Mock tested.  I have included my code for your consideration.  To  allow for easier testing I pass in new()d class instances. This also avoids possible typing errors by passing in Strings as in a standard web.xml file This also allows for simpler testing (see my example test class below).
> From MockServletContext.java
>  private List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();
>     public void removeListeners() {
>         ServletContextEvent e = new ServletContextEvent(this);
>         if (listeners == null || listeners.size() == 0) {
>            return;
>         }
>         for (ServletContextListener l : listeners) {
>             l.contextDestroyed(e);
>        }
>         listeners.clear();
>  }
>     public void addListener(ServletContextListener listener) {
>         ServletContextEvent e = new ServletContextEvent(this);
>         listener.contextInitialized(e);
>         listeners.add(listener);
>     }
>     public void addListeners(List<ServletContextListener> l) {
>         for (ServletContextListener s : l) {
>             addListener(s);
>         }
>     }
> From my test class:
> public class ListenerT {
>     private MockServletContext context = MockTestFixture.getServletContext();
>     @Test
>     public void addListeners() {
>         List<ServletContextListener> listeners = new ArrayList<ServletContextListener>();
>         listeners.add(new ServletContextListener() {
>             public void contextDestroyed(ServletContextEvent event) {
>                 event.getServletContext().removeAttribute("ListenerOne");
>             }
>             public void contextInitialized(ServletContextEvent event) {
>                 event.getServletContext().setAttribute("ListenerOne", "ListenerOneMessage");
>             }
>         });
>         listeners.add(new ServletContextListener() {
>             public void contextDestroyed(ServletContextEvent event) {
>                 event.getServletContext().removeAttribute("ListenerOne");
>             }
>             public void contextInitialized(ServletContextEvent event) {
>                 event.getServletContext().setAttribute("ListenerTwo", "ListenerTwoMessage");
>             }
>         });
>         context.addListeners(listeners);
>         assertEquals("ListenerOneMessage", (String) context.getAttribute("ListenerOne"));
>         assertEquals("ListenerTwoMessage", (String) context.getAttribute("ListenerTwo"));
>     }
>     @Test(dependsOnMethods = "addListeners")
>     public void removeListeners() {
>         context.removeListeners();
>     }
> }

--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

------------------------------------------------------------------------------
The Go Parallel Website, sponsored by Intel - in partnership with Geeknet,
is your hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials, tech docs,
whitepapers, evaluation guides, and opinion stories. Check out the most
recent posts - join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Stripes-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-development