Java Reference
In-Depth Information
assert db.rows('select * from stadium').size() == stadiums.size()
db.eachRow('select latitude, longitude from stadium') { row ->
assert row.latitude > 25 && row.latitude < 48
assert row.longitude > -123 && row.longitude < -71
}
The first assert statement checks that the total number of rows in the table matches the
number of stadiums in the collection. The next statement invokes the eachRow method on
the connection, selecting just the latitude and longitude, and assigning the dummy variable
row to each of the rows in the result set. The two contained assert statements verify that
the latitudes are between 25 and 48 and that the longitudes are between -123 and -71.
The Sql class
The groovy.sql.Sql class removes almost all the ceremony surrounding raw JDBC
and adds convenience methods as well.
The complete script is shown in the next listing.
Listing 2.4. populate_stadium_data.groovy
Search WWH ::




Custom Search