tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quintin Beukes <quin...@skywalk.co.za>
Subject Re: Hackety hack: @Test, @LocalClient and @Stateless for simple JPA testing
Date Sat, 03 Oct 2009 16:07:16 GMT
Yes,it is managed by the container and the context. The initial
context will close with the VM. Afaik it will have the same behaviour
after the test closes as the EJB would. Though because your test isn't
created and it's instance managed by the container, the transactions
won't happen "before" and "after" the test automatically. That's
something that's going to be in the JUnit-runner.

Anyway, why do you need this behavior for tests?

>From you e-mail I figure your focus is on the automatic destruction of
the db. This should do it for you. I don't see how CMT could be the
reason for that happening. EJB closing down maybe, but not a single
CMT. And OpenEJB closes down even if you don't have EJBs, once the VM
closes down, and this behavior is the same whether or not you have
EJBs, as long as you start it in the first place, which happens with
the InitialContext.

Best thing is to try it and see if it works, then if it doesn't - come
back and we'll see if there is some way to do it. OpenEJB is very
flexible, which is one of the things that makes it brilliant.

Quintin Beukes



On Sat, Oct 3, 2009 at 4:55 PM, Laird Nelson <ljnelson@gmail.com> wrote:
> On Fri, Oct 2, 2009 at 4:42 PM, Quintin Beukes <quintin@skywalk.co.za>wrote:
>
>> If you really only want to test the JPA entities, and don't mind the
>> transactions, why not remove the @Stateless and @EJB completely, and
>> just make your test @LocalClient and inject an entity manager?
>>
>
> That may be just the ticket.  I wanted to avoid all the boilerplate of
> creating and committing transactions.  If I inject an EntityManager into my
> LocalClient, is it managed by the container?  Or does it behave in a more
> Java SE manner?  Does it start and automatically commit the transaction?
>
> Mainly I'm looking to do whatever is simplest to get the
> auto-context-closing behavior of the local InitialContext, because that
> wipes out my in-memory H2 database automatically between tests.  I wanted to
> combine that behavior with automatic transaction management to eliminate
> EntityManager boilerplate operations.  Whatever is the simplest way to do
> this involving the least code--I'm all ears.
>
> Best,
> Laird
>

Mime
View raw message