Update cucumber to work with new stubs.

This commit is contained in:
Marco Vermeulen
2012-09-27 20:51:59 +01:00
parent 6b0747e510
commit 60ddf4c15f
11 changed files with 140 additions and 83 deletions

View File

@@ -8,8 +8,8 @@ Feature: List Candidates
Then I see "Available Grails Versions"
Scenario: List all available Versions without a Candidate installed
Given I do not have a "groovy" candidate installed
When I enter "gvm list groovy"
Then I see "Stop! groovy has never been installed."
Given I do not have a "grails" candidate installed
When I enter "gvm list grails"
Then I see "Stop! grails has never been installed."

View File

@@ -16,7 +16,7 @@ Feature: Uninstall
Scenario: Attempt uninstalling a Candidate Version that is not installed
Given the candidate "grails" version "2.1.0" is already installed
When I enter "gvm uninstall grails 2.1.0"
Then I see "grails 2.1.0 is not installed."
And the candidate "grails" version "2.1.0" is not installed
When I enter "gvm uninstall grails 1.3.9"
Then I see "grails 1.3.9 is not installed."
And the candidate "grails" version "1.3.9" is not installed

View File

@@ -0,0 +1,8 @@
Feature: Upgrade
Scenario: Upgrade an outdated installation
Given an initialised system
When I enter "gvm selfupdate"
Then I see "Successfully upgraded GVM."
Then the gvm scripts are up to date

View File

@@ -1,81 +1,118 @@
package gvm
import groovy.text.SimpleTemplateEngine
import org.vertx.groovy.core.http.RouteMatcher
import org.vertx.groovy.core.Vertx
class VertxUtils {
final static grails = ['1.3.9','2.1.0']
final static candidates = [grails:grails]
final static defaults = [grails:'2.1.0']
static final gvmVersion = '0.1'
static final serverVersion = '0.1'
static final vertxVersion = '1.2.3.final'
static templateEngine = new SimpleTemplateEngine()
static server
public static startServer(){
println "Starting stub webservice..."
if(!server){
println "Starting stub webservice..."
server = createServer("localhost", 8080)
}
server
}
private static createServer(String host, int port){
def rm = new RouteMatcher()
rm.get("/") { req ->
req.response.sendFile('srv/scripts/install.sh')
}
rm.get("/res/init") { req ->
req.response.sendFile('srv/scripts/gvm-init.sh')
}
rm.get("/res/gvm") { req ->
req.response.sendFile('srv/scripts/gvm')
}
rm.get("/candidates") { req ->
req.response.end "grails"
}
rm.get("/candidates/:candidate") { req ->
def candidate = req.params['candidate']
def versions = buildCsv(candidates[candidate])?.toString()
req.response.end (versions ?: "invalid")
}
rm.get("/candidates/:candidate/default") { req ->
def candidate = req.params['candidate']
req.response.end "2.1.0"
}
rm.get("/candidates/:candidate/list") { req ->
def candidate = req.params['candidate']
def current = req.params['current']
def installed = req.params['installed']
def gtplFile = new File('srv/templates/list.gtpl')
def binding = [candidate:candidate, available:grails, current:current, installed:installed]
def template = templateEngine.createTemplate(gtplFile).make(binding)
req.response.end template.toString()
}
rm.get("/candidates/:candidate/:version") { req ->
def candidate = req.params['candidate']
def version = req.params['version']
def found = (candidates[candidate].find { it == version}) ? version : 'invalid'
req.response.end found
}
rm.get("/download/:candidate/:version") { req ->
def candidate = req.params['candidate']
def version = req.params['version']
req.response.putHeader "Content-disposition", "attachment; filename=${candidate}-${version}.zip"
req.response.sendFile "src/test/resources/${candidate}-${version}.zip"
}
rm.get("/app/version") { req ->
req.response.end '0.1'
}
rm.get("/app/alive/:version") { req ->
def version = req.params['version']
def gtplFile, binding
if(gvmVersion == version){
gtplFile = new File('srv/templates/broadcast.gtpl')
binding = [server:serverVersion, vertx:vertxVersion]
} else {
gtplFile = new File('srv/templates/upgrade.gtpl')
binding = [version:gvmVersion]
}
def template = templateEngine.createTemplate(gtplFile).make(binding)
req.response.end template.toString()
}
def vertx = Vertx.newVertx()
def server = vertx.createHttpServer()
server.requestHandler { req ->
req.response.chunked = true
//mocked responses
switch(req.path){
case('/alive'):
req.response.end 'hello world'
break
case('/candidate/all'):
req.response.end 'groovy, grails, griffon, gradle'
break
case('/candidate/index/2.1.0'):
req.response.end 'true'
break
case('/candidate/index/grails'):
req.response.end 'true'
break
case('/candidate/index/groovy'):
req.response.end 'true'
break
case('/candidate/index/groffle'):
req.response.end 'false'
break
case('/grails/version'):
req.response.end "2.1.0"
break
case('/grails/version/2.1.0'):
req.response.end "2.1.0"
break
case('/grails/version/1.3.9'):
req.response.end "1.3.9"
break
case('/grails/version/1.4.4'):
req.response.end "invalid"
break
case('/grails/download/1.3.9'):
req.response.end "http://localhost:8080/someurl/downloadz/1.3.9"
break
case('/someurl/downloadz/1.3.9'):
req.response.putHeader("Content-disposition", "attachment; filename=grails-1.3.9.zip")
req.response.sendFile 'src/test/resources/grails-1.3.9.zip'
break
case('/grails/download/2.1.0'):
req.response.end "http://localhost:8080/someurl/downloadz/2.1.0"
break
case('/someurl/downloadz/2.1.0'):
req.response.putHeader("Content-disposition", "attachment; filename=grails-2.1.0.zip")
req.response.sendFile 'src/test/resources/grails-2.1.0.zip'
break
case('/grails/download'):
req.response.end "http://localhost:8080/someurl/downloadz/2.1.0"
break
case('/grails/list'):
assert req.params.current == '2.1.0'
assert req.params.installed.contains('2.1.0')
assert req.params.installed.contains('1.3.9')
req.response.end "Available Grails Versions"
break
default:
req.response.end "Invalid path: ${req.path}"
}
}.listen(8080)
server = vertx.createHttpServer()
server.requestHandler(rm.asClosure())
server.listen(port, host)
server
}
private static buildCsv(list){
if(!list) return ""
def csv = ''
list.each { csv += "$it," }
csv[0..-2]
}
public static stopServer(server){
println "Stopping web service..."
server.close()

View File

@@ -1,7 +1,7 @@
import static cucumber.runtime.groovy.EN.*
import cucumber.runtime.PendingException
scriptPath = 'bin'
scriptPath = 'srv/scripts'
When(~'^I enter \"([^\"]*)\"$') { String command ->
command = "$scriptPath/$command"

View File

@@ -6,7 +6,7 @@ gvmDir = new File(System.getenv('GVM_DIR'))
server = null
Before(){
if(!server) server = startServer()
server = startServer()
cleanUp()
}

View File

@@ -1,17 +1,17 @@
import static cucumber.runtime.groovy.EN.*
import cucumber.runtime.PendingException
scriptPath = 'bin'
scriptPath = 'srv/scripts'
gvmDir = new File(System.getenv('GVM_DIR'))
serviceUrl = System.getenv('GVM_SERVICE')
Given(~'^the default "([^"]*)" candidate is "([^"]*)"$') { String candidate, String version ->
def candidateVersion = new URL("${serviceUrl}/${candidate}/version").text
def candidateVersion = new URL("${serviceUrl}/candidates/${candidate}/default").text
assert candidateVersion == version
}
Then(~'^the candidate "([^"]*)" version "([^"]*)" is installed$') { String candidate, String version ->
def file = new File("${gvmDir}/${candidate}/${version}")
def file = new File("${gvmDir}/${candidate}/${version}")
assert file.exists()
}
@@ -22,4 +22,4 @@ When(~'^the candidate "([^"]*)" version "([^"]*)" is already installed$') { Stri
proc.waitFor()
def result = "${proc.in.text}"
assert result.contains("Done installing!")
}
}

View File

@@ -1,7 +1,7 @@
import static cucumber.runtime.groovy.EN.*
import cucumber.runtime.PendingException
scriptPath = 'bin'
scriptPath = 'srv/scripts'
gvmDir = new File(System.getenv('GVM_DIR'))
Given(~'^I do not have a "([^"]*)" candidate installed$') { String candidate ->

View File

@@ -1,11 +1,11 @@
import static cucumber.runtime.groovy.EN.*
import cucumber.runtime.PendingException
scriptPath = 'bin'
scriptPath = 'srv/scripts'
gvmDir = new File(System.getenv('GVM_DIR'))
serviceUrl = System.getenv('GVM_SERVICE')
Then(~'^the candidate "([^"]*)" is no longer selected$') { String candidate ->
def symlink = new File("$gvmDir/$candidate/current")
assert ! symlink.exists()
}
}

View File

@@ -0,0 +1,12 @@
import static cucumber.runtime.groovy.EN.*
import cucumber.runtime.PendingException
gvmDir = new File(System.getenv('GVM_DIR'))
Then(~'^the gvm scripts are up to date$') { ->
def gvm = new File("$gvmDir/bin/gvm")
assert gvm.exists()
def gvmInit = new File("$gvmDir/bin/gvm-init.sh")
assert gvmInit.exists()
}

View File

@@ -1,7 +1,7 @@
import static cucumber.runtime.groovy.EN.*
import java.nio.file.*
scriptPath = 'bin'
scriptPath = 'srv/scripts'
gvmDir = new File(System.getenv('GVM_DIR'))
Then(~'^the candidate "([^"]*)" version "([^"]*)" is in use$') { String candidate, String version ->
@@ -19,4 +19,4 @@ Then(~'^the candidate "([^"]*)" version "([^"]*)" should be in use$') { String c
Given(~'^the candidate "([^"]*)" version "([^"]*)" is not installed$') { String candidate, String version ->
def directory = FileSystems.default.getPath("$gvmDir/$candidate/$version")
assert ! Files.exists(directory)
}
}