I had issues with @DataJpaTest
, because tables fail to be created, due to missing schema [1]. So I thought, I could cheat spring by creating schema in connection string as in:
application.properties
spring.datasource.url=jdbc:h2:mem:SCH;MODE=Oracle;DB_CLOSE_DELAY=-1;INIT=create schema if not exists SCH
spring.datasource.username=test
spring.datasource.password=test
however mysteriously, that did not help. Why?
quick peek at excerpt from test log:
2019-02-13 17:48:12.735 INFO [CCH,,,] 28586 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Starting embedded database: url='jdbc:h2:mem:11247702-6bc4-44b9-be65-9639ebb8d695;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
well it's because @DataJpaTest ignores datasource configured in application.properties and rather uses autoconfigured h2 database
I found that I can use @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
but that does not work either and fails with Unknown host specified
. What host???
So any ideas how to confince @DataJpaTest to use configured data source?
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
actually turns off autoconfigured embedded h2 database and uses the one declared in project configuration. Sorry for my mistake.