From 807563f6c9948340ebeebd08797145ad2f95fd35 Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Wed, 28 Aug 2013 08:51:44 +0100 Subject: [PATCH] Move environment initialisation into own step definition. --- src/test/cucumber/gvm/broadcast.feature | 1 + .../cucumber/gvm/command_line_interop.feature | 4 +- .../cucumber/gvm/current_candidate.feature | 3 +- src/test/cucumber/gvm/flush.feature | 1 + .../cucumber/gvm/forced_offline_mode.feature | 15 +++++++ .../gvm/idempotent_self_update.feature | 4 +- src/test/cucumber/gvm/initialisation.feature | 2 +- .../cucumber/gvm/install_candidate.feature | 1 + src/test/cucumber/gvm/list_candidates.feature | 1 + .../gvm/local_developement_versions.feature | 1 + src/test/cucumber/gvm/mnemonics.feature | 1 + src/test/cucumber/gvm/offline_mode.feature | 1 + src/test/cucumber/gvm/self_update.feature | 4 +- .../cucumber/gvm/uninstall_candidate.feature | 1 + .../gvm/use_and_default_candidate.feature | 1 + src/test/cucumber/gvm/version.feature | 1 + src/test/steps/gvm/env.groovy | 5 ++- .../steps/gvm/initialisation_steps.groovy | 44 +++++++++---------- src/test/steps/gvm/installation_steps.groovy | 4 +- 19 files changed, 61 insertions(+), 34 deletions(-) diff --git a/src/test/cucumber/gvm/broadcast.feature b/src/test/cucumber/gvm/broadcast.feature index efc3998d..0f70d4b8 100644 --- a/src/test/cucumber/gvm/broadcast.feature +++ b/src/test/cucumber/gvm/broadcast.feature @@ -2,6 +2,7 @@ Feature: Broadcast Background: Given the internet is reachable + And an initialised environment Scenario: A command is issued with no prior Broadcast received Given no prior Broadcast was received diff --git a/src/test/cucumber/gvm/command_line_interop.feature b/src/test/cucumber/gvm/command_line_interop.feature index 03d2af8e..f2cc6b50 100644 --- a/src/test/cucumber/gvm/command_line_interop.feature +++ b/src/test/cucumber/gvm/command_line_interop.feature @@ -1,8 +1,8 @@ Feature: Command Line Interop Background: - Given an initialised system - And the internet is reachable + Given the internet is reachable + And an initialised environment Scenario: Enter gvm When I enter "gvm" diff --git a/src/test/cucumber/gvm/current_candidate.feature b/src/test/cucumber/gvm/current_candidate.feature index d800f336..ebb5a016 100644 --- a/src/test/cucumber/gvm/current_candidate.feature +++ b/src/test/cucumber/gvm/current_candidate.feature @@ -1,7 +1,8 @@ Feature: Current Candidate Background: - And the internet is reachable + Given the internet is reachable + And an initialised environment Scenario: Display current candidate version in use Given the candidate "grails" version "1.3.9" is already installed and default diff --git a/src/test/cucumber/gvm/flush.feature b/src/test/cucumber/gvm/flush.feature index 558e5eb5..bf703bba 100644 --- a/src/test/cucumber/gvm/flush.feature +++ b/src/test/cucumber/gvm/flush.feature @@ -2,6 +2,7 @@ Feature: Flush Background: Given the internet is reachable + And an initialised environment Scenario: Flush omitting the Qualifier When I enter "gvm flush" diff --git a/src/test/cucumber/gvm/forced_offline_mode.feature b/src/test/cucumber/gvm/forced_offline_mode.feature index abcb5553..c02d54a7 100644 --- a/src/test/cucumber/gvm/forced_offline_mode.feature +++ b/src/test/cucumber/gvm/forced_offline_mode.feature @@ -4,16 +4,19 @@ Feature: Forced Offline Mode Scenario: Enter an invalid offline mode Given offline mode is disabled with reachable internet + And an initialised environment When I enter "gvm offline grails" Then I see "Stop! grails is not a valid offline mode." Scenario: Issue Offline command without qualification Given offline mode is disabled with reachable internet + And an initialised environment When I enter "gvm offline" Then I see "Stop! Specify a valid offline mode." Scenario: Enable Offline Mode with internet reachable Given offline mode is disabled with reachable internet + And an initialised environment When I enter "gvm offline enable" Then I see "Forced offline mode enabled." And I do not see "OFFLINE MODE ENABLED!" @@ -22,6 +25,7 @@ Feature: Forced Offline Mode Scenario: Disable Offline Mode with internet reachable Given offline mode is enabled with reachable internet + And an initialised environment When I enter "gvm offline disable" Then I see "Online mode re-enabled!" When I enter "gvm install grails 2.1.0" and answer "Y" @@ -30,6 +34,7 @@ Feature: Forced Offline Mode Scenario: Disable Offline Mode with internet unreachable Given offline mode is enabled with unreachable internet + And an initialised environment When I enter "gvm offline disable" Then I see "Online mode re-enabled!" When I enter "gvm install grails 2.1.0" @@ -39,6 +44,7 @@ Feature: Forced Offline Mode #broadcast Scenario: Recall a broadcast while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment When a prior Broadcast "This is an OLD Broadcast!" was issued And I enter "gvm broadcast" Then I see "This is an OLD Broadcast!" @@ -46,18 +52,21 @@ Feature: Forced Offline Mode #gvm version Scenario: Determine the GVM version while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment When I enter "gvm version" Then I see the current gvm version #list candidate version Scenario: List candidate versions found while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment When I enter "gvm list grails" Then I see "Offline Mode: only showing installed grails versions" #use version Scenario: Use an uninstalled candidate version while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment And the candidate "grails" version "1.3.9" is already installed and default And the candidate "grails" version "2.1.0" is not installed When I enter "gvm use grails 2.1.0" @@ -66,6 +75,7 @@ Feature: Forced Offline Mode #default version Scenario: Set the default to an uninstalled candidate version while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment And the candidate "grails" version "1.3.9" is already installed and default When I enter "gvm default grails 2.1.0" Then I see "Stop! grails 2.1.0 is not available in offline mode." @@ -73,6 +83,7 @@ Feature: Forced Offline Mode #install command Scenario: Install a candidate version that is not installed while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment And the candidate "grails" version "2.1.0" is not installed When I enter "gvm install grails 2.1.0" Then I see "Stop! grails 2.1.0 is not available in offline mode." @@ -80,6 +91,7 @@ Feature: Forced Offline Mode #uninstall command Scenario: Uninstall a candidate version while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment And the candidate "grails" version "2.1.0" is already installed and default When I enter "gvm uninstall grails 2.1.0" And the candidate "grails" version "2.1.0" is not installed @@ -87,6 +99,7 @@ Feature: Forced Offline Mode #current command Scenario: Display the current version of a candidate while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment And the candidate "grails" version "2.1.0" is already installed and default When I enter "gvm current grails" Then I see "Using grails version 2.1.0" @@ -94,12 +107,14 @@ Feature: Forced Offline Mode #help command Scenario: Request help while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment When I enter "gvm help" Then I see "Usage: gvm [version]" #selfupdate command Scenario: Attempt self-update while Forced Offline Given offline mode is enabled with reachable internet + And an initialised environment When I enter "gvm selfupdate" Then I see "This command is not available in offline mode." diff --git a/src/test/cucumber/gvm/idempotent_self_update.feature b/src/test/cucumber/gvm/idempotent_self_update.feature index a8ecd733..1716df77 100644 --- a/src/test/cucumber/gvm/idempotent_self_update.feature +++ b/src/test/cucumber/gvm/idempotent_self_update.feature @@ -1,7 +1,7 @@ Feature: Idempotent Self Update Scenario: Attempt Self Update on an up to date system - Given an initialised system - And the internet is reachable + Given the internet is reachable + And an initialised environment When I enter "gvm selfupdate" Then I see "No update available at this time." \ No newline at end of file diff --git a/src/test/cucumber/gvm/initialisation.feature b/src/test/cucumber/gvm/initialisation.feature index 091518a2..95d1189c 100644 --- a/src/test/cucumber/gvm/initialisation.feature +++ b/src/test/cucumber/gvm/initialisation.feature @@ -2,13 +2,13 @@ Feature: Initialisation Background: Given the internet is reachable + And an initialised environment Scenario: Use gvm for the first time When I enter "gvm" Then the gvm work folder is created Scenario: Use gvm after initialisation - Given an initialised system When I enter "gvm" Then I see "Usage: gvm [version]" Then the gvm work folder is created diff --git a/src/test/cucumber/gvm/install_candidate.feature b/src/test/cucumber/gvm/install_candidate.feature index fb640245..9295cc52 100644 --- a/src/test/cucumber/gvm/install_candidate.feature +++ b/src/test/cucumber/gvm/install_candidate.feature @@ -2,6 +2,7 @@ Feature: Install Candidate Background: Given the internet is reachable + And an initialised environment Scenario: Install a default Candidate Given the default "grails" candidate is "2.1.0" diff --git a/src/test/cucumber/gvm/list_candidates.feature b/src/test/cucumber/gvm/list_candidates.feature index e60ed428..37b58341 100644 --- a/src/test/cucumber/gvm/list_candidates.feature +++ b/src/test/cucumber/gvm/list_candidates.feature @@ -2,6 +2,7 @@ Feature: List Candidates Background: Given the internet is reachable + And an initialised environment Scenario: List an uninstalled available Version Given I do not have a "grails" candidate installed diff --git a/src/test/cucumber/gvm/local_developement_versions.feature b/src/test/cucumber/gvm/local_developement_versions.feature index 6f6b2868..1826ac08 100644 --- a/src/test/cucumber/gvm/local_developement_versions.feature +++ b/src/test/cucumber/gvm/local_developement_versions.feature @@ -2,6 +2,7 @@ Feature: Local Development Versions Background: Given the internet is reachable + And an initialised environment Scenario: Install a new local development version Given the candidate "groovy" version "2.1-SNAPSHOT" is not available for download diff --git a/src/test/cucumber/gvm/mnemonics.feature b/src/test/cucumber/gvm/mnemonics.feature index 86664381..1f42bcdb 100644 --- a/src/test/cucumber/gvm/mnemonics.feature +++ b/src/test/cucumber/gvm/mnemonics.feature @@ -2,6 +2,7 @@ Feature: Mnemonics Background: Given the internet is reachable + And an initialised environment Scenario: Shortcut for listing an uninstalled available Version Given I do not have a "grails" candidate installed diff --git a/src/test/cucumber/gvm/offline_mode.feature b/src/test/cucumber/gvm/offline_mode.feature index bcee96db..0eed5300 100644 --- a/src/test/cucumber/gvm/offline_mode.feature +++ b/src/test/cucumber/gvm/offline_mode.feature @@ -2,6 +2,7 @@ Feature: Offline Mode Background: Given the internet is not reachable + And an initialised environment # list command diff --git a/src/test/cucumber/gvm/self_update.feature b/src/test/cucumber/gvm/self_update.feature index e52e89c0..98f47c75 100644 --- a/src/test/cucumber/gvm/self_update.feature +++ b/src/test/cucumber/gvm/self_update.feature @@ -1,9 +1,9 @@ Feature: Self Update Background: - Given an initialised system - And an outdated system + Given an outdated system And the internet is reachable + And an initialised environment Scenario: Upgrade an outdated installation When I enter "gvm selfupdate" diff --git a/src/test/cucumber/gvm/uninstall_candidate.feature b/src/test/cucumber/gvm/uninstall_candidate.feature index dc91d31a..eeef1e6d 100644 --- a/src/test/cucumber/gvm/uninstall_candidate.feature +++ b/src/test/cucumber/gvm/uninstall_candidate.feature @@ -2,6 +2,7 @@ Feature: Uninstall Candidate Background: Given the internet is reachable + And an initialised environment Scenario: Uninstall an installed Candidate Version not in use Given the candidate "grails" version "2.1.0" is already installed but not default diff --git a/src/test/cucumber/gvm/use_and_default_candidate.feature b/src/test/cucumber/gvm/use_and_default_candidate.feature index 7f460698..20278c8a 100644 --- a/src/test/cucumber/gvm/use_and_default_candidate.feature +++ b/src/test/cucumber/gvm/use_and_default_candidate.feature @@ -2,6 +2,7 @@ Feature: Use and Default Candidate Background: Given the internet is reachable + And an initialised environment Scenario: Use without providing a Candidate When I enter "gvm use" diff --git a/src/test/cucumber/gvm/version.feature b/src/test/cucumber/gvm/version.feature index e07a8a65..0b9e1751 100644 --- a/src/test/cucumber/gvm/version.feature +++ b/src/test/cucumber/gvm/version.feature @@ -2,6 +2,7 @@ Feature: Version Background: Given the internet is reachable + And an initialised environment Scenario: Show the current version of gvm When I enter "gvm version" diff --git a/src/test/steps/gvm/env.groovy b/src/test/steps/gvm/env.groovy index 7096533a..edcf3f31 100644 --- a/src/test/steps/gvm/env.groovy +++ b/src/test/steps/gvm/env.groovy @@ -3,7 +3,10 @@ package gvm import static cucumber.api.groovy.Hooks.* import static gvm.VertxUtils.* -serviceUrlEnv = "http://localhost:8080" +SERVICE_DOWN_URL = "http://localhost:0" +SERVICE_UP_URL = "http://localhost:8080" +FAKE_JDK_PATH = "/path/to/my/openjdk" + forceOffline = false buildScriptDir = new File("build/testScripts") diff --git a/src/test/steps/gvm/initialisation_steps.groovy b/src/test/steps/gvm/initialisation_steps.groovy index 8eeb9eaa..355b4cda 100644 --- a/src/test/steps/gvm/initialisation_steps.groovy +++ b/src/test/steps/gvm/initialisation_steps.groovy @@ -5,9 +5,6 @@ import java.util.zip.ZipFile import static cucumber.api.groovy.EN.* -final SERVICE_DOWN = "http://localhost:0" -final FAKE_JDK_PATH = "/path/to/my/openjdk" - Then(~'^the gvm work folder is created$') { -> assert gvmDir.isDirectory(), "The gvm directory does not exist." } @@ -16,10 +13,6 @@ Then(~'^the "([^"]*)" folder exists in user home$') { String arg1 -> assert gvmDir.isDirectory(), "The gvm directory does not exist." } -Given(~'^an initialised system$') { -> - gvmDir.mkdirs() -} - When(~'^the archive for candidate "([^"]*)" version "([^"]*)" is corrupt$') { String candidate, String version -> try { new ZipFile(new File("src/test/resources/${candidate}-${version}.zip")) @@ -51,36 +44,41 @@ When(~'^I reinitialise the shell$') { -> } Given(~'^the internet is reachable$') {-> - def forceOffline = "false" - def online = "true" - initialiseEnvironment(gvmBaseEnv, gvmDirEnv, online, forceOffline, serviceUrlEnv, FAKE_JDK_PATH) + forceOffline = "false" + online = "true" + serviceUrlEnv = SERVICE_UP_URL + javaHome = FAKE_JDK_PATH } Given(~'^the internet is not reachable$') {-> - def forceOffline = "false" - def online = "false" - initialiseEnvironment(gvmBaseEnv, gvmDirEnv, online, forceOffline, SERVICE_DOWN, FAKE_JDK_PATH) + forceOffline = "false" + online = "false" + serviceUrlEnv = SERVICE_DOWN_URL + javaHome = FAKE_JDK_PATH } And(~'^offline mode is disabled with reachable internet$') {-> - def forceOffline = "false" - def online = "true" - initialiseEnvironment(gvmBaseEnv, gvmDirEnv, online, forceOffline, serviceUrlEnv, FAKE_JDK_PATH) + forceOffline = "false" + online = "true" + serviceUrlEnv = SERVICE_UP_URL + javaHome = FAKE_JDK_PATH } And(~'^offline mode is enabled with reachable internet$') {-> - def forceOffline = "true" - def online = "true" - initialiseEnvironment(gvmBaseEnv, gvmDirEnv, online, forceOffline, serviceUrlEnv, FAKE_JDK_PATH) + forceOffline = "true" + online = "true" + serviceUrlEnv = SERVICE_UP_URL + javaHome = FAKE_JDK_PATH } And(~'^offline mode is enabled with unreachable internet$') {-> - def forceOffline = "true" - def online = "false" - initialiseEnvironment(gvmBaseEnv, gvmDirEnv, online, forceOffline, SERVICE_DOWN, FAKE_JDK_PATH) + forceOffline = "true" + online = "false" + serviceUrlEnv = SERVICE_DOWN_URL + javaHome = FAKE_JDK_PATH } -private initialiseEnvironment(gvmBaseEnv, gvmDirEnv, online, forceOffline, serviceUrlEnv, javaHome){ +And(~'^an initialised environment$') {-> bash = new BashEnv(gvmBaseEnv, [GVM_DIR: gvmDirEnv, GVM_ONLINE:online, GVM_FORCE_OFFLINE: forceOffline, GVM_SERVICE: serviceUrlEnv, JAVA_HOME: javaHome]) bash.start() bash.execute("source $gvmDirEnv/bin/gvm-init.sh") diff --git a/src/test/steps/gvm/installation_steps.groovy b/src/test/steps/gvm/installation_steps.groovy index 54819821..b91607e5 100644 --- a/src/test/steps/gvm/installation_steps.groovy +++ b/src/test/steps/gvm/installation_steps.groovy @@ -7,7 +7,7 @@ import java.nio.file.Path import static cucumber.api.groovy.EN.* Given(~'^the default "([^"]*)" candidate is "([^"]*)"$') { String candidate, String version -> - def candidateVersion = new URL("${serviceUrlEnv}/candidates/${candidate}/default").text + def candidateVersion = new URL("${SERVICE_UP_URL}/candidates/${candidate}/default").text assert candidateVersion == version } @@ -45,7 +45,7 @@ Given(~'^I do not have a "([^"]*)" candidate installed$') { String candidate -> } Given(~'^the candidate "([^"]*)" version "([^"]*)" is not available for download$') { String candidate, String version -> - def versions = new URL("${serviceUrlEnv}/candidates/${candidate}").text + def versions = new URL("${SERVICE_UP_URL}/candidates/${candidate}").text assert ! versions.contains(version) }