On Sep 7, 2010, at 12:10 AM, Bengt Rodehav wrote: > Lots of mails from me today - just trying to get on top of things.... > > I'm investigating the best way to deploy a JPA based application in OSGi. > I've successfully used Karaf and iPojo in combination with Camel before but > JPA seems a bit more complicated. > > Using Aries components (jpa, transaction and blueprint) seems to provide the > functionality I need. However, one problem for me is how to being able to > unit test my services without having to startup a Karaf instance. In the past > I've been using Spring/Hibernate for this purpose. Spring is very flexible in > the sense that I can configure a test environment for my unit test and still > being able to test services that uses transactions. > > In more detail, my problem is as follows: > > I have DAO objects containing persistence logic using JPA. These are used by > my service objects that contains business logic and also specifies > transaction requirements. I can deploy those objects in Karaf using Aries. > However, I don't know how to unit test those services since they need the > presence of Aries. I know that this might be defined as integration tests > (and not unit tests) for that reason but I would still like a convenient way > to execute these tests as part of my maven build and preferrably without > having to deploy Karaf. Is that possible? > > If not, what is the recommended way (best practice) for these kind of tests?
Use ops4j pax-runner. There are a bunch of integration tests in aries that use this. > > BTW it is not easy to unit test the DAO objects either since I need to get > hold of an entity manager in completely different ways depending on if I'm in > an OSGi environment or not. I could take some advice on this subject as > well... If you code your DAO objects using constructor dependency injection, one of the arguments being the EMF, can't you inject it in blueprint/osgi and simply supply it as a constructor argument in unit tests? If you do some kind of service lookup in your DAO then you will tie it to whatever lookup technology you are using (service registry for osgi, jndi for java ee,....) hope this is relevant to what you are asking about... david jencks > > Best regards, > > /Bengt >
