From 60ddf4c15fc6c977095da2102bbdc66057612fda Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Thu, 27 Sep 2012 20:51:59 +0100 Subject: [PATCH] Update cucumber to work with new stubs. --- src/test/cucumber/gvm/list.feature | 6 +- src/test/cucumber/gvm/uninstall.feature | 6 +- src/test/cucumber/gvm/upgrade.feature | 8 + src/test/groovy/gvm/VertxUtils.groovy | 169 +++++++++++------- .../gvm/command_line_interop_steps.groovy | 2 +- src/test/resources/gvm/env.groovy | 2 +- .../resources/gvm/installation_steps.groovy | 8 +- src/test/resources/gvm/list_steps.groovy | 2 +- src/test/resources/gvm/uninstall_steps.groovy | 4 +- src/test/resources/gvm/upgrade_steps.groovy | 12 ++ src/test/resources/gvm/use_steps.groovy | 4 +- 11 files changed, 140 insertions(+), 83 deletions(-) create mode 100644 src/test/cucumber/gvm/upgrade.feature create mode 100644 src/test/resources/gvm/upgrade_steps.groovy diff --git a/src/test/cucumber/gvm/list.feature b/src/test/cucumber/gvm/list.feature index 6fcc5f92..4152aa65 100644 --- a/src/test/cucumber/gvm/list.feature +++ b/src/test/cucumber/gvm/list.feature @@ -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." diff --git a/src/test/cucumber/gvm/uninstall.feature b/src/test/cucumber/gvm/uninstall.feature index 153c3eee..c6173d14 100644 --- a/src/test/cucumber/gvm/uninstall.feature +++ b/src/test/cucumber/gvm/uninstall.feature @@ -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 \ No newline at end of file diff --git a/src/test/cucumber/gvm/upgrade.feature b/src/test/cucumber/gvm/upgrade.feature new file mode 100644 index 00000000..1b35d9e7 --- /dev/null +++ b/src/test/cucumber/gvm/upgrade.feature @@ -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 + diff --git a/src/test/groovy/gvm/VertxUtils.groovy b/src/test/groovy/gvm/VertxUtils.groovy index ab2d2f2c..3c06ea74 100644 --- a/src/test/groovy/gvm/VertxUtils.groovy +++ b/src/test/groovy/gvm/VertxUtils.groovy @@ -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() diff --git a/src/test/resources/gvm/command_line_interop_steps.groovy b/src/test/resources/gvm/command_line_interop_steps.groovy index 56839b84..2999650d 100644 --- a/src/test/resources/gvm/command_line_interop_steps.groovy +++ b/src/test/resources/gvm/command_line_interop_steps.groovy @@ -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" diff --git a/src/test/resources/gvm/env.groovy b/src/test/resources/gvm/env.groovy index d03ac406..398f99d6 100644 --- a/src/test/resources/gvm/env.groovy +++ b/src/test/resources/gvm/env.groovy @@ -6,7 +6,7 @@ gvmDir = new File(System.getenv('GVM_DIR')) server = null Before(){ - if(!server) server = startServer() + server = startServer() cleanUp() } diff --git a/src/test/resources/gvm/installation_steps.groovy b/src/test/resources/gvm/installation_steps.groovy index 3941ad11..8c0662a7 100644 --- a/src/test/resources/gvm/installation_steps.groovy +++ b/src/test/resources/gvm/installation_steps.groovy @@ -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!") -} \ No newline at end of file +} diff --git a/src/test/resources/gvm/list_steps.groovy b/src/test/resources/gvm/list_steps.groovy index 7c070044..b7a2565b 100644 --- a/src/test/resources/gvm/list_steps.groovy +++ b/src/test/resources/gvm/list_steps.groovy @@ -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 -> diff --git a/src/test/resources/gvm/uninstall_steps.groovy b/src/test/resources/gvm/uninstall_steps.groovy index 0bc3fbd8..70f55108 100644 --- a/src/test/resources/gvm/uninstall_steps.groovy +++ b/src/test/resources/gvm/uninstall_steps.groovy @@ -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() -} \ No newline at end of file +} diff --git a/src/test/resources/gvm/upgrade_steps.groovy b/src/test/resources/gvm/upgrade_steps.groovy new file mode 100644 index 00000000..ff48df63 --- /dev/null +++ b/src/test/resources/gvm/upgrade_steps.groovy @@ -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() +} \ No newline at end of file diff --git a/src/test/resources/gvm/use_steps.groovy b/src/test/resources/gvm/use_steps.groovy index c6f58e11..1bbefcb0 100644 --- a/src/test/resources/gvm/use_steps.groovy +++ b/src/test/resources/gvm/use_steps.groovy @@ -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) -} \ No newline at end of file +}