In Grails 2.1.x, I would like to create an additional dataSource for the integration test so that I can verify that my service is dynamically retrieving data from a user-specified data source. Currently my tests are pretty simple, like this:
@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 pass the test if I configure a new data source for the test environment in DataSource.groovy called test , but then a new data source appears in all my tests. unit and integration. Ideally, I would like to create a new data source as part of setUp for an 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 seems that dataSources are loading before running the integration tests, and I cannot figure out how to add them.
source share