Skip to content

Commit

Permalink
Upgrade gradle to 3.2.1 and switch to use TestKit
Browse files Browse the repository at this point in the history
  • Loading branch information
ghale committed Nov 30, 2016
1 parent 16ae685 commit 2a841b1
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 71 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ buildscript {
}

apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'java-gradle-plugin'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'idea'
Expand Down Expand Up @@ -67,6 +68,8 @@ dependencies {
exclude(module: 'groovy-all')
}

integTestCompile gradleTestKit()

jenkins('org.jenkins-ci.main:jenkins-war:1.+') { transitive = false }
}

Expand All @@ -82,7 +85,6 @@ task integTest(type: Test) {
testClassesDir = compileIntegTestJava.destinationDir

systemProperty "jenkins.port", "${jenkinsPort}"
systemProperty "jenkins.plugin", "${jar.archivePath}"
shouldRunAfter test
}
check.dependsOn integTest
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Apr 02 11:30:33 EDT 2015
#Wed Nov 30 09:38:19 EST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip
10 changes: 3 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ case "`uname`" in
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
Expand All @@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

Expand Down Expand Up @@ -114,6 +109,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package com.terrafolio.gradle.plugins.jenkins.integTest

import nebula.test.IntegrationSpec
import nebula.test.functional.ExecutionResult
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification

abstract class AbstractJenkinsIntegrationTest extends IntegrationSpec {
abstract class AbstractJenkinsIntegrationTest extends Specification {
@Rule final TemporaryFolder testProjectDir = new TemporaryFolder()
def serverName = "test"
def needsCleanup = true
File buildFile

def setup() {
fork = true
buildFile = testProjectDir.newFile("build.gradle")
buildFile << """
buildscript {
dependencies {
classpath files('${System.getProperty('jenkins.plugin').replaceAll("\\\\", "/")}')
}
plugins {
id 'com.terrafolio.jenkins'
}
apply plugin: 'com.terrafolio.jenkins'
jenkins {
servers {
${serverName} {
Expand All @@ -30,19 +31,33 @@ abstract class AbstractJenkinsIntegrationTest extends IntegrationSpec {
"""
}

@Override
protected ExecutionResult runTasks(String... tasks) {
ExecutionResult result = super.runTasks(tasks)
println "<========= Standard Output =========>"
println result.standardOutput
println "<========= Standard Error =========>"
println result.standardError
return result
TaskResults succeeds(String... tasks) {
BuildResult result = GradleRunner.create()
.withPluginClasspath()
.withProjectDir(testProjectDir.root)
.withArguments(tasks)
.build()
println result.output
return new TaskResults(result)
}

TaskResults fails(String... tasks) {
BuildResult result = GradleRunner.create()
.withPluginClasspath()
.withProjectDir(testProjectDir.root)
.withArguments(tasks)
.buildAndFail()
println result.output
return new TaskResults(result)
}

boolean fileExists(String relativePath) {
return new File(testProjectDir.root, relativePath).exists()
}

def cleanup() {
if (needsCleanup) {
runTasks("deleteJenkinsItems")
succeeds("deleteJenkinsItems")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.terrafolio.gradle.plugins.jenkins.integTest

import nebula.test.functional.ExecutionResult

class JenkinsErrorHandlingIntegrationTest extends AbstractJenkinsIntegrationTest {
def setup() {
buildFile << """
Expand All @@ -26,12 +24,12 @@ class JenkinsErrorHandlingIntegrationTest extends AbstractJenkinsIntegrationTest
"""

when:
ExecutionResult result = runTasks('updateJenkinsItems')
TaskResults results = fails('updateJenkinsItems')

then:
result.failure
result.standardError.contains("Jenkins Service Call failed")
result.standardError.contains("Connection to http://localhost:${badPort} refused")
results.allFailed
results.output.contains("Jenkins Service Call failed")
results.output.contains("Connection to http://localhost:${badPort} refused")
}

def "provides sensible error when url path is wrong" () {
Expand All @@ -44,11 +42,11 @@ class JenkinsErrorHandlingIntegrationTest extends AbstractJenkinsIntegrationTest
"""

when:
ExecutionResult result = runTasks('updateJenkinsItems')
TaskResults results = fails('updateJenkinsItems')

then:
result.failure
result.standardError.contains("Jenkins Service Call failed")
result.standardError.contains("Not Found")
results.allFailed
results.output.contains("Jenkins Service Call failed")
results.output.contains("Not Found")
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.terrafolio.gradle.plugins.jenkins.integTest

import nebula.test.functional.ExecutionResult

class JenkinsJobIntegrationTest extends AbstractJenkinsIntegrationTest {
def setup() {
buildFile << """
Expand All @@ -17,56 +15,56 @@ class JenkinsJobIntegrationTest extends AbstractJenkinsIntegrationTest {

def "can create/dump/validate/delete job in jenkins" () {
when:
ExecutionResult result = runTasks('updateJenkinsItems')
TaskResults results = succeeds('updateJenkinsItems')

then:
result.success
result.standardOutput.contains("Creating new item test_job")
results.allSucceeded
results.output.contains("Creating new item test_job")

when:
result = runTasks('updateJenkinsItems')
results = succeeds('updateJenkinsItems')

then:
result.success
result.standardOutput.contains("Jenkins item test_job has no changes to the existing item")
results.allSucceeded
results.output.contains("Jenkins item test_job has no changes to the existing item")

when:
result = runTasks('dumpRemoteJenkinsItems')
results = succeeds('dumpRemoteJenkinsItems')

then:
result.success
results.allSucceeded
fileExists("build/remotes/${serverName}/jobs/test_job.xml")

when:
result = runTasks('validateJenkinsItems')
results = succeeds('validateJenkinsItems')

then:
result.success
results.allSucceeded

when:
result = runTasks('deleteJenkinsItems')
results = succeeds('deleteJenkinsItems')

then:
result.success
result.standardOutput.contains("Deleting item test_job")
results.allSucceeded
results.output.contains("Deleting item test_job")
}

def "can force update a job" () {
when:
ExecutionResult result = runTasks('updateJenkinsItems')
TaskResults results = succeeds('updateJenkinsItems')

then:
result.success
result.standardOutput.contains("Creating new item test_job")
results.allSucceeded
results.output.contains("Creating new item test_job")

when:
buildFile << """
project.ext.forceJenkinsJobsUpdate = 'true'
"""
result = runTasks('updateJenkinsItems')
results = succeeds('updateJenkinsItems')

then:
result.success
result.standardOutput.contains("Updating item test_job")
results.allSucceeded
results.output.contains("Updating item test_job")
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.terrafolio.gradle.plugins.jenkins.integTest

import nebula.test.functional.ExecutionResult

class JenkinsViewIntegrationTest extends AbstractJenkinsIntegrationTest {
def setup() {
buildFile << """
Expand Down Expand Up @@ -30,24 +28,24 @@ class JenkinsViewIntegrationTest extends AbstractJenkinsIntegrationTest {

def "can create/dump/delete view in jenkins" () {
when:
ExecutionResult result = runTasks('updateJenkinsItems')
TaskResults results = succeeds('updateJenkinsItems')

then:
result.success
result.standardOutput.contains("Creating new item test_view")
results.allSucceeded
results.output.contains("Creating new item test_view")

when:
result = runTasks('dumpRemoteJenkinsItems')
results = succeeds('dumpRemoteJenkinsItems')

then:
result.success
results.allSucceeded
fileExists("build/remotes/${serverName}/views/test_view.xml")

when:
result = runTasks('deleteJenkinsItems')
results = succeeds('deleteJenkinsItems')

then:
result.success
result.standardOutput.contains("Deleting item test_view")
results.allSucceeded
results.output.contains("Deleting item test_view")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.terrafolio.gradle.plugins.jenkins.integTest

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome

class TaskResults {
final BuildResult result

TaskResults(BuildResult result) {
this.result = result
}

public boolean isAllSucceeded() {
return result.tasks.every { task -> task.outcome == TaskOutcome.SUCCESS }
}

public boolean isAllFailed() {
return result.tasks.every { task -> task.outcome == TaskOutcome.FAILED }
}

public getOutput() {
return result.output
}
}

0 comments on commit 2a841b1

Please sign in to comment.