I have a parameters module in my project which other modules are dependent on. I'd like to write instegration tests for this module in separate manner. This module is a spring based one and has some db related logic, though db migration scripts are not available in this module since it is something that is out of its area of resposibility. By the way in-memory H2 instance is used for testing purposes.
What I'm trying to achieve is to make spring/hibernate create DB tables based on single @Entity class present in this module, it is called ParameterEntity.
It is defined like this:
@Entity
@Table(name = "SYSTEM_PARAMETERS")
public class ParameterEntity {
@Id
@Column(name = "id")
private String id;
@Column(name = "value")
private String value;
// accessors go here...
}
In my application-test.yml file I provide the following props:
spring:
jpa:
hibernate:
ddl-auto: create
database: h2
show-sql: true
And define integration test class like this:
@ExtendWith(SpringExtension.class)
@EnableConfigurationProperties
@EntityScan("path.to.package.where.parameter.entity.resides")
@ConstextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)
@ActiveProfiles("test")
@TestInstance(Lifecycle.PER_CLASS)
public class ParametersIntegrationTest {
@Autowired
private ParameterWarden warden;
@BeforeEach
public void setUp() {
warden.initialize();
}
@Configuration
@ComponentScan("base.module.package")
static class TestConfiguration {
// here comes some test beans which will be used in testing purposes only
}
}
In @BeforeEach method ParameterWarden class calls repository class which in turn make some calls to database to retrieve parameter entities from database and these calls fail because SYSTEM_PARAMETERS is missing.
Could anyone, please, let me know what am I missing here and how can I make spring or hibernate create table based on the entity present in my project. Even the place where I can debug this would be nice to know.
It seems like I need another magical thing that will trigger this functionality but I was unable to figure out what exactly I need.
Any help is really appreciated, thank you very much for your time!
p.s. I can not use @SpringBootTest annotation since this module uses only some spring features and is not a spring boot application itself. It is used as a dependecy in another spring boot applications.