They are not coupled with the web tier. They only require _something else_
to close the session at the appropriate time. In a web application, it
happens to be a servlet filter. In test cases, it happens to be the
tearDown() method. There is no dependency on the web tier when running the
test cases. If you have other scenarios, you just need to find an
appropriate place to close the session (maybe a controller of some sort).

Joe

----- Original Message ----- 
From: "Matthew E.Porter" <[EMAIL PROTECTED]>
To: "Joseph Fifield" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, August 06, 2003 9:59 AM
Subject: Re: [Hibernate] Unit Testing With ThreadLocal Sessions


> My only concern with this is that the business logic component is now
> coupled with the web tier.  For this project (which is basically a
> framework), we want to be able to use the components internal and
> external to the servlet container.  However, I do appreciate the
> feedback!  It helps confirm my thinking regarding potential solutions.
>
>
> Cheers,
>    matthew
>
> On Wednesday, August 6, 2003, at 07:29 AM, Joseph Fifield wrote:
>
> > I don't close the session at all in any of my business logic methods.
> > In
> > deployment, a servlet filter _always_ closes the session at the end of
> > the
> > request. For unit testing, I have a base test case class that does the
> > same
> > thing in the tearDown() method. That way, each test case can execute
> > in the
> > same manner as the app running in deployment (i.e. each test case is
> > like a
> > separate "request"). The result is each test case executes using the
> > same
> > session, and they don't need to worry about closing it at the end.
> >
> > Hope this helps...
> >
> > Joe
> >
> > ----- Original Message -----
> > From: "Matthew E.Porter" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, August 05, 2003 11:12 PM
> > Subject: [Hibernate] Unit Testing With ThreadLocal Sessions
> >
> >
> >> Greetings.  I am interested in hearing how people unit test method
> >> that
> >> call session.save(), update(), and delete() when the session is
> >> provided via the ThreadLocal pattern.  For me, the primary question is
> >> whether or not the method containing the session method calls actually
> >> closes the database connection (session.close()) or is it called after
> >> returning from the tested method.  From a pure unit testing
> >> stand-point, it would seem that it would be desired to be called
> >> inside
> >> the tested method.
> >>
> >> For a project I am working on, we devised a solution (aka hack) to
> >> solve this.  A new Session interface implementation was created that
> >> wraps an internal Session object as normally provided.  Yet, we added
> >> 2
> >> methods: suspendClose() and unsuspendClose().  When closes are
> >> suspend,
> >> the connection is NOT closed despite being called.  Specifically, it
> >> does not call session.close() on the internal Session object.
> >>
> >> When a Session is retrieved, the closes are automatically suspended.
> >> The servlet filter unsuspends the close and closes the session if
> >> necessary at the end of the request.
> >>
> >> Is this a hack?  Yes.  Does it work?  Yes.  Do we get the benefits of
> >> a
> >> ThreadLocal session?  Yes.  Can it be confusing to newbies who expect
> >> close to actual close the session?  Yes, but it only has this behavior
> >> during deployment.
> >>
> >> Any thoughts and comments are welcome.
> >>
> >>
> >> Cheers,
> >>    matthew
> >>
> >>
> >>
> >> -------------------------------------------------------
> >> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> >> Data Reports, E-commerce, Portals, and Forums are available now.
> >> Download today and enter to win an XBOX or Visual Studio .NET.
> >>
> > http://aspnet.click-url.com/go/psa00100003ave/
> > direct;at.aspnet_072303_01/01
> >> _______________________________________________
> >> hibernate-devel mailing list
> >> [EMAIL PROTECTED]
> >> https://lists.sourceforge.net/lists/listinfo/hibernate-devel
> >>
> >>
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> > Data Reports, E-commerce, Portals, and Forums are available now.
> > Download today and enter to win an XBOX or Visual Studio .NET.
> > http://aspnet.click-url.com/go/psa00100003ave/
> > direct;at.aspnet_072303_01/01
> > _______________________________________________
> > hibernate-devel mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/hibernate-devel
>
>
>




-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to