1 Reply Latest reply: Feb 28, 2012 6:29 AM by Michael Brill RSS

Arquillian Persistence Extension - seeding / cleaning db and annotation naming

Bartosz Majsak Master

Hi guys,

 

I'm struggling a bit with naming for new annotations in APE (or maybe speculating about the features too much) . Currently we have following possibilities:

 

  • @UsingDataSet and @ShouldMatchDataSet to use on class or test level for seeding and verifying db content using data sets (JSON, YAML, XLS or XML)
  • @UsingScript which is triggered before seeding db using data sets, so can be used to prepare database (e.g. turning off integrity checks, constraints)

 

Based on the roadmap discussion and feedback from the early adopters there is a need for additional features, namely:

 

  • define a phase when cleanup is executed (by default it's based on DBUnit DELETE_ALL operation triggered after the test as of Alpha3 - this will be changed in Alpha4 to be triggered before the test by default)

  • ability to clean up database using custom script (which will result in not using aforementioned dbunit approach)

 

So here are the changes which I'm considering to introduce in APE Alpha4:

 

  • Introducing @Cleanup annotation with BEFORE | AFTER or NONE values so user can decide if he wants dbunit to be executed and when
  • Additionally he can define one of the strategies
    • STRICT (implemented currently) - Cleans whole database content (using DELETE_ALL). Might require turning off database constraints (e.g. referential integrity).
    • USED_ROWS_ONLY - Deletes only those entries which were defined in data sets.
    • USED_TABLES_ONLY - Deletes only those tables which were used in data sets.
  • In some cases however it might not be sufficient (i.e. there is no way to turn off referential integrity checks). For this purpose I would like to introduce @CleanupUsingScript annotation where one can define:
    • scripts to be used
    • phase when it should happen (BEFORE or AFTER)

 

However there might be also a need to run some custom scripts after test execution (for instance to turn on integrity checks back). Therefore I was thinking to rework @UsingScript annotation and introduce following two:

  • @ApplyScriptBefore
  • @ApplyScriptAfter

 

And here are my questions - do you think all those features are needed? What about the naming?

 

I really like phrasing Test (is) UsingDataSet and result ShouldMatchDataSet (stolen from Aslak ) and I strongly believe that should be recommended convention. However there are also exceptional cases where I want to apply custom scripts before and after test. Hence the names I came up with.

 

I'm aware that @CleanupUsingScript is somehow redundant because you can achieve the same this using @ApplyScript*, but on the other hand former says clearly your intent, where latter is general purpose feature.

 

Looking forward to your feedback!

 

Cheers,

Bartosz

  • 1. Re: Arquillian Persistence Extension - seeding / cleaning db and annotation naming
    Michael Brill Newbie

    Hi,

     

    First of all

    do you think all those features are needed?

    Yes, I could actually think of a use case for each feature in my current project. I'm fine with the naming, but I'm not in the jboss naming conventions :-).

     

    I believe the STRICT cleanup strategy should use TRUNCATE rather than DELETE_ALL, as I pointed out in my Example. The reason is that I believe that foreign key constraints are the most common case. Your framework should handle them without additional configuration.

     

    Today an additional use case for seeding came up which is worth to think about. I'm working on a @Singleton@Startup annotated class doing some JMS stuff in the background. On Startup, this class takes its configuration from the database. Since Datasets are only seeded before a test execution I would recommend an additional seeding phase preDeploy. However, I am aware that such a seeding phase conflicts with the current cleanup solution. But it would be an awesome feature^^.

     

    Cheers