diff --git a/build.gradle b/build.gradle index d5a49da0..5a1efc64 100644 --- a/build.gradle +++ b/build.gradle @@ -42,18 +42,16 @@ repositories { } dependencies { - compile 'org.codehaus.groovy:groovy:2.4.7' - compile 'org.codehaus.groovy:groovy-templates:2.4.7' - compile 'org.codehaus.groovy:groovy-json:2.4.7' + compile 'org.codehaus.groovy:groovy:2.4.5' + compile 'org.codehaus.groovy:groovy-templates:2.4.5' + compile 'org.codehaus.groovy:groovy-json:2.4.5' testCompile 'junit:junit:4.11' - testCompile 'info.cukes:cucumber-groovy:1.2.4' - testCompile 'info.cukes:cucumber-junit:1.2.4' + testCompile 'info.cukes:cucumber-groovy:1.1.8' + testCompile 'info.cukes:cucumber-junit:1.1.8' testCompile('org.spockframework:spock-core:0.7-groovy-2.0') { exclude module: 'groovy-all' } - testCompile('com.github.tomakehurst:wiremock:2.2.2') { - exclude module: 'junit' - } + testCompile 'com.github.tomakehurst:wiremock:1.46' } test.testLogging.exceptionFormat = 'full' diff --git a/src/main/bash/sdkman-env-helpers.sh b/src/main/bash/sdkman-env-helpers.sh index 93df0a45..fe77f2de 100644 --- a/src/main/bash/sdkman-env-helpers.sh +++ b/src/main/bash/sdkman-env-helpers.sh @@ -62,11 +62,7 @@ function __sdkman_determine_version { VERSION=$(__sdkman_secure_curl "${SDKMAN_LEGACY_API}/candidates/${candidate}/default") else - local validation_url="${SDKMAN_CURRENT_API}/candidates/validate/${candidate}/${version}/$(echo $SDKMAN_PLATFORM | tr '[:upper:]' '[:lower:]')" - VERSION_VALID=$(__sdkman_secure_curl "$validation_url") - __sdkman_echo_debug "Validate $candidate $version for $SDKMAN_PLATFORM: $VERSION_VALID" - __sdkman_echo_debug "Validation URL: $validation_url" - + VERSION_VALID=$(__sdkman_secure_curl "${SDKMAN_LEGACY_API}/candidates/${candidate}/${version}") if [[ "$VERSION_VALID" == 'valid' || "$VERSION_VALID" == 'invalid' && -n "$folder" ]]; then VERSION="$version" @@ -78,9 +74,7 @@ function __sdkman_determine_version { else echo "" - echo "Stop! $candidate $version is not available. Possible causes:" - echo " * $version is an invalid version" - echo " * $candidate binaries are incompatible with $SDKMAN_PLATFORM" + echo "Stop! $version is not a valid ${candidate} version." return 1 fi fi diff --git a/src/main/bash/sdkman-init.sh b/src/main/bash/sdkman-init.sh index 7109b214..4a1576b1 100644 --- a/src/main/bash/sdkman-init.sh +++ b/src/main/bash/sdkman-init.sh @@ -114,7 +114,7 @@ fi # fabricate list of candidates SDKMAN_CANDIDATES_FILE="${SDKMAN_DIR}/var/candidates" -if [[ "$sdkman_beta_channel" != "true" && -f "$SDKMAN_CANDIDATES_FILE" && -z "$(find "$SDKMAN_CANDIDATES_FILE" -mmin +$((60*24)))" ]]; then +if [[ -f "$SDKMAN_CANDIDATES_FILE" && -z "$(find "$SDKMAN_CANDIDATES_FILE" -mmin +$((60*24)))" ]]; then SDKMAN_CANDIDATES_CSV=$(cat "$SDKMAN_CANDIDATES_FILE") else SDKMAN_CANDIDATES_CSV=$(__sdkman_secure_curl "${SDKMAN_LEGACY_API}/candidates") @@ -133,7 +133,7 @@ if [[ -z "$sdkman_curl_max_time" ]]; then sdkman_curl_max_time=10; fi # determine if up to date SDKMAN_VERSION_FILE="${SDKMAN_DIR}/var/version" -if [[ "$sdkman_beta_channel" != "true" && -f "$SDKMAN_VERSION_FILE" && -z "$(find "$SDKMAN_VERSION_FILE" -mmin +$((60*24)))" ]]; then +if [[ -f "$SDKMAN_VERSION_FILE" && -z "$(find "$SDKMAN_VERSION_FILE" -mmin +$((60*24)))" ]]; then SDKMAN_REMOTE_VERSION=$(cat "$SDKMAN_VERSION_FILE") else diff --git a/src/main/bash/sdkman-install.sh b/src/main/bash/sdkman-install.sh index ae0412fc..1a2082d0 100644 --- a/src/main/bash/sdkman-install.sh +++ b/src/main/bash/sdkman-install.sh @@ -91,44 +91,25 @@ function __sdkman_install_local_version { } function __sdkman_download { - local candidate version archives_folder + local candidate version candidate="$1" version="$2" - - archives_folder="${SDKMAN_DIR}/archives" - if [ ! -f "${archives_folder}/${candidate}-${version}.zip" ]; then - - #TODO: pre installation hook here - + mkdir -p "${SDKMAN_DIR}/archives" + if [ ! -f "${SDKMAN_DIR}/archives/${candidate}-${version}.zip" ]; then echo "" echo "Downloading: ${candidate} ${version}" echo "" echo "In progress..." echo "" - - local platform_parameter="$(echo $SDKMAN_PLATFORM | tr '[:upper:]' '[:lower:]')" - local download_url="${SDKMAN_CURRENT_API}/broker/download/${candidate}/${version}/${platform_parameter}" - local base_name="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)" - local zip_archive_target="${SDKMAN_DIR}/archives/${candidate}-${version}.zip" - - export local binary_input="${SDKMAN_DIR}/tmp/${base_name}.bin" - export local zip_output="${SDKMAN_DIR}/tmp/$base_name.zip" - - __sdkman_secure_curl_download "$download_url" > "$binary_input" - __sdkman_echo_debug "Downloaded binary to: $binary_input" - - #responsible for taking `binary_input` and producing `zip_output` - __sdkman_secure_curl "${SDKMAN_CURRENT_API}/hooks/post/${candidate}/${version}/${platform_parameter}" | bash - __sdkman_echo_debug "Processed binary as: $zip_output" - - mv "$zip_output" "$zip_archive_target" - __sdkman_echo_debug "Moved to archive folder: $zip_archive_target" + local download_url="${SDKMAN_CURRENT_API}/broker/download/${candidate}/${version}?platform=${SDKMAN_PLATFORM}" + local zip_archive="${SDKMAN_DIR}/archives/${candidate}-${version}.zip" + __sdkman_secure_curl_download "$download_url" > "$zip_archive" else echo "" echo "Found a previously downloaded ${candidate} ${version} archive. Not downloading it again..." fi - __sdkman_validate_zip "${archives_folder}/${candidate}-${version}.zip" || return 1 + __sdkman_validate_zip "${SDKMAN_DIR}/archives/${candidate}-${version}.zip" || return 1 echo "" } diff --git a/src/main/bash/sdkman-utils.sh b/src/main/bash/sdkman-utils.sh index bda75a00..d7ff11c0 100644 --- a/src/main/bash/sdkman-utils.sh +++ b/src/main/bash/sdkman-utils.sh @@ -17,7 +17,7 @@ # function __sdkman_echo_debug { - if [[ "$sdkman_debug_mode" == 'true' ]]; then + if [[ "$SDKMAN_DEBUG_MODE" == 'true' ]]; then echo "$1" fi } diff --git a/src/test/cucumber/default_version.feature b/src/test/cucumber/default_version.feature index f74681d7..ff514e70 100644 --- a/src/test/cucumber/default_version.feature +++ b/src/test/cucumber/default_version.feature @@ -30,4 +30,4 @@ Feature: Default Version Given the candidate "groovy" version "2.9.9" is not available for download And the system is bootstrapped When I enter "sdk default groovy 2.9.9" - Then I see "Stop! groovy 2.9.9 is not available." \ No newline at end of file + Then I see "Stop! 2.9.9 is not a valid groovy version." \ No newline at end of file diff --git a/src/test/cucumber/install_candidate.feature b/src/test/cucumber/install_candidate.feature index b1ac4efc..6e13aee7 100644 --- a/src/test/cucumber/install_candidate.feature +++ b/src/test/cucumber/install_candidate.feature @@ -20,7 +20,7 @@ Feature: Install Candidate Scenario: Install a Candidate version that does not exist Given the candidate "grails" version "1.4.4" is not available for download When I enter "sdk install grails 1.4.4" - Then I see "Stop! grails 1.4.4 is not available." + Then I see "Stop! 1.4.4 is not a valid grails version." Scenario: Install a Candidate version that is already installed Given the candidate "grails" version "1.3.9" is available for download diff --git a/src/test/cucumber/multi_platform_binaries.feature b/src/test/cucumber/multi_platform_binaries.feature deleted file mode 100644 index c887a210..00000000 --- a/src/test/cucumber/multi_platform_binaries.feature +++ /dev/null @@ -1,23 +0,0 @@ -Feature: Multi Platform Binary Distribution - - Background: - Given the internet is reachable - And an initialised environment - - Scenario: A compatible binary is installed - And a machine with "Mac OSX" installed - And the system is bootstrapped - And the candidate "java" version "8u101" is available for download on "Mac OSX" - When I enter "sdk install java 8u101" and answer "Y" - Then I see "Done installing!" - And the candidate "java" version "8u101" is installed - - Scenario: Platform is not supported - And a machine with "FreeBSD" installed - And the system is bootstrapped - And the candidate "java" version "8u101" is not available for download on "FreeBSD" - When I enter "sdk install java 8u101" - Then I see "Stop! java 8u101 is not available. Possible causes:" - Then I see " * 8u101 is an invalid version" - Then I see " * java binaries are incompatible with FreeBSD" - And the candidate "java" version "8u101" is not installed \ No newline at end of file diff --git a/src/test/cucumber/use_version.feature b/src/test/cucumber/use_version.feature index d3881357..9346f5f9 100644 --- a/src/test/cucumber/use_version.feature +++ b/src/test/cucumber/use_version.feature @@ -39,7 +39,7 @@ Feature: Use Version Given the candidate "groovy" version "1.9.9" is not available for download And the system is bootstrapped When I enter "sdk use groovy 1.9.9" - Then I see "Stop! groovy 1.9.9 is not available." + Then I see "Stop! 1.9.9 is not a valid groovy version." Scenario: Use a candidate version that only exists locally Given the candidate "grails" version "2.0.0.M1" is not available for download diff --git a/src/test/groovy/sdkman/env/SdkmanBashEnvBuilder.groovy b/src/test/groovy/sdkman/env/SdkmanBashEnvBuilder.groovy index 993a90bd..17f16453 100644 --- a/src/test/groovy/sdkman/env/SdkmanBashEnvBuilder.groovy +++ b/src/test/groovy/sdkman/env/SdkmanBashEnvBuilder.groovy @@ -10,8 +10,8 @@ class SdkmanBashEnvBuilder { private final File baseFolder //optional fields with sensible defaults - private Optional curlStub = Optional.empty() - private List candidates = ['groovy', 'grails', 'java'] + private CurlStub curlStub + private List candidates = ['groovy', 'grails'] private List availableCandidates = candidates private boolean offlineMode = false private String broadcast = "This is a LIVE broadcast!" @@ -38,7 +38,7 @@ class SdkmanBashEnvBuilder { } SdkmanBashEnvBuilder withCurlStub(CurlStub curlStub) { - this.curlStub = Optional.of(curlStub) + this.curlStub = curlStub this } @@ -108,8 +108,6 @@ class SdkmanBashEnvBuilder { sdkmanTmpDir = prepareDirectory(sdkmanDir, "tmp") sdkmanCandidatesDir = prepareDirectory(sdkmanDir, "candidates") - curlStub.map { cs -> cs.build() } - initializeCandidates(sdkmanCandidatesDir, candidates) initializeAvailableCandidates(sdkmanVarDir, availableCandidates) initializeBroadcast(sdkmanVarDir, broadcast) @@ -126,7 +124,6 @@ class SdkmanBashEnvBuilder { SDKMAN_LEGACY_API : legacyService, SDKMAN_CURRENT_API : currentService, SDKMAN_VERSION : sdkmanVersion, - sdkman_debug_mode : 'true', JAVA_HOME : jdkHome ] diff --git a/src/test/groovy/sdkman/specs/BetaChannelBootstrapSpec.groovy b/src/test/groovy/sdkman/specs/BetaChannelBootstrapSpec.groovy index 9f5dfbab..85b18f2e 100644 --- a/src/test/groovy/sdkman/specs/BetaChannelBootstrapSpec.groovy +++ b/src/test/groovy/sdkman/specs/BetaChannelBootstrapSpec.groovy @@ -15,15 +15,17 @@ class BetaChannelBootstrapSpec extends SdkmanEnvSpecification { versionFile = new File("${sdkmanDotDirectory}/var", "version") } - void "should attempt immediate upgrade of stable to beta version if beta channel is first enabled"() { + void "should attempt upgrade of stable to beta version if beta channel is first enabled"() { given: def betaVersion = "x.y.c" - curlStub.primeWith(CLI_BETA_ENDPOINT, "echo $betaVersion") + curlStub.primeWith(CLI_BETA_ENDPOINT, "echo $betaVersion").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withConfiguration("sdkman_beta_channel", "true") .withVersionFile("x.y.b") .build() + versionFile.setLastModified(TWO_DAYS_AGO) and: bash.start() @@ -39,8 +41,9 @@ class BetaChannelBootstrapSpec extends SdkmanEnvSpecification { void "should attempt downgrade of beta to stable version if beta channel is first disabled"() { given: def stableVersion = "x.y.b" - curlStub.primeWith(CLI_STABLE_ENDPOINT, "echo $stableVersion") + curlStub.primeWith(CLI_STABLE_ENDPOINT, "echo $stableVersion").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withConfiguration("sdkman_beta_channel", "false") .withVersionFile("x.y.c") @@ -58,15 +61,17 @@ class BetaChannelBootstrapSpec extends SdkmanEnvSpecification { versionFile.text.contains(stableVersion) } - void "should attempt immediate upgrade to new version of beta channel if available"() { + void "should attempt upgrade to new version of beta channel if available"() { given: def newerBetaVersion = "x.y.d" - curlStub.primeWith(CLI_BETA_ENDPOINT, "echo $newerBetaVersion") + curlStub.primeWith(CLI_BETA_ENDPOINT, "echo $newerBetaVersion").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withConfiguration("sdkman_beta_channel", "true") .withVersionFile("x.y.c") .build() + versionFile.setLastModified(TWO_DAYS_AGO) and: bash.start() @@ -82,8 +87,9 @@ class BetaChannelBootstrapSpec extends SdkmanEnvSpecification { void "should attempt upgrade to new version of stable channel if available"() { given: def newerStableVersion = "x.y.d" - curlStub.primeWith(CLI_STABLE_ENDPOINT, "echo $newerStableVersion") + curlStub.primeWith(CLI_STABLE_ENDPOINT, "echo $newerStableVersion").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withConfiguration("sdkman_beta_channel", "false") .withVersionFile("x.y.c") @@ -100,4 +106,5 @@ class BetaChannelBootstrapSpec extends SdkmanEnvSpecification { versionFile.exists() versionFile.text.contains(newerStableVersion) } + } diff --git a/src/test/groovy/sdkman/specs/CandidatesFileBootstrapSpec.groovy b/src/test/groovy/sdkman/specs/CandidatesFileBootstrapSpec.groovy index 211d304e..e41510a3 100644 --- a/src/test/groovy/sdkman/specs/CandidatesFileBootstrapSpec.groovy +++ b/src/test/groovy/sdkman/specs/CandidatesFileBootstrapSpec.groovy @@ -5,10 +5,7 @@ import sdkman.support.SdkmanEnvSpecification class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { static final LEGACY_API = "http://localhost:8080" - static final LEGACY_CANDIDATES_ENDPOINT = "$LEGACY_API/candidates" - - static final CURRENT_API = "http://localhost:8080" - static final CURRENT_CANDIDATES_ENDPOINT = "$CURRENT_API/candidates" + static final CANDIDATES_ENDPOINT = "$LEGACY_API/candidates" File candidatesFile @@ -18,8 +15,9 @@ class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { void "should store candidates if does not exist"() { given: 'a working sdkman installation without candidates' - curlStub.primeWith(LEGACY_CANDIDATES_ENDPOINT, "echo groovy,scala") + curlStub.primeWith(CANDIDATES_ENDPOINT, "echo groovy,scala").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withAvailableCandidates([]) .withLegacyService(LEGACY_API) .build() @@ -34,9 +32,10 @@ class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { candidatesFile.exists() } - void "should not query server if fresh candidates file is found"() { + void "should not query server if candidates file is found"() { given: 'a working sdkman installation with candidates file' bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withAvailableCandidates(['gradle', 'sbt']) .build() @@ -53,8 +52,10 @@ class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { void "should query server for candidates and refresh if older than a day"() { given: 'a working sdkman installation with expired candidates' - curlStub.primeWith(LEGACY_CANDIDATES_ENDPOINT, "echo groovy,scala") + curlStub.primeWith(CANDIDATES_ENDPOINT, "echo groovy,scala") + .build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withAvailableCandidates(['groovy']) .build() @@ -72,32 +73,12 @@ class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { candidatesFile.text.contains('groovy,scala') } - void "should always query server for candidates and refresh if subscribed to beta channel"() { - given: 'a working sdkman installation with expired candidates' - curlStub.primeWith(CURRENT_CANDIDATES_ENDPOINT, "echo groovy,java,scala") - bash = sdkmanBashEnvBuilder - .withLegacyService(LEGACY_API) - .withCurrentService(CURRENT_API) - .withConfiguration("sdkman_beta_channel", "true") - .withAvailableCandidates(['groovy']) - .build() - - and: - bash.start() - - when: 'bootstrap the system' - bash.execute("source $bootstrapScript") - - then: - candidatesFile.exists() - candidatesFile.text.contains('groovy,java,scala') - } - void "should ignore candidates if api is offline"() { given: 'a working sdkman installation with api down' def candidates = ['groovy', 'scala'] - curlStub.primeWith(LEGACY_CANDIDATES_ENDPOINT, "echo ''") + curlStub.primeWith(CANDIDATES_ENDPOINT, "echo ''").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withAvailableCandidates(candidates) .build() @@ -114,8 +95,9 @@ class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { void "should not go offline if curl times out"() { given: 'a working sdkman installation with api down' - curlStub.primeWith(LEGACY_CANDIDATES_ENDPOINT, "echo ''") + curlStub.primeWith(CANDIDATES_ENDPOINT, "echo ''").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .build() @@ -132,8 +114,9 @@ class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { void "should ignore candidates if api returns garbage"() { given: 'a working sdkman installation with garbled api' def candidates = ['groovy', 'scala'] - curlStub.primeWith(LEGACY_CANDIDATES_ENDPOINT, "echo 'sorry'") + curlStub.primeWith(CANDIDATES_ENDPOINT, "echo 'sorry'").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withAvailableCandidates(candidates) .build() diff --git a/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy b/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy index 3bf3830d..05b6aa7a 100644 --- a/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy +++ b/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy @@ -33,6 +33,7 @@ class CurrentCommandSpec extends SdkmanEnvSpecification { ] bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withOfflineMode(false) .withAvailableCandidates(allCandidates) .withCandidates(installedCandidates.keySet().toList()) diff --git a/src/test/groovy/sdkman/specs/InitialisationSpec.groovy b/src/test/groovy/sdkman/specs/InitialisationSpec.groovy index 3ab07674..b7289512 100644 --- a/src/test/groovy/sdkman/specs/InitialisationSpec.groovy +++ b/src/test/groovy/sdkman/specs/InitialisationSpec.groovy @@ -14,6 +14,7 @@ class InitialisationSpec extends SdkmanEnvSpecification { bash = sdkmanBashEnvBuilder .withAvailableCandidates(allCandidates) .withCandidates(allCandidates) + .withCurlStub(curlStub) .withVersionFile("x.y.z") .build() prepareCandidateDirectories(allCandidates) diff --git a/src/test/groovy/sdkman/specs/VersionFileBootstrapSpec.groovy b/src/test/groovy/sdkman/specs/VersionFileBootstrapSpec.groovy index ba812e97..663542f0 100644 --- a/src/test/groovy/sdkman/specs/VersionFileBootstrapSpec.groovy +++ b/src/test/groovy/sdkman/specs/VersionFileBootstrapSpec.groovy @@ -17,8 +17,9 @@ class VersionFileBootstrapSpec extends SdkmanEnvSpecification { void "should store version file if does not exist"() { given: 'a working sdkman installation without version file' - curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo x.y.b") + curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo x.y.b").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .build() @@ -35,6 +36,7 @@ class VersionFileBootstrapSpec extends SdkmanEnvSpecification { void "should not query server if version file is found"() { given: 'a working sdkman installation with version file' bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withVersionFile("x.y.z") .build() @@ -51,8 +53,9 @@ class VersionFileBootstrapSpec extends SdkmanEnvSpecification { void "should query server for version and refresh if file is older than a day"() { given: 'a working sdkman installation with expired version file' - curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo x.y.b") + curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo x.y.b").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withVersionFile("x.y.a") .build() @@ -73,8 +76,9 @@ class VersionFileBootstrapSpec extends SdkmanEnvSpecification { void "should ignore version if api is offline"() { given: 'a working sdkman installation with api down' def sdkmanVersion = "x.y.z" - curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo ''") + curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo ''").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withVersionFile(sdkmanVersion) .build() @@ -91,8 +95,9 @@ class VersionFileBootstrapSpec extends SdkmanEnvSpecification { void "should not go offline if curl times out"() { given: 'a working sdkman installation with api down' - curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo ''") + curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo ''").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .build() @@ -109,8 +114,9 @@ class VersionFileBootstrapSpec extends SdkmanEnvSpecification { void "should ignore version if api returns garbage"() { given: 'a working sdkman installation with garbled api' def sdkmanVersion = "x.y.z" - curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo 'sorry'") + curlStub.primeWith(CLI_VERSION_ENDPOINT, "echo 'sorry'").build() bash = sdkmanBashEnvBuilder + .withCurlStub(curlStub) .withLegacyService(LEGACY_API) .withVersionFile(sdkmanVersion) .build() diff --git a/src/test/groovy/sdkman/steps/env.groovy b/src/test/groovy/sdkman/steps/env.groovy index 79da16fe..8224ceed 100644 --- a/src/test/groovy/sdkman/steps/env.groovy +++ b/src/test/groovy/sdkman/steps/env.groovy @@ -9,7 +9,7 @@ import static cucumber.api.groovy.Hooks.After import static cucumber.api.groovy.Hooks.Before HTTP_PROXY = System.getProperty("httpProxy") ?: "" -PLATFORM = UnixUtils.platform.toLowerCase() +PLATFORM = UnixUtils.platform FAKE_JDK_PATH = "/path/to/my/openjdk" SERVICE_UP_HOST="localhost" @@ -70,4 +70,4 @@ After(){ scenario -> scenario.write("\nOutput: \n${output}") } bash?.stop() -} \ No newline at end of file +} diff --git a/src/test/groovy/sdkman/steps/initialisation_steps.groovy b/src/test/groovy/sdkman/steps/initialisation_steps.groovy index 3f45621e..36027136 100644 --- a/src/test/groovy/sdkman/steps/initialisation_steps.groovy +++ b/src/test/groovy/sdkman/steps/initialisation_steps.groovy @@ -1,7 +1,5 @@ package sdkman.steps -import sdkman.stubs.UnameStub - import java.util.zip.ZipException import java.util.zip.ZipFile @@ -11,8 +9,6 @@ import static sdkman.stubs.WebServiceStub.primeSelfupdate import sdkman.env.SdkmanBashEnvBuilder -import static sdkman.support.UnixUtils.asUname - And(~'^the sdkman work folder is created$') { -> assert sdkmanDir.isDirectory(), "The SDKMAN directory does not exist." } @@ -79,13 +75,6 @@ And(~'^offline mode is enabled with unreachable internet$') {-> javaHome = FAKE_JDK_PATH } -And(~'^a machine with "(.*)" installed$') { String platform -> - def binFolder = "$sdkmanBaseDir/bin" as File - UnameStub.prepareIn(binFolder) - .forPlatform(asUname(platform)) - .build() -} - And(~'^an initialised environment$') {-> bash = SdkmanBashEnvBuilder.create(sdkmanBaseDir) .withOfflineMode(offlineMode) diff --git a/src/test/groovy/sdkman/steps/stub_steps.groovy b/src/test/groovy/sdkman/steps/stub_steps.groovy index 2d19091f..d63e5417 100644 --- a/src/test/groovy/sdkman/steps/stub_steps.groovy +++ b/src/test/groovy/sdkman/steps/stub_steps.groovy @@ -1,7 +1,5 @@ package sdkman.steps -import sdkman.support.UnixUtils - import static cucumber.api.groovy.EN.And import static sdkman.stubs.WebServiceStub.* import static sdkman.support.FilesystemUtils.readCurrentFromCandidateFolder @@ -10,7 +8,6 @@ import static sdkman.support.FilesystemUtils.readVersionsCsvFromCandidateFolder And(~'^the default "([^"]*)" candidate is "([^"]*)"$') { String candidate, String version -> primeEndpointWithString("/candidates/${candidate}/default", version) primeDownloadFor(SERVICE_UP_URL, candidate, version, PLATFORM) - primeEndpointWithString("/hooks/post/${candidate}/${version}/${PLATFORM}", 'mv $binary_input $zip_output') //bash command } And(~'^an available selfupdate$') { -> @@ -18,25 +15,12 @@ And(~'^an available selfupdate$') { -> } And(~'^the candidate "([^"]*)" version "([^"]*)" is available for download$') { String candidate, String version -> - primeEndpointWithString("/candidates/validate/${candidate}/${version}/${PLATFORM}", "valid") + primeEndpointWithString("/candidates/${candidate}/${version}", "valid") primeDownloadFor(SERVICE_UP_URL, candidate, version, PLATFORM) - primeEndpointWithString("/hooks/post/${candidate}/${version}/${PLATFORM}", 'mv $binary_input $zip_output') //bash command } And(~'^the candidate "([^"]*)" version "([^"]*)" is not available for download$') { String candidate, String version -> - primeEndpointWithString("/candidates/validate/${candidate}/${version}/${PLATFORM}", "invalid") -} - -And(~/^the candidate "(.*?)" version "(.*?)" is available for download on "(.*?)"$/) { String candidate, String version, String platform -> - String lowerCaseUname = UnixUtils.asUname(platform).toLowerCase() - primeEndpointWithString("/candidates/validate/${candidate}/${version}/${lowerCaseUname}", "valid") - primeEndpointWithString("/hooks/post/${candidate}/${version}/${lowerCaseUname}", 'mv $binary_input $zip_output') //bash command - primeDownloadFor(SERVICE_UP_URL, candidate, version, lowerCaseUname) -} - -And(~/^the candidate "(.*?)" version "(.*?)" is not available for download on "(.*?)"$/) { String candidate, String version, String platform -> - String lowerCaseUname = UnixUtils.asUname(platform).toLowerCase() - primeEndpointWithString("/candidates/validate/${candidate}/${version}/${lowerCaseUname}", "invalid") + primeEndpointWithString("/candidates/${candidate}/${version}", "invalid") } And(~'^a "([^"]*)" list view is available for consumption$') { String candidate -> @@ -44,11 +28,11 @@ And(~'^a "([^"]*)" list view is available for consumption$') { String candidate } And(~'^the candidate "([^"]*)" version "([^"]*)" is a valid candidate version$') { String candidate, String version -> - primeEndpointWithString("/candidates/validate/${candidate}/${version}/${PLATFORM}", "valid") + primeEndpointWithString("/candidates/${candidate}/${version}", "valid") } And(~'^the candidate "([^"]*)" version "([^"]*)" is not a valid candidate version$') { String candidate, String version -> - primeEndpointWithString("/candidates/validate/${candidate}/${version}/${PLATFORM}", "invalid") + primeEndpointWithString("/candidates/${candidate}/${version}", "invalid") } And(~/^the candidate "(.*?)" has a version list available$/) { String candidate -> diff --git a/src/test/groovy/sdkman/stubs/UnameStub.groovy b/src/test/groovy/sdkman/stubs/UnameStub.groovy deleted file mode 100644 index 269805f2..00000000 --- a/src/test/groovy/sdkman/stubs/UnameStub.groovy +++ /dev/null @@ -1,27 +0,0 @@ -package sdkman.stubs - -class UnameStub { - - private File file - private uname - - static UnameStub prepareIn(File folder) { - folder.mkdirs() - - def file = new File(folder, "uname") - file.createNewFile() - file.write "#!/bin/bash\n" - file.executable = true - - new UnameStub(file:file) - } - - UnameStub forPlatform(String uname) { - this.uname = uname - this - } - - void build(){ - file << "echo $uname" - } -} diff --git a/src/test/groovy/sdkman/stubs/WebServiceStub.groovy b/src/test/groovy/sdkman/stubs/WebServiceStub.groovy index 8cf02c22..22424235 100644 --- a/src/test/groovy/sdkman/stubs/WebServiceStub.groovy +++ b/src/test/groovy/sdkman/stubs/WebServiceStub.groovy @@ -12,9 +12,16 @@ class WebServiceStub { .withBody(body))) } + static primeEndpointWithBinary(String endpoint, byte[] body) { + stubFor(get(urlEqualTo(endpoint)).willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/octet-stream") + .withBody(body))) + } static primeDownloadFor(String host, String candidate, String version, String platform) { - stubFor(get(urlEqualTo("/broker/download/${candidate}/${version}/${platform}")).willReturn( + stubFor(get(urlEqualTo("/broker/download/${candidate}/${version}?platform=${platform}")).willReturn( aResponse() .withHeader("Location", "${host}/${candidate}-${version}.zip") .withStatus(302))) diff --git a/src/test/groovy/sdkman/support/SdkmanEnvSpecification.groovy b/src/test/groovy/sdkman/support/SdkmanEnvSpecification.groovy index bd5b4072..be72b128 100644 --- a/src/test/groovy/sdkman/support/SdkmanEnvSpecification.groovy +++ b/src/test/groovy/sdkman/support/SdkmanEnvSpecification.groovy @@ -19,14 +19,12 @@ abstract class SdkmanEnvSpecification extends BashEnvSpecification { def setup() { sdkmanBaseDirectory = prepareBaseDir() - curlStub = CurlStub.prepareIn(new File(sdkmanBaseDirectory, "bin")) - sdkmanBashEnvBuilder = SdkmanBashEnvBuilder - .create(sdkmanBaseDirectory) - .withCurlStub(curlStub) + sdkmanBashEnvBuilder = SdkmanBashEnvBuilder.create(sdkmanBaseDirectory) sdkmanDotDirectory = new File(sdkmanBaseDirectory, ".sdkman") candidatesDirectory = new File(sdkmanDotDirectory, "candidates") bootstrapScript = "${sdkmanDotDirectory}/bin/sdkman-init.sh" + curlStub = CurlStub.prepareIn(new File(sdkmanBaseDirectory, "bin")) } def cleanup() { diff --git a/src/test/groovy/sdkman/support/UnixUtils.groovy b/src/test/groovy/sdkman/support/UnixUtils.groovy index d3d6ddc3..d61eef6e 100644 --- a/src/test/groovy/sdkman/support/UnixUtils.groovy +++ b/src/test/groovy/sdkman/support/UnixUtils.groovy @@ -2,24 +2,14 @@ package sdkman.support class UnixUtils { static getPlatform() { - asUname(System.getProperty("os.name")) - } - - static asUname(platform) { - def result - switch (platform) { - case "Mac OSX": - result = "Darwin" - break - case "Linux": - result = "Linux" - break - case "FreeBSD": - result = "FreeBSD" + def osName = System.getProperty("os.name") + switch (osName) { + case "Mac OS X": + "Darwin" break default: - result = platform + osName + break } - result } } diff --git a/src/test/resources/__files/java-8u101.zip b/src/test/resources/__files/java-8u101.zip deleted file mode 100644 index 864ab5fe..00000000 Binary files a/src/test/resources/__files/java-8u101.zip and /dev/null differ