Skip to content

Commit 0459612

Browse files
authored
build: gradle plugin download sdl / introspection integration tests (ExpediaGroup#1656)
### 📝 Description Migrate download sdl task and introspection task integration tests to a composite build. Failure scenarios (i.e. timeout) is still run through `GradleRunner` in the plugin project. ### 🔗 Related Issues
1 parent ae9b7e9 commit 0459612

File tree

15 files changed

+2261
-227
lines changed

15 files changed

+2261
-227
lines changed

integration/gradle-plugin-integration-tests/build.gradle.kts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
import java.util.Properties
2+
import com.github.tomakehurst.wiremock.standalone.WireMockServerRunner
3+
import java.net.ServerSocket
4+
5+
buildscript {
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
classpath(libs.wiremock.standalone)
12+
}
13+
}
214

315
allprojects {
416
repositories {
@@ -19,5 +31,71 @@ allprojects {
1931
}
2032
}
2133

34+
open class WireMockIntegrationExtension {
35+
var wireMockServer: WireMockServerRunner? = null
36+
var port: Int? = null
37+
}
38+
39+
val extension: WireMockIntegrationExtension = project.extensions.create("WireMockIntegrationExtension", WireMockIntegrationExtension::class.java)
40+
project.extensions.configure(WireMockIntegrationExtension::class.java) {
41+
val serverSocket = ServerSocket(0)
42+
port = serverSocket.localPort
43+
serverSocket.close()
44+
}
45+
46+
tasks {
47+
// workaround to be able to build clients without running server
48+
val startWireMock by register("startWireMock") {
49+
finalizedBy("stopWireMock")
50+
51+
doLast {
52+
val wireMockConfig = arrayOf(
53+
"--root-dir=${project.projectDir}/src/integration/wiremock",
54+
"--port=${extension.port}"
55+
)
56+
val server = WireMockServerRunner()
57+
server.run(*wireMockConfig)
58+
59+
extension.wireMockServer = server
60+
logger.info("wiremock started at port ${extension.port}")
61+
}
62+
}
63+
val stopWireMock by register("stopWireMock") {
64+
mustRunAfter("startWireMock")
65+
66+
doLast {
67+
val server = extension.wireMockServer
68+
if (server?.isRunning == true) {
69+
logger.info("attempting to stop wiremock server")
70+
server.stop()
71+
logger.info("wiremock server stopped")
72+
}
73+
}
74+
}
75+
}
76+
77+
for (projectName in listOf(":download-sdl-groovy-it", ":download-sdl-kotlin-it")) {
78+
project("$projectName") {
79+
ext.set("wireMockServerPort", extension.port)
2280

81+
project.afterEvaluate {
82+
tasks.getByName("graphqlDownloadSDL") {
83+
dependsOn(":startWireMock")
84+
finalizedBy(":stopWireMock")
85+
}
86+
}
87+
}
88+
}
2389

90+
for (projectName in listOf(":introspection-groovy-it", ":introspection-kotlin-it")) {
91+
project("$projectName") {
92+
ext.set("wireMockServerPort", extension.port)
93+
94+
project.afterEvaluate {
95+
tasks.getByName("graphqlIntrospectSchema") {
96+
dependsOn(":startWireMock")
97+
finalizedBy(":stopWireMock")
98+
}
99+
}
100+
}
101+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
plugins {
2+
id 'com.expediagroup.graphql'
3+
alias(libs.plugins.kotlin.jvm)
4+
}
5+
6+
dependencies {
7+
implementation "com.expediagroup:graphql-kotlin-spring-client"
8+
implementation(libs.kotlin.stdlib)
9+
}
10+
11+
String wireMockPort = ext.wireMockServerPort
12+
graphqlDownloadSDL {
13+
endpoint = "http://localhost:${wireMockPort}/sdl"
14+
headers["X-Custom-Header"] = "My-Custom-Header-Value"
15+
}
16+
17+
// simple test to verify file was downloaded
18+
tasks.named("test", Test) {
19+
dependsOn("graphqlDownloadSDL")
20+
21+
doLast {
22+
if (!new File(project.buildDir, "schema.graphql").exists()) {
23+
throw new RuntimeException("failed to download schema.graphql file")
24+
}
25+
}
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLDownloadSDLTask
2+
3+
@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove once KTIJ-19369 / Gradle#22797 is fixed
4+
plugins {
5+
alias(libs.plugins.kotlin.jvm)
6+
id("com.expediagroup.graphql")
7+
}
8+
9+
dependencies {
10+
implementation("com.expediagroup:graphql-kotlin-spring-client")
11+
implementation(libs.kotlin.stdlib)
12+
}
13+
14+
val wireMockServerPort: Int? = ext.get("wireMockServerPort") as? Int
15+
val graphqlDownloadSDL by tasks.getting(GraphQLDownloadSDLTask::class) {
16+
endpoint.set("http://localhost:$wireMockServerPort/sdl")
17+
headers.put("X-Custom-Header", "My-Custom-Header-Value")
18+
}
19+
20+
tasks {
21+
named<Test>("test") {
22+
dependsOn("graphqlDownloadSDL")
23+
24+
doLast {
25+
if (!File(project.buildDir, "schema.graphql").exists()) {
26+
throw RuntimeException("failed to download schema.graphql file")
27+
}
28+
}
29+
}
30+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
group = com.expediagroup.plugin.integration
22

33
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g
4+
org.gradle.caching=true
5+
org.gradle.parallel=true
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
plugins {
2+
id 'com.expediagroup.graphql'
3+
alias(libs.plugins.kotlin.jvm)
4+
}
5+
6+
dependencies {
7+
implementation "com.expediagroup:graphql-kotlin-spring-client"
8+
implementation(libs.kotlin.stdlib)
9+
}
10+
11+
String wireMockPort = ext.wireMockServerPort
12+
graphqlIntrospectSchema {
13+
endpoint = "http://localhost:${wireMockPort}/graphql"
14+
headers["X-Custom-Header"] = "My-Custom-Header-Value"
15+
}
16+
17+
// simple test to verify file was downloaded
18+
tasks.named("test", Test) {
19+
dependsOn("graphqlIntrospectSchema")
20+
21+
doLast {
22+
if (!new File(project.buildDir, "schema.graphql").exists()) {
23+
throw new RuntimeException("failed to download schema.graphql file")
24+
}
25+
}
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLIntrospectSchemaTask
2+
3+
@Suppress("DSL_SCOPE_VIOLATION") // TODO: re
4+
plugins {
5+
alias(libs.plugins.kotlin.jvm)
6+
id("com.expediagroup.graphql")
7+
}
8+
9+
dependencies {
10+
implementation("com.expediagroup:graphql-kotlin-spring-client")
11+
implementation(libs.kotlin.stdlib)
12+
}
13+
14+
val wireMockServerPort: Int? = ext.get("wireMockServerPort") as? Int
15+
val graphqlIntrospectSchema by tasks.getting(GraphQLIntrospectSchemaTask::class) {
16+
endpoint.set("http://localhost:$wireMockServerPort/graphql")
17+
headers.put("X-Custom-Header", "My-Custom-Header-Value")
18+
}
19+
20+
tasks {
21+
named<Test>("test") {
22+
dependsOn("graphqlIntrospectSchema")
23+
24+
doLast {
25+
if (!File(project.buildDir, "schema.graphql").exists()) {
26+
throw RuntimeException("failed to introspect the schema and generate schema.graphql file")
27+
}
28+
}
29+
}
30+
}

integration/gradle-plugin-integration-tests/settings.gradle.kts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,33 @@ dependencyResolutionManagement {
1111
// composite graphql-kotlin library build
1212
includeBuild("../..")
1313

14+
// client generator integration tests
1415
include(":client-custom-scalars-jackson-it")
1516
include(":client-custom-scalars-kotlinx-it")
1617
include(":client-jacoco-it")
1718
include(":client-polymorphic-types-jackson-it")
1819
include(":client-polymorphic-types-kotlinx-it")
1920
include(":client-skip-include-it")
2021

21-
// remap directories to projects
2222
project(":client-custom-scalars-jackson-it").projectDir = file("client-generator/custom-scalars-jackson")
2323
project(":client-custom-scalars-kotlinx-it").projectDir = file("client-generator/custom-scalars-kotlinx")
2424
project(":client-jacoco-it").projectDir = file("client-generator/jacoco")
2525
project(":client-polymorphic-types-jackson-it").projectDir = file("client-generator/polymorphic-types-jackson")
2626
project(":client-polymorphic-types-kotlinx-it").projectDir = file("client-generator/polymorphic-types-kotlinx")
2727
project(":client-skip-include-it").projectDir = file("client-generator/skip-include")
2828

29+
// download sdl task integration tests
30+
include(":download-sdl-kotlin-it")
31+
include(":download-sdl-groovy-it")
32+
33+
project(":download-sdl-kotlin-it").projectDir = file("download-sdl/kotlin")
34+
project(":download-sdl-groovy-it").projectDir = file("download-sdl/groovy")
35+
36+
// introspect schema task integration tests
37+
include(":introspection-kotlin-it")
38+
include(":introspection-groovy-it")
39+
40+
project(":introspection-kotlin-it").projectDir = file("introspection/kotlin")
41+
project(":introspection-groovy-it").projectDir = file("introspection/groovy")
42+
2943
// sdl generator integration tests
30-
// TODO

0 commit comments

Comments
 (0)