Trying to add some groovy test cases to a project I'm working on. It's a Spring Boot Java project. I'm at the point where I need a database to do some interactions. We're using the @TestPropertySource to set the db properties for the spring.liquibase.change-log ... which when encountered should run the noted script that builds the schema within the database. For some reason it isn't. Later, in the test, when I go to load the dataset of sample data needed, it throws an exception that it can't insert the data because the table doesn't exist... I'm able to persist the database to file and inspect it... sure enough, there's no tables in it, other than the default ones that get created in a blank db.
I've been banging my head on this for two days now and it's ticking me off. I'm comparing configurations and code and pom files between my project and two others that do work... and as far as I can tell, it's all right.
Here's the base class: (names changed)
java Code:
package g.v.myapp.myclass.junk
import org.springframework.boot.autoconfigure.ImportAutoConfiguration
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.unitils.database.annotations.Transactional
import org.unitils.database.util.TransactionMode
import spock.lang.Specification
@ContextConfiguration(classes = [MyClassTestConfiguration])
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ImportAutoConfiguration([LiquibaseAutoConfiguration])
@TestPropertySource(properties = [
'debug=true',
'spring.liquibase.change-log=classpath:liquibase/schema.xml',
'spring.liquibase.contexts=!partitioned',
'spring.datasource.url=jdbc:h2:file:/Users/me/dev/github/c/myapp/mymodule/src/test/data:sampletest;DB_CLOSE_DELAY=-1;MODE=PostgreSQL;DB_CLOSE_ON_EXIT=FALSE'])
@Transactional(TransactionMode.DISABLED)
class MyClassTestBase extends Specification {
}
And here's the implementing test class:
java Code:
package g.v.myapp.myclass.junk
import org.junit.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.CommandLineRunner
import org.unitils.dbunit.annotation.DataSet
import org.unitils.dbunit.datasetloadstrategy.impl.CleanInsertLoadStrategy
import spock.lang.Unroll
import spock.unitils.UnitilsSupport
@UnitilsSupport
@DataSet(
value = ['dbunit/..../repository/SampleData.xml'],
loadStrategy = CleanInsertLoadStrategy
)
class MyClassTestCaseTest extends MyClassTestBase {
When it loads the dataset (SampleData.xml) that's when I get the errors... For what ever reason, it looks like it isn't using the properties set in the base class to create the schema structure that I'm expecting.
I feel like I've missed something stupid simple & obvious, but I can't figure it out.