While we could have set up a source in jetty-env.xml and placed that file in WEB-INF, from a number of postings on the 'net (see, for example, this thread), it seems like the integration tests don't actually run within the web application context Jetty provides. So, instead, we decided to register the data source programmatically as we needed it in our integration tests.
Fortunately, Grails provides access easily enough to the testing data source (configured in grails-app/conf/DataSource.groovy) merely by adding a "def dataSource" in our integration test class defintion:
class MyClassTests extends GroovyTestCase {
def dataSource // auto-wired by Grails
. . . setup, test methods, etc . . .
}
With the data source defined, we can now access it as we need it.
The next step is to create an InitialContext and bind the data source:
def ctx = new javax.naming.InitialContext()
ctx.bind("java:/testing-db", dataSource)
Now, with the data source bound in JNDI, we can retrieve it and use it where we need it:
def ctx = new javax.naming.InitialContext()
def conn = ctx.lookup("java:/testing-db")
def sql = new groovy.sql.Sql(conn)
// create a table to hold some test data
sql.execute("create table test_data(id identity, some_column varchar, col_ts timestamp default current_timestamp)")
Of course, if we didn't want to worry about accidentally messing up the Grails testing data source, we could always have set up our own HSQLDB data source and bound it:
import org.apache.commons.dbcp.BasicDataSource
def ds = new BasicDataSource()
ds.setUrl("jdbc:hsqldb:mem:myTestDb")
ds.setUsername("sa")
ds.setPassword("")
ds.setDriverClassName("org.hsqldb.jdbcDriver")
def ctx = new InitialContext()
ctx.bind("java:/testing-db", ds)
However, in our case, using the standard Grails data source worked just fine. It's probably worth our while to try to set up a data source through jetty-env.xml for using our components requiring JNDI in the "run-app" development environment, but our integration tests are running, and that's good enough for now.