Wednesday, December 17, 2008

Have a Fit


Tuesday, December 16, 2008

Not too bad



One semi-nasty pucker in one of my heel locks that I didn't notice til I was finished, but otherwise not too bad.


Monday, December 15, 2008

Yes, chewing!


Durian

Hung eats durian. I love him anyway.

Saturday, December 06, 2008

temporary patch


Friday, December 05, 2008

OSIV-like Behaviour for Unit Tests

It is fairly common when writing unit tests to use mock objects in place of DAOs, and the whole issue of lazy loading is avoided, since the mock objects will simply be created to satisfy whatever conditions are required for testing to work. In some cases, however, such as with functional or acceptance testing, it is sometimes desirable to hit an actual test database. This seems simple enough until you realize that Spring's Open Session in View (or Open Entity Manager in View) has been handling sessions for you so that traversing lazy relationships work. Without it, you get a session long enough to execute a dao.find() and then the first time you attempt to traverse a lazy relationship, you get an exception.

Fortunately, with jUnit, it is fairly easy to create a setUp and tearDown to behave similarly to the start and end of a servlet request, and Spring provides the means to associate a session with the current thread, making things work basically the same way as they do with OSIV. Just do something like this:

        @Before
public void setUp()
{
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
}

@After
public void tearDown()
{
SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.releaseSession(sessionHolder.getSession(), sessionFactory);
}

Labels: ,


Monday, December 01, 2008

office kitty


This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]