Move integration tests into a separate task and start using GradleTestKit

This commit introduces a failing integration test, that's expected
This commit is contained in:
R. Tyler Croy 2015-08-11 08:27:25 -07:00
parent 43b07fc936
commit 988888d068
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
6 changed files with 192 additions and 89 deletions

View File

@ -13,11 +13,11 @@ buildscript {
}
}
apply plugin: 'com.jfrog.bintray'
apply plugin: 'org.ysb33r.gradletest'
apply plugin: 'codenarc'
apply plugin: 'groovy'
apply plugin: 'maven'
apply from: 'gradle/integration-test.gradle'
apply from: 'gradle/releasing.gradle'
group = 'com.github.jruby-gradle'
version = '0.2.0'
@ -25,7 +25,6 @@ defaultTasks 'check', 'assemble'
repositories {
jcenter()
mavenLocal()
}
dependencies {
@ -57,42 +56,4 @@ test {
}
}
gradleTest {
versions '2.0', '2.2', '2.4', '2.6'
dependsOn jar
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
bintray {
user = project.bintrayUser
key = project.bintrayKey
publish = true
dryRun = false
configurations = ['archives']
pkg {
userOrg = 'jruby-gradle'
repo = 'plugins'
name = 'jruby-gradle-storm-plugin'
labels = ['jruby','storm','java']
version {
name = project.version
vcsTag = "v${project.version}"
attributes = ['gradle-plugin' : 'com.github.jruby-gradle.storm:com.github.jruby-gradle:jruby-gradle-storm-plugin']
desc = 'This plugin encapsulates Storm topology building functionality for JRuby Gradle projects'
}
}
}
bintrayUpload.dependsOn assemble
// vim: ft=groovy

View File

@ -0,0 +1,58 @@
import groovy.json.JsonOutput
apply plugin: 'org.ysb33r.gradletest'
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime, integrationTestCompile
}
sourceSets {
integrationTest {
groovy {
srcDir file("${projectDir}/src/integTest/groovy")
}
compileClasspath = sourceSets.main.output + configurations.integrationTestCompile
runtimeClasspath = output + compileClasspath + configurations.integrationTestRuntime
}
}
task prepareGradleTestKitClasspath {
group 'Build Setup'
description 'Prepare the plugin classpath until TestKit supports it more natively'
File outputDir = file("$buildDir/$name")
inputs.files sourceSets.main.runtimeClasspath
outputs.dir outputDir
doLast {
outputDir.mkdirs()
List<String> files = sourceSets.main.runtimeClasspath.files.collect { File f -> f.absolutePath }
file("$outputDir/plugin-classpath.json").text = JsonOutput.toJson(files)
}
}
task integrationTest(type: Test) {
group 'Verification'
description 'Run the TestKit-based integration tests'
dependsOn prepareGradleTestKitClasspath, test, jar
classpath = sourceSets.integrationTest.runtimeClasspath
testClassesDir = sourceSets.integrationTest.output.classesDir
testLogging {
showStandardStreams = true
exceptionFormat "full"
}
}
check.dependsOn integrationTest
gradleTest {
versions '2.0', '2.2', '2.4', '2.6'
dependsOn test, integrationTest, jar
}
dependencies {
integrationTestCompile gradleTestKit()
/* add our TestKit classpath to our test runtime so we can find it again */
integrationTestRuntime files(prepareGradleTestKitClasspath)
}

33
gradle/releasing.gradle Normal file
View File

@ -0,0 +1,33 @@
apply plugin: 'com.jfrog.bintray'
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
bintray {
user = project.bintrayUser
key = project.bintrayKey
publish = true
dryRun = false
configurations = ['archives']
pkg {
userOrg = 'jruby-gradle'
repo = 'plugins'
name = 'jruby-gradle-storm-plugin'
labels = ['jruby','storm','java']
version {
name = project.version
vcsTag = "v${project.version}"
attributes = ['gradle-plugin' : 'com.github.jruby-gradle.storm:com.github.jruby-gradle:jruby-gradle-storm-plugin']
desc = 'This plugin encapsulates Storm topology building functionality for JRuby Gradle projects'
}
}
}
bintrayUpload.dependsOn assemble

View File

@ -0,0 +1,99 @@
package com.github.jrubygradle.storm
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.BuildResult
import org.gradle.api.artifacts.Dependency
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.*
/**
* This integration test will stand up Gradle integration tests using
*/
class JRubyStormTaskIntegrationSpec extends Specification {
@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile
String pluginDependencies
def setup() {
buildFile = testProjectDir.newFile('build.gradle')
def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.json")
if (pluginClasspathResource == null) {
throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
}
pluginDependencies = pluginClasspathResource.text //(new JsonSlurper()).parseText(pluginClasspathResource.text)
}
def "evaluation of the project should result in an assemble and run task"() {
given:
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'com.github.jruby-gradle.storm'
when:
project.evaluate()
then:
project.tasks.findByName('assembleJRubyStorm')
project.tasks.findByName('runJRubyStorm')
}
def "evaluation of the project should result in dependencies being added to the configuration"() {
given:
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'com.github.jruby-gradle.storm'
JRubyStorm task = project.task('spock', type: JRubyStorm)
def deps = task.configuration.dependencies
when:
project.evaluate()
then:
deps.matching { Dependency d -> d.name == 'redstorm' }
}
def "evaluation of the project should result in local mode dependencies"() {
given:
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'com.github.jruby-gradle.storm'
JRubyStorm task = project.task('spock', type: JRubyStorm)
when:
project.evaluate()
then:
project.configurations.findByName('jrubyStormLocal')?.dependencies?.matching {
it.name == 'storm-core'
}
}
def "executing the assemble task produces a jar artifact"() {
given:
buildFile << """
buildscript {
dependencies {
classpath files(${pluginDependencies})
}
}
apply plugin: 'com.github.jruby-gradle.storm'
jrubyStorm {
}
"""
when:
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('assembleJRubyStorm')
.build()
then:
File[] artifacts = (new File(testProjectDir.root, ['build', 'libs'].join(File.separator))).listFiles()
artifacts && artifacts.size() == 1
result.task(":assembleJRubyStorm").outcome == TaskOutcome.SUCCESS
}
}

View File

@ -1,6 +1,5 @@
package com.github.jrubygradle.storm
import org.gradle.api.artifacts.Dependency
import spock.lang.*
import org.gradle.api.Project
@ -104,32 +103,6 @@ class JRubyStormSpec extends Specification {
project.task('spock', type: JRubyStorm)
then:
println project.configurations
project.configurations.findByName(JRubyStorm.DEFAULT_CONFIGURATION_NAME)
}
def "evaluation of the project should result in dependencies being added to the configuration"() {
given:
JRubyStorm task = project.task('spock', type: JRubyStorm)
def deps = task.configuration.dependencies
when:
project.evaluate()
then:
deps.matching { Dependency d -> d.name == 'redstorm' }
}
def "evaluation of the project should result in local mode dependencies"() {
given:
JRubyStorm task = project.task('spock', type: JRubyStorm)
when:
project.evaluate()
then:
project.configurations.findByName('jrubyStormLocal')?.dependencies?.matching {
it.name == 'storm-core'
}
}
}

View File

@ -1,21 +0,0 @@
package com.github.jrubygradle.storm
import spock.lang.*
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
class JRubyStormTaskIntegrationSpec extends Specification {
protected Project project
void setup() {
project = ProjectBuilder.builder().build()
project.apply plugin: 'com.github.jruby-gradle.storm'
}
@Ignore('not clear if this is the right direction')
def "project should have a default jrubyStorm task"() {
expect:
project.tasks.findByName('jrubyStorm')
}
}