Skip to content

Commit 00b1731

Browse files
authored
build: migrate remaining gradle plugin integration tests (ExpediaGroup#1658)
### 📝 Description Migrate last remaining Gradle integration tests to a composite build. ### 🔗 Related Issues * ExpediaGroup#1654 * ExpediaGroup#1656 * ExpediaGroup#1657
1 parent 6c54938 commit 00b1731

File tree

80 files changed

+1541
-2352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1541
-2352
lines changed

gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ icu = "71.1"
3030
junit = "5.8.2"
3131
logback = "1.2.1"
3232
mockk = "1.12.5"
33-
mustache = "0.9.10"
3433
rxjava = "3.1.5"
3534
wiremock = "2.33.2"
3635

@@ -97,7 +96,6 @@ ktor-server-cio = { group = "io.ktor", name = "ktor-server-cio", version.ref = "
9796
ktor-server-netty = { group = "io.ktor", name = "ktor-server-netty", version.ref = "ktor" }
9897
ktor-server-test-host = { group = "io.ktor", name = "ktor-server-test-host", version.ref = "ktor" }
9998
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
100-
mustache = { group = "com.github.spullara.mustache.java", name = "compiler", version.ref = "mustache" }
10199
reactor-core = { group = "io.projectreactor", name = "reactor-core", version.ref = "reactor-core" }
102100
reactor-extensions = { group = "io.projectreactor.kotlin", name = "reactor-kotlin-extensions", version.ref = "reactor-extensions" }
103101
reactor-test = { group = "io.projectreactor", name = "reactor-test", version.ref = "reactor-core" }

integration/gradle-plugin-integration-tests/client-generator/custom-scalars-kotlinx/src/main/kotlin/com/expediagroup/scalars/KtorGraphQLServer.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.expediagroup.scalars
22

33
import com.expediagroup.graphql.generator.SchemaGeneratorConfig
44
import com.expediagroup.graphql.generator.TopLevelObject
5-
import com.expediagroup.graphql.generator.scalars.ID
65
import com.expediagroup.graphql.generator.scalars.IDValueUnboxer
76
import com.expediagroup.graphql.generator.toSchema
87
import com.expediagroup.graphql.server.execution.GraphQLContextFactory
@@ -13,8 +12,6 @@ import com.expediagroup.graphql.server.types.GraphQLServerRequest
1312
import com.expediagroup.scalars.queries.ScalarQuery
1413
import com.fasterxml.jackson.databind.ObjectMapper
1514
import graphql.GraphQL
16-
import graphql.execution.DefaultValueUnboxer
17-
import graphql.execution.ValueUnboxer
1815
import io.ktor.server.request.ApplicationRequest
1916
import io.ktor.server.request.receiveText
2017
import java.io.IOException

integration/gradle-plugin-integration-tests/client-generator/custom-scalars-kotlinx/src/test/kotlin/com/expediagroup/scalars/CustomScalarKotlinxTests.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ class CustomScalarKotlinxTests {
3131

3232
@Test
3333
fun `verify custom scalars are correctly serialized and deserialized`() {
34-
val engine = embeddedServer(CIO, port = 8080, module = Application::graphQLModule)
34+
val engine = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
3535
try {
3636
engine.start()
3737
runBlocking {
38-
val client = GraphQLKtorClient(url = URL("http://localhost:8080/graphql"))
38+
val port = engine.resolvedConnectors().first().port
39+
val client = GraphQLKtorClient(url = URL("http://localhost:$port/graphql"))
3940

4041
val undefinedLocaleQuery = LocaleQuery(variables = LocaleQuery.Variables())
4142
val undefinedLocaleResult = client.execute(undefinedLocaleQuery)
@@ -56,11 +57,12 @@ class CustomScalarKotlinxTests {
5657

5758
@Test
5859
fun `verify undefined optionals are correctly serialized and deserialized`() {
59-
val engine = embeddedServer(CIO, port = 8080, module = Application::graphQLModule)
60+
val engine = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
6061
try {
6162
engine.start()
6263
runBlocking {
63-
val client = GraphQLKtorClient(url = URL("http://localhost:8080/graphql"))
64+
val port = engine.resolvedConnectors().first().port
65+
val client = GraphQLKtorClient(url = URL("http://localhost:$port/graphql"))
6466

6567
val undefinedWrapperQuery = OptionalScalarQuery(variables = OptionalScalarQuery.Variables())
6668
val undefinedWrapperResult = client.execute(undefinedWrapperQuery).data?.optionalScalarQuery
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLSerializer
2+
3+
plugins {
4+
id 'com.expediagroup.graphql'
5+
alias(libs.plugins.kotlin.jvm)
6+
}
7+
8+
dependencies {
9+
implementation "com.expediagroup:graphql-kotlin-spring-client"
10+
implementation(libs.kotlin.stdlib)
11+
}
12+
13+
graphql {
14+
client {
15+
schemaFile = file("${project.projectDir}/schema.graphql")
16+
packageName = "com.expediagroup.generated"
17+
// optional configuration
18+
allowDeprecatedFields = true
19+
headers = ["X-Custom-Header": "My-Custom-Header-Value"]
20+
queryFiles = [
21+
file("${project.projectDir}/src/main/resources/queries/HelloWorldQuery.graphql"),
22+
file("${project.projectDir}/src/main/resources/queries/UpdateNameMutation.graphql")
23+
]
24+
serializer = GraphQLSerializer.JACKSON
25+
timeout { t ->
26+
t.connect = 10000
27+
t.read = 30000
28+
}
29+
}
30+
}
31+
32+
tasks.named("test", Test) {
33+
dependsOn("graphqlGenerateClient")
34+
35+
doLast {
36+
// verify files were generated
37+
if (!new File(project.buildDir, "generated/source/graphql/main/com/expediagroup/generated/HelloWorldQuery.kt").exists()) {
38+
throw new RuntimeException("failed to generate client for HelloWorldQuery")
39+
}
40+
if (!new File(project.buildDir, "generated/source/graphql/main/com/expediagroup/generated/UpdateNameMutation.kt").exists()) {
41+
throw new RuntimeException("failed to generate client for UpdateNameMutation")
42+
}
43+
}
44+
}
45+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type Query {
2+
helloWorld(name: String): String! @deprecated(reason: "this is a test schema")
3+
}
4+
5+
type Mutation {
6+
updateName(name: String!): String!
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query HelloWorldQuery {
2+
helloWorld
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mutation UpdateNameMutation($name: String!) {
2+
updateName(name: $name)
3+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLSerializer
2+
3+
plugins {
4+
id 'com.expediagroup.graphql'
5+
alias(libs.plugins.kotlin.jvm)
6+
}
7+
8+
dependencies {
9+
implementation "com.expediagroup:graphql-kotlin-spring-client"
10+
implementation(libs.kotlin.stdlib)
11+
}
12+
13+
graphqlGenerateClient {
14+
packageName = "com.expediagroup.generated"
15+
schemaFile = file("${project.projectDir}/schema.graphql")
16+
// optional config
17+
allowDeprecatedFields = true
18+
serializer = GraphQLSerializer.JACKSON
19+
queryFiles.from("${project.projectDir}/src/main/resources/queries/HelloWorldQuery.graphql",
20+
"${project.projectDir}/src/main/resources/queries/UpdateNameMutation.graphql")
21+
}
22+
23+
tasks.named("test", Test) {
24+
dependsOn("graphqlGenerateClient")
25+
26+
doLast {
27+
// verify files were generated
28+
if (!new File(project.buildDir, "generated/source/graphql/main/com/expediagroup/generated/HelloWorldQuery.kt").exists()) {
29+
throw new RuntimeException("failed to generate client for HelloWorldQuery")
30+
}
31+
if (!new File(project.buildDir, "generated/source/graphql/main/com/expediagroup/generated/UpdateNameMutation.kt").exists()) {
32+
throw new RuntimeException("failed to generate client for UpdateNameMutation")
33+
}
34+
}
35+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type Query {
2+
helloWorld(name: String): String! @deprecated(reason: "this is a test schema")
3+
}
4+
5+
type Mutation {
6+
updateName(name: String!): String!
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query HelloWorldQuery {
2+
helloWorld
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mutation UpdateNameMutation($name: String!) {
2+
updateName(name: $name)
3+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLSerializer
2+
import com.expediagroup.graphql.plugin.gradle.graphql
3+
4+
@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove once KTIJ-19369 / Gradle#22797 is fixed
5+
plugins {
6+
id("com.expediagroup.graphql")
7+
alias(libs.plugins.kotlin.jvm)
8+
}
9+
10+
dependencies {
11+
implementation("com.expediagroup:graphql-kotlin-spring-client")
12+
implementation(libs.kotlin.stdlib)
13+
}
14+
15+
graphql {
16+
client {
17+
schemaFile = file("${project.projectDir}/schema.graphql")
18+
packageName = "com.expediagroup.generated"
19+
// optional
20+
allowDeprecatedFields = true
21+
headers = mapOf("X-Custom-Header" to "My-Custom-Header-Value")
22+
queryFiles = listOf(
23+
file("${project.projectDir}/src/main/resources/queries/HelloWorldQuery.graphql"),
24+
file("${project.projectDir}/src/main/resources/queries/UpdateNameMutation.graphql")
25+
)
26+
}
27+
}
28+
29+
tasks {
30+
named<Test>("test") {
31+
dependsOn("graphqlGenerateClient")
32+
33+
doLast {
34+
// verify files were generated
35+
if (!File(project.buildDir, "generated/source/graphql/main/com/expediagroup/generated/HelloWorldQuery.kt").exists()) {
36+
throw RuntimeException("failed to generate client for HelloWorldQuery")
37+
}
38+
if (!File(project.buildDir, "generated/source/graphql/main/com/expediagroup/generated/UpdateNameMutation.kt").exists()) {
39+
throw RuntimeException("failed to generate client for UpdateNameMutation")
40+
}
41+
}
42+
}
43+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type Query {
2+
helloWorld(name: String): String! @deprecated(reason: "this is a test schema")
3+
}
4+
5+
type Mutation {
6+
updateName(name: String!): String!
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query HelloWorldQuery {
2+
helloWorld
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mutation UpdateNameMutation($name: String!) {
2+
updateName(name: $name)
3+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLSerializer
2+
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLGenerateClientTask
3+
4+
@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove once KTIJ-19369 / Gradle#22797 is fixed
5+
plugins {
6+
id("com.expediagroup.graphql")
7+
alias(libs.plugins.kotlin.jvm)
8+
}
9+
10+
dependencies {
11+
implementation("com.expediagroup:graphql-kotlin-spring-client")
12+
implementation(libs.kotlin.stdlib)
13+
}
14+
15+
val graphqlGenerateClient by tasks.getting(GraphQLGenerateClientTask::class) {
16+
packageName.set("com.example.generated")
17+
schemaFile.set(file("${project.projectDir}/schema.graphql"))
18+
// optional config
19+
allowDeprecatedFields.set(true)
20+
queryFiles.from(
21+
"${project.projectDir}/src/main/resources/queries/HelloWorldQuery.graphql",
22+
"${project.projectDir}/src/main/resources/queries/UpdateNameMutation.graphql"
23+
)
24+
}
25+
26+
tasks {
27+
named<Test>("test") {
28+
dependsOn("graphqlGenerateClient")
29+
30+
doLast {
31+
// verify files were generated
32+
if (!File(project.buildDir, "generated/source/graphql/main/com/expediagroup/generated/HelloWorldQuery.kt").exists()) {
33+
throw RuntimeException("failed to generate client for HelloWorldQuery")
34+
}
35+
if (!File(project.buildDir, "generated/source/graphql/main/com/expediagroup/generated/UpdateNameMutation.kt").exists()) {
36+
throw RuntimeException("failed to generate client for UpdateNameMutation")
37+
}
38+
}
39+
}
40+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type Query {
2+
helloWorld(name: String): String! @deprecated(reason: "this is a test schema")
3+
}
4+
5+
type Mutation {
6+
updateName(name: String!): String!
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query HelloWorldQuery {
2+
helloWorld
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mutation UpdateNameMutation($name: String!) {
2+
updateName(name: $name)
3+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLSerializer
2+
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLGenerateSDLTask
3+
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLGenerateTestClientTask
4+
5+
@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove once KTIJ-19369 / Gradle#22797 is fixed
6+
plugins {
7+
id("com.expediagroup.graphql")
8+
alias(libs.plugins.kotlin.jvm)
9+
application
10+
}
11+
12+
dependencies {
13+
implementation("com.expediagroup", "graphql-kotlin-ktor-client") {
14+
exclude("com.expediagroup", "graphql-kotlin-client-serialization")
15+
}
16+
implementation("com.expediagroup", "graphql-kotlin-client-jackson")
17+
implementation("com.expediagroup:graphql-kotlin-server")
18+
implementation(libs.icu)
19+
implementation(libs.ktor.server.core)
20+
implementation(libs.ktor.server.cio)
21+
implementation(libs.ktor.server.netty)
22+
implementation(libs.logback)
23+
testImplementation(libs.junit.api)
24+
testImplementation(libs.junit.engine)
25+
testImplementation(libs.kotlin.junit.test)
26+
testImplementation(libs.ktor.server.test.host)
27+
}
28+
29+
val graphqlGenerateSDL by tasks.getting(GraphQLGenerateSDLTask::class) {
30+
packages.set(listOf("com.expediagroup.ktor.jackson"))
31+
}
32+
val graphqlGenerateTestClient by tasks.getting(GraphQLGenerateTestClientTask::class) {
33+
packageName.set("com.expediagroup.generated")
34+
schemaFile.set(graphqlGenerateSDL.schemaFile)
35+
serializer.set(GraphQLSerializer.JACKSON)
36+
useOptionalInputWrapper.set(true)
37+
}
38+
39+
tasks {
40+
test {
41+
useJUnitPlatform()
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.expediagroup.ktor.jackson
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper
4+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
5+
import io.ktor.http.ContentType
6+
import io.ktor.http.HttpStatusCode
7+
import io.ktor.server.application.Application
8+
import io.ktor.server.application.call
9+
import io.ktor.server.application.install
10+
import io.ktor.server.response.respond
11+
import io.ktor.server.response.respondText
12+
import io.ktor.server.routing.Routing
13+
import io.ktor.server.routing.get
14+
import io.ktor.server.routing.post
15+
import io.ktor.server.routing.routing
16+
17+
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
18+
19+
fun Application.graphQLModule() {
20+
val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
21+
val ktorGraphQLServer: KtorGraphQLServer = KtorGraphQLServer(jacksonObjectMapper)
22+
23+
install(Routing)
24+
routing {
25+
post("graphql") {
26+
val result = ktorGraphQLServer.execute(call.request)
27+
if (result != null) {
28+
val json = jacksonObjectMapper.writeValueAsString(result)
29+
call.response.call.respond(json)
30+
} else {
31+
call.response.call.respond(HttpStatusCode.BadRequest, "Invalid request")
32+
}
33+
}
34+
get("playground") {
35+
this.call.respondText(buildPlaygroundHtml("graphql", "subscriptions"), ContentType.Text.Html)
36+
}
37+
}
38+
}
39+
40+
private fun buildPlaygroundHtml(graphQLEndpoint: String, subscriptionsEndpoint: String) =
41+
Application::class.java.classLoader.getResource("graphql-playground.html")?.readText()
42+
?.replace("\${graphQLEndpoint}", graphQLEndpoint)
43+
?.replace("\${subscriptionsEndpoint}", subscriptionsEndpoint)
44+
?: throw IllegalStateException("graphql-playground.html cannot be found in the classpath")

0 commit comments

Comments
 (0)