Environment
SpringBoot 2 with H2 as test dependency.
Production works
Jar is deployed to cloud. A DB2 service is configured with driver and connection details, and automatically bound to the java application. There's no configuration in the jar itself. There is the application.properties file but it's empty. This part works fine and I'm hoping that a solution exists which will not require me to create property files and profiles.
Local Unit Test crashes on 'schema xxx not found'
@Entity(table="Employee", schema="acme")
class Employee {
...
}
@RunWith(SpringRunner.class)
@DataJpaTest
public class EmployeeTest {
...
}
- No data source configuration exists.
- SpringBoot sees H2 dependency and selects Hibernate by default.
- Hibernate sees the Entity definition and attempts to drop the table first.
- The drop uses the schema name
drop table acme.employee if exists
. No schema has been created so process fails withJdbcSQLSyntaxErrorException: Schema "acme" not found
. - I tried
@TestPropertySource(properties ="jdbc:h2:testb;INIT=CREATE SCHEMA IF NOT EXISTS acme;")
with no luck.
I've found issues like this on the web and potential solutions. But they go very far into Hibernate and/or Spring configuration files. I would really want to avoid this. It's only local unit test that fails so I'm hoping to find a solution that is contained within the test.