From 988888d068286de2f3f33b63cc6771aaa087be50 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Tue, 11 Aug 2015 08:27:25 -0700 Subject: [PATCH] Move integration tests into a separate task and start using GradleTestKit This commit introduces a failing integration test, that's expected --- build.gradle | 43 +------- gradle/integration-test.gradle | 58 +++++++++++ gradle/releasing.gradle | 33 +++++++ .../JRubyStormTaskIntegrationSpec.groovy | 99 +++++++++++++++++++ .../jrubygradle/storm/JRubyStormSpec.groovy | 27 ----- .../JRubyStormTaskIntegrationSpec.groovy | 21 ---- 6 files changed, 192 insertions(+), 89 deletions(-) create mode 100644 gradle/integration-test.gradle create mode 100644 gradle/releasing.gradle create mode 100644 src/integTest/groovy/com/github/jrubygradle/storm/JRubyStormTaskIntegrationSpec.groovy delete mode 100644 src/test/groovy/com/github/jrubygradle/storm/JRubyStormTaskIntegrationSpec.groovy diff --git a/build.gradle b/build.gradle index 4e97e11..006c9cc 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/gradle/integration-test.gradle b/gradle/integration-test.gradle new file mode 100644 index 0000000..580e0ab --- /dev/null +++ b/gradle/integration-test.gradle @@ -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 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) +} diff --git a/gradle/releasing.gradle b/gradle/releasing.gradle new file mode 100644 index 0000000..95c2955 --- /dev/null +++ b/gradle/releasing.gradle @@ -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 diff --git a/src/integTest/groovy/com/github/jrubygradle/storm/JRubyStormTaskIntegrationSpec.groovy b/src/integTest/groovy/com/github/jrubygradle/storm/JRubyStormTaskIntegrationSpec.groovy new file mode 100644 index 0000000..91a6236 --- /dev/null +++ b/src/integTest/groovy/com/github/jrubygradle/storm/JRubyStormTaskIntegrationSpec.groovy @@ -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 + } +} \ No newline at end of file diff --git a/src/test/groovy/com/github/jrubygradle/storm/JRubyStormSpec.groovy b/src/test/groovy/com/github/jrubygradle/storm/JRubyStormSpec.groovy index a92b963..5fbf801 100644 --- a/src/test/groovy/com/github/jrubygradle/storm/JRubyStormSpec.groovy +++ b/src/test/groovy/com/github/jrubygradle/storm/JRubyStormSpec.groovy @@ -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' - } - } } diff --git a/src/test/groovy/com/github/jrubygradle/storm/JRubyStormTaskIntegrationSpec.groovy b/src/test/groovy/com/github/jrubygradle/storm/JRubyStormTaskIntegrationSpec.groovy deleted file mode 100644 index 7df9c4d..0000000 --- a/src/test/groovy/com/github/jrubygradle/storm/JRubyStormTaskIntegrationSpec.groovy +++ /dev/null @@ -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') - } -}