|
| 1 | +plugins { |
| 2 | + id("otel.javaagent-testing") |
| 3 | +} |
| 4 | + |
| 5 | +val testServer by configurations.creating |
| 6 | +val appLibrary by configurations.creating |
| 7 | + |
| 8 | +configurations.named("testCompileOnly") { |
| 9 | + extendsFrom(appLibrary) |
| 10 | +} |
| 11 | + |
| 12 | +dependencies { |
| 13 | + appLibrary("org.springframework:spring-webmvc:3.1.0.RELEASE") |
| 14 | + testImplementation("javax.servlet:javax.servlet-api:3.1.0") |
| 15 | + |
| 16 | + val arquillianVersion = "1.4.0.Final" |
| 17 | + testImplementation("org.jboss.arquillian.junit:arquillian-junit-container:${arquillianVersion}") |
| 18 | + testImplementation("org.jboss.arquillian.protocol:arquillian-protocol-servlet:${arquillianVersion}") |
| 19 | + testImplementation("org.jboss.arquillian.spock:arquillian-spock-container:1.0.0.CR1") |
| 20 | + testImplementation("org.jboss.shrinkwrap:shrinkwrap-impl-base:1.2.6") |
| 21 | + |
| 22 | + testRuntimeOnly("org.wildfly.arquillian:wildfly-arquillian-container-embedded:2.2.0.Final") |
| 23 | + |
| 24 | + testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent")) |
| 25 | + testInstrumentation(project(":instrumentation:spring:spring-webmvc-3.1:javaagent")) |
| 26 | + testInstrumentation(project(":instrumentation:spring:spring-web-3.1:javaagent")) |
| 27 | + |
| 28 | + // wildfly version used to run tests |
| 29 | + testServer("org.wildfly:wildfly-dist:18.0.0.Final@zip") |
| 30 | +} |
| 31 | + |
| 32 | +tasks { |
| 33 | + // extract wildfly dist, path is used from arquillian.xml |
| 34 | + val setupServer by registering(Copy::class) { |
| 35 | + from(zipTree(testServer.singleFile)) |
| 36 | + into(file("build/server/")) |
| 37 | + } |
| 38 | + |
| 39 | + // logback-classic contains /META-INF/services/javax.servlet.ServletContainerInitializer |
| 40 | + // that breaks deploy on embedded wildfly |
| 41 | + // create a copy of logback-classic jar that does not have this file |
| 42 | + val modifyLogbackJar by registering(Jar::class) { |
| 43 | + destinationDirectory.set(file("$buildDir/tmp")) |
| 44 | + archiveFileName.set("logback-classic-modified.jar") |
| 45 | + exclude("/META-INF/services/javax.servlet.ServletContainerInitializer") |
| 46 | + doFirst { |
| 47 | + configurations.configureEach { |
| 48 | + if (name.toLowerCase().endsWith("testruntimeclasspath")) { |
| 49 | + val logbackJar = find { it.name.contains("logback-classic") } |
| 50 | + from(zipTree(logbackJar)) |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + val copyDependencies by registering(Copy::class) { |
| 57 | + // test looks for spring jars that are bundled inside deployed application from this directory |
| 58 | + from(appLibrary).into("$buildDir/app-libs") |
| 59 | + } |
| 60 | + |
| 61 | + named<Test>("test") { |
| 62 | + dependsOn(modifyLogbackJar) |
| 63 | + dependsOn(setupServer) |
| 64 | + dependsOn(copyDependencies) |
| 65 | + |
| 66 | + doFirst { |
| 67 | + // --add-modules is unrecognized on jdk8, ignore it instead of failing |
| 68 | + jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") |
| 69 | + // needed for java 11 to avoid org.jboss.modules.ModuleNotFoundException: java.se |
| 70 | + jvmArgs("--add-modules=java.se") |
| 71 | + // add offset to default port values |
| 72 | + jvmArgs("-Djboss.socket.binding.port-offset=300") |
| 73 | + |
| 74 | + // remove logback-classic from classpath |
| 75 | + classpath = classpath.filter { |
| 76 | + !it.absolutePath.contains("logback-classic") |
| 77 | + } |
| 78 | + // add modified copy of logback-classic to classpath |
| 79 | + classpath = classpath.plus(files("$buildDir/tmp/logback-classic-modified.jar")) |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments