Created
February 18, 2015 13:58
-
-
Save musketyr/164bf82d4a07b3355a08 to your computer and use it in GitHub Desktop.
how to be sure the test runs only against data from fixtures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class AbstractIntegrationSpec extends IntegrationSpec { | |
@Shared | |
def fixtureLoader, fixtures, initCatalogueService, sessionFactory | |
def loadFixtures(){ | |
String scriptLocation = "${System.getProperty('java.io.tmpdir')}mc/testdata.sql" | |
def sql = new Sql(sessionFactory.currentSession.connection()) | |
if (new File(scriptLocation).exists()) { | |
long start = System.currentTimeMillis() | |
sql.execute("RUNSCRIPT FROM ${scriptLocation}") | |
sessionFactory.currentSession.clear() | |
println "database restored from in ${scriptLocation} ${System.currentTimeMillis() - start} ms" | |
return | |
} | |
long start = System.currentTimeMillis() | |
String clearScriptLocation = "${System.getProperty('java.io.tmpdir')}mc/drop.sql" | |
sql.execute("SCRIPT NODATA DROP TO ${clearScriptLocation}") | |
println "Clear script created in $clearScriptLocation" | |
sql.execute("RUNSCRIPT FROM ${clearScriptLocation}") | |
println "Database cleared from $clearScriptLocation" | |
initCatalogueService.initDefaultRelationshipTypes() | |
println "loading fixtures" | |
fixtures = fixtureLoader.load("assets/*", "batches/*", "dataTypes/*", "enumeratedTypes/*", "measurementUnits/*", "models/*", "relationshipTypes/*", "classifications/*").load("actions/*", "valueDomains/*", "users/*").load("dataElements/*").load("extensions/*", "mappings/*").load("csvTransformations/*") | |
sessionFactory.currentSession.flush() | |
sql.execute("SCRIPT DROP TO ${scriptLocation}") | |
println "Data script created in $scriptLocation" | |
println "database created in ${System.currentTimeMillis() - start} ms" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment