@@ -2,17 +2,21 @@ package test
2
2
3
3
import com.apollographql.execution.ExecutableSchema
4
4
import com.apollographql.execution.http4k.apolloHandler
5
+ import com.google.common.truth.Truth
5
6
import okhttp3.mockwebserver.MockResponse
6
7
import okhttp3.mockwebserver.MockWebServer
7
8
import okhttp3.tls.HandshakeCertificates
8
9
import okhttp3.tls.HeldCertificate
9
10
import org.gradle.testkit.runner.TaskOutcome
11
+ import org.gradle.testkit.runner.UnexpectedBuildFailure
10
12
import org.http4k.server.Jetty
11
13
import org.http4k.server.asServer
12
14
import org.junit.Assert
13
15
import org.junit.Test
14
16
import util.TestUtils
15
17
import java.io.File
18
+ import kotlin.test.assertContains
19
+ import kotlin.test.assertEquals
16
20
17
21
class DownloadSchemaTests {
18
22
private val mockServer = MockWebServer ()
@@ -152,6 +156,17 @@ class DownloadSchemaTests {
152
156
}
153
157
""" .trimIndent()
154
158
159
+ private val apolloConfigurationWithGradleProperty = """
160
+ apollo {
161
+ service("mock") {
162
+ introspection {
163
+ schemaFile = file("src/main/graphql/com/example/schema.json")
164
+ endpointUrl = providers.gradleProperty("schema-endpoint")
165
+ }
166
+ }
167
+ }
168
+ """ .trimIndent()
169
+
155
170
@Test
156
171
fun `schema is downloaded correctly` () {
157
172
TestUtils .withSimpleProject(apolloConfiguration = apolloConfiguration) { dir ->
@@ -240,4 +255,37 @@ class DownloadSchemaTests {
240
255
241
256
server.stop()
242
257
}
258
+
259
+ @Test
260
+ fun `when endpoint url property value is missing and the download task isn't executed, build succeeds` () {
261
+ TestUtils .withSimpleProject(apolloConfiguration = apolloConfigurationWithGradleProperty) { dir ->
262
+ Assert .assertEquals(TaskOutcome .SUCCESS , TestUtils .executeTask(" help" , dir).task(" :help" )?.outcome)
263
+ }
264
+ }
265
+
266
+ @Test
267
+ fun `when endpoint url property value is missing and the download task is executed, build fails` () {
268
+ TestUtils .withSimpleProject(apolloConfiguration = apolloConfigurationWithGradleProperty) { dir ->
269
+ try {
270
+ TestUtils .executeTask(" downloadMockApolloSchemaFromIntrospection" , dir)
271
+ } catch (ex: UnexpectedBuildFailure ) {
272
+ Assert .assertEquals(TaskOutcome .FAILED , ex.buildResult.task(" :downloadMockApolloSchemaFromIntrospection" )?.outcome)
273
+ Truth .assertThat(ex.buildResult.output).contains(" Apollo: either endpoint (for introspection) or key (for registry) is required" )
274
+ }
275
+ }
276
+ }
277
+
278
+ @Test
279
+ fun `when endpoint url property value is present and the download task is executed, build succeeds` () {
280
+ TestUtils .withSimpleProject(apolloConfiguration = apolloConfigurationWithGradleProperty) { dir ->
281
+ mockServer.enqueue(MockResponse ().setBody(preIntrospectionResponse))
282
+ mockServer.enqueue(MockResponse ().setBody(schemaString1))
283
+
284
+ val buildResult =
285
+ TestUtils .executeTask(" downloadMockApolloSchemaFromIntrospection" , dir, " -Pschema-endpoint=${mockServer.url(" /" ).toUrl()} " )
286
+
287
+ Assert .assertEquals(TaskOutcome .SUCCESS , buildResult.task(" :downloadMockApolloSchemaFromIntrospection" )?.outcome)
288
+ Assert .assertEquals(schemaString1, File (dir, " src/main/graphql/com/example/schema.json" ).readText())
289
+ }
290
+ }
243
291
}
0 commit comments