In Grails 2.1.x, I would like to create an additional dataSource for an integration test so that I can verify that my service is dynamically pulling data from a user specified dataSource. Currently my tests are pretty simple such as:
@Test
void "get Action Types by data source name returns all action types"() {
new ActionCache(actionType: 'Action Type 1').test.save()
new ActionCache(actionType: 'Action Type 2').test.save()
new ActionCache(actionType: 'Action Type 3').save()
def result = reportService.getActionTypesByDataSource('test')
assert result.size() == 2
}
I can get the test to pass if I configure a new dataSource for the test environment in DataSource.groovy named test
, but then the new dataSource shows up in all of my tests; unit and integration. Ideally I would like to create a new dataSource as part of the setUp for the integration test using something like:
def grailsApplication
@Before
void setUp() {
grailsApplication.config.dataSource_test = {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE"
}
}
But it appears that the dataSources are loaded prior to the integration tests being run and I can't figure out how to add to them.