rmpestano / dbunit-rules

https://github.com/database-rider/database-rider
15 stars 5 forks source link

Tomee ApplicationComposer #30

Closed hwaastad closed 8 years ago

hwaastad commented 8 years ago

Hi, not really an issue, but have you tried to integrate the cdi module with TomEE ApplicationComposer?

btw, great job :-)

rmpestano commented 8 years ago

Hi @hwaastad,

I didn't tried but looks like a nice idea!

Do you know if ApplicationComposer runner can treat the test class as a CDI bean? this is needed so dbunit interceptor can intercept test methods in order to seed database.

Another option is to use Dbunit Rule, in this case the test class doesn't need to be a cdi bean.

I'll have a look over the weekend, thank you for the feedback!

hwaastad commented 8 years ago

Hi, I think both appcomposer and dbunit rules can be chained.

I've done some initial testing and hav an issue with getting the PU correctly.

/hw

rmpestano commented 8 years ago

Hi, great!

About the pu issue you may be having trouble to get the jdbc connection, right?

this project comes with a utility to look up PU, ex:

   @Rule
   public EntityManagerProvider emProvider = EntityManagerProvider.instance("rules-it");

with this emProvider you can retrieve the jdbc connection to use DBUnit rule BUT it only works for resource_local units and I think app copmposer uses managed ones

If that's the case then you can get jdbc connection from entity manager, look here for an example.

rmpestano commented 8 years ago

Hi @hwaastad , I've added an example of dbunit and application composer rules integration here: https://github.com/rmpestano/tomee/blob/master/examples/application-composer-dbunit/src/test/java/org/superbiz/composed/MoviesTest.java#L71

Let me know If it solves your case.

hwaastad commented 8 years ago

Hi, great work! I've been following the discussion with Romain and I'm pleased that you got it working.

a couple of comments:

  1. It does'nt seem to bee needed to initialize the em in the initialization (maybe using resource_local). I've been using jta and its all ok.
  2. I see a: WARNING: Potential problem found: The configured data type factory 'class org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems with the current database 'HSQL Database Engine'

Not sure if I need to care about this one, but just wanted to check with you :-)

br hw

rmpestano commented 8 years ago

Hi,

About 1 there is no need to use RESOURCE_LOCAL entity manager, dbunit rule just needs a JDBC connection. The utility component which comes with this rule, EntityManagerProvider, is the one which only works with RESOUCE_LOCAL em.

About 2 I've created an issue (#34).

Thank you very much for your feedback.