0 Replies Latest reply on Sep 28, 2012 3:58 PM by Peter Sterba

    @ApplyScriptBefore and MySQL

    Peter Sterba Newbie

      I am working on running unit tests with JBoss 7.1.1 on a MySQL DB server 5.5.  I am using .yml files for the datasets for the unit tests.  The .yml files I use creates a row in the publishers table, and there is a trigger on the publishers table to create a row in the publisher_audit_trail table, which has a foreign key constraint back to the publishers table. 


      We are using @Cleanup(phase = TestExecutionPhase.AFTER, strategy = CleanupStrategy.STRICT) as our cleanup configs, but because the publisher_audit_trail table is not in the dataset, it is not being deleted from before the publisher is deleted (if at all; I am not 100% sure Arquillian even realizes a row on the audit_trail is created).  Because of the foreign key constraint, the unit test is failing because the DB cannot delete from the audit_trail table. 


      I have tried adding @ApplyScriptBefore({"turnOffReferentialIntegrity.sql"}) to the Unit Test class to run the following script:

      SET @@foreign_key_checks = 0;        --I have also tried 'SET foreign_key_checks = 0;'

      I have also tried adding <property name="scriptsToExecuteBeforeTest">turnOffReferentialIntegrity.sql</property> to the arquillian.xml file under the extension tag.

      Both config changes should turn off the foreign key constraints so I can cleanly delete everything from the database.  At first it did not appear that the .sql script was being run as the unit test was still failing on cleaning up the database, but then I added a fake sql statement and the deploy process failed for the unit test on the fake statement, so I know Arquillian is finding and running the file. 


      https://docs.jboss.org/author/display/ARQ/Persistence states that you can add either of these config changes specifically for the purpose of turning off referential integrity constraints (such as I am trying to do) but it appears that the script being run is run in it's own session, and the referential integrity constraints are still active when the Cleanup phase comes about.  It appears that MySQL only allows the constraints to be turned off for the session (not permanently) but it looks like Arquillian is running the @ApplyScriptBefore annotation in it's own session. 


      Are there any ideas as to what to change in the configs so that the script is run and valid when the database is cleaned?