Introduce embedded mongo with full fixture.

This commit is contained in:
Marco Vermeulen
2014-04-09 08:21:59 +01:00
parent 9b59ca045a
commit 32d61738ba
6 changed files with 81 additions and 3 deletions

View File

@@ -17,7 +17,7 @@ apply plugin: 'eclipse'
apply plugin: 'mongo'
apply plugin: 'spawn'
defaultTasks 'clean', 'prepareTestScripts', 'prepareScripts', 'prepareServer', 'prepareTemplates', 'assembleArchive', 'test'
defaultTasks 'clean', 'prepareTestScripts', 'prepareScripts', 'prepareServer', 'prepareTemplates', 'assembleArchive', 'startManagedMongoDb', 'startServer', 'test', 'stopServer'
def userHome = System.getProperty('user.home')
ext.installBinDir = "${userHome}/.gvm/bin"
@@ -38,6 +38,7 @@ dependencies {
testCompile group: 'info.cukes', name: 'cucumber-groovy', version: '1.1.5'
testCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.1.5'
testCompile group: 'org.spockframework', name: 'spock-core', version: '0.7-groovy-2.0'
testCompile "org.mongodb:mongo-java-driver:2.12.0"
}
test.testLogging.exceptionFormat = 'full'

View File

@@ -0,0 +1,30 @@
package gvm
import com.mongodb.DB
import com.mongodb.Mongo
import com.mongodb.MongoClient
import com.mongodb.WriteConcern
import com.mongodb.util.JSON
class MongoHelper {
static final TEST_SOURCE_ROUTE = "src/test/resources"
static prepareDB(){
def mongo = new MongoClient()
mongo.writeConcern = WriteConcern.NORMAL
mongo.getDB("gvm")
}
static loadDbCollectionFromFile(DB db, String collection, String fileName){
def fixtureFile = "$TEST_SOURCE_ROUTE/$fileName" as File
def dbObject = JSON.parse(fixtureFile.text)
def dbCollection = db.getCollection(collection)
dbCollection.insert(dbObject)
}
static dropCollectionFromDb(DB db, String collection){
def dbCollection = db.getCollection(collection)
dbCollection.drop()
}
}

View File

@@ -0,0 +1 @@
{ "_id" : "528887f05e75a57eee081491", "alive" : "OK" }

View File

@@ -0,0 +1 @@
{ "_id" : 1, "text" : "This is a LIVE Broadcast!" }

View File

@@ -0,0 +1,31 @@
[{
"_id" : "530d9e23f0085665c6ad009c",
"candidate" : "groovy",
"default" : "2.0.5",
"versions" : [
{
"version" : "2.0.5",
"url" : "http://localhost/groovy-2.0.5.zip"
}
]
},
{
"_id" : "530d9e23f0085665c6ad009d",
"candidate" : "grails",
"default" : "2.1.0",
"versions" : [
{
"version" : "1.3.6",
"url" : "http://localhost/grails-1.3.6.zip"
},
{
"version" : "1.3.9",
"url" : "http://localhost/grails-1.3.9.zip"
},
{
"version" : "2.1.0",
"url" : "http://localhost/grails-2.1.0.zip"
}
]
}]

View File

@@ -2,6 +2,8 @@ package gvm
import static cucumber.api.groovy.Hooks.After
import static cucumber.api.groovy.Hooks.Before
import static gvm.MongoHelper.loadDbCollectionFromFile
import static gvm.MongoHelper.prepareDB
SERVICE_DOWN_URL = "http://localhost:0"
SERVICE_UP_URL = "http://localhost:8080"
@@ -34,8 +36,20 @@ initScript = new File(binDir, "gvm-init.sh")
bash = null
if(!binding.hasVariable("db")) {
db = setupDb()
}
private setupDb(){
db = prepareDB()
loadDbCollectionFromFile(db, "candidates", "gvm_candidates.js")
loadDbCollectionFromFile(db, "broadcast", "gvm_broadcast.js")
loadDbCollectionFromFile(db, "application", "gvm_application.js")
db
}
Before(){
cleanUp()
cleanUp()
}
After(){ scenario ->
@@ -44,7 +58,7 @@ After(){ scenario ->
scenario.write("\nOutput: \n${output}")
}
bash?.stop()
cleanUp()
//cleanUp()
}
private cleanUp(){