I'd like to use for my Quarkus tests the H2 Test Resource:
@QuarkusTestResource(H2DatabaseTestResource.class)
However I need to have some tables available in the Database. Although I have placed a resources/import.sql with the DDL in it, the test fails because it attempts to use tables from the configuration before executing the import.sql:
quarkus.security.jdbc.principal-query.sql=SELECT u.password, u.role FROM test_user u WHERE u.username=?
As a result:
Caused by: org.h2.jdbc.JdbcSQLException: Table "TEST_USER" not found; SQL statement:
SELECT u.password, u.role FROM test_user u WHERE u.username=? [42102-197]
Any way to execute the SQL before Quarkus reads the configuration file?
You need to include into the JDBC Connection String the INIT Parameter with in it a reference to the SQL Script to execute. Example:
quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:elytron_jdbc_test;DB_CLOSE_DELAY=-1;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'classpath:import.sql'
See an example application which secures Quarkus with H2 Database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With