Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force execution of import.sql before Quarkus Tests?

Tags:

quarkus


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?

like image 670
Carla Avatar asked Nov 06 '25 16:11

Carla


1 Answers

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.

like image 91
Francesco Marchioni Avatar answered Nov 12 '25 17:11

Francesco Marchioni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!