I'm writing integration tests for my first Gradle plugin using nebula-test.
I'm now working on a test that requires copying one or more files from my "resources" into the temp project directory. The "copyResources()" call is failing because it says the "from" directory is not in the classpath.
Specifically, it fails with this:
java.lang.RuntimeException: Could not find classpath resource: src/integTest/resources
at nebula.test.IntegrationSpec.copyResources(IntegrationSpec.groovy:189)
at com.att.opnfv.yang.gradle.YangPluginIntegSpec.process Yang module with simple type reference and imported file for type(YangPluginIntegSpec.groovy:227)
Here's the relevant pieces of my "build.gradle" file:
buildscript {
repositories {
jcenter()
mavenCentral()
}
}
apply plugin: 'groovy'
apply plugin: 'java-gradle-plugin'
apply plugin: 'maven'
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.codehaus.groovy:groovy-all:2.3.9"
compile gradleApi()
compile "commons-io:commons-io:2.4"
testCompile("org.spockframework:spock-core:1.0-groovy-2.3") {
exclude group: "org.codehaus.groovy"
}
}
sourceCompatibility = 1.7
group = 'com.att.opnfv.yang'
version = '1.0.0-SNAPSHOT'
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
}
}
sourceSets {
integTest {
groovy.srcDir file("src/integTest/groovy")
resources.srcDir file("src/integTest/resources")
runtimeClasspath = output + compileClasspath // I thought this would do it
}
}
dependencies {
integTestCompile sourceSets.main.output
integTestCompile configurations.testCompile
integTestCompile sourceSets.test.output
integTestRuntime configurations.testRuntime
testCompile( 'com.netflix.nebula:nebula-test:2.2.1' ) {
exclude module: 'groovy-all'
}
}
task integTest(type: Test) {
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath
outputs.upToDateWhen { false }
}
check.dependsOn -= integTest
And here's my Spec method that has the "copyResources()" call:
def 'process Yang module with simple type reference and imported file for type'() {
when:
directory("src/main/yang")
File yangFile = createFile("src/main/yang/base.yang")
yangFile << '''
module base {
namespace "base";
prefix base;
import ietf-inet-types {prefix inet; revision-date "2010-09-24";}
grouping "group" {
leaf ip-base {
type inet:ip-version;
}
}
}
'''.stripIndent()
directory("yangImports")
copyResources("src/integTest/resources", "yangImports") // line 227
buildFile << applyPlugin(YangPlugin)
buildFile << """
configurations {
yangImports
}
dependencies {
yangImports fileTree(dir: "yangImports", include: "*.yang")
}
yang {
yangFilesConfiguration "yangImports"
inspectDependencies true
yangFilesRootDir 'src/main/yang'
generator {
generatorClassName = 'com.att.opnfv.yang.generator.MockCodeGenerator'
outputDir = 'build/gen'
}
}
""".stripIndent()
ExecutionResult result = runTasksWithFailure('build')
then:
!result.wasUpToDate("yangGenerate")
result.standardError.contains("Imported module ietf-inet-types not found")
}
What am I missing?
Update:
I was confused about the relationship between the configuration classpath and the path referenced in "copyResources". I created "src/integTest/resources/yang", copied the one file into that new folder, then changed the reference to:
copyResources("yang", "yangImports")
and that worked, or at least it got past that problem just so I could hit my next hurdle, but that's not a Gradle/nebula-test problem.
My mistake was referencing "src/integTest/resources" in the "copyResources" call. That folder is already in the classpath. What I needed to reference was the folder INSIDE of "src/integTest/resources". Once I did that, it worked fine.