I want to use a in memorey H2
database together with Spring Boot (v. "3.2.0"
) for testing the reult of the JPA Repository Queries.
- I want to use a common migration script which is located under
src/main/resources/db/migration/setup_schema.sql
in order set up the schema of myH2
database - The data to populate the so created schema in the
H2
database is located undersrc/test/resources/db/migration/insert_data.sql
This is the content of the application properties under src/main
spring.jpa.hibernate.naming.physical-strategy=org.....CustomPhysicalNamingStrategy
spring.jackson.property-naming-strategy=LOWER_CAMEL_CASE
spring.datasource.url=jdbc:postgresql://localhost:5434/px4
spring.datasource.username=postgres
spring.datasource.password=...
logging.level.org.springframework.security=DEBUG
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.jpa.hibernate.ddl-auto=validate
spring.flyway.baseline-on-migrate=true
spring.flyway.enabled=true
spring.flyway.mixed=true
spring.flyway.default-schema=public
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
Now, I wonder how I configure a test to
- Create a H2 in memory database
- Use the migration script form here
src/main/resources/db/migration/setup_schema.sql
in order set up the schema - Then use this
src/test/resources/db/migration/insert_data.sql
to populate the database with the data - Make the whole
H2
database available in my tests to test the queries written in the JPA Repositories.