Skip to content

Commit

Permalink
Use com.apollographql.mockserver.MockServer (#5939)
Browse files Browse the repository at this point in the history
* Use com.apollographql.mockserver.MockServer

* unbreak ctng
  • Loading branch information
martinbonnin authored Jun 5, 2024
1 parent 5b6ad56 commit e9f2620
Show file tree
Hide file tree
Showing 101 changed files with 295 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import com.apollographql.apollo3.cache.normalized.api.NormalizedCacheFactory
import com.apollographql.apollo3.cache.normalized.fetchPolicy
import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.apollo3.cache.normalized.store
import com.apollographql.apollo3.mockserver.MockRequestBase
import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.MockServerHandler
import com.apollographql.mockserver.MockRequestBase
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.MockServerHandler
import com.apollographql.apollo3.testing.MapTestNetworkTransport
import com.apollographql.apollo3.testing.registerTestResponse
import kotlinx.coroutines.joinAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import com.apollographql.apollo3.cache.normalized.api.NormalizedCacheFactory
import com.apollographql.apollo3.cache.normalized.fetchPolicy
import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.apollo3.cache.normalized.store
import com.apollographql.apollo3.mockserver.MockRequestBase
import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.MockServerHandler
import com.apollographql.mockserver.MockRequestBase
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.MockServerHandler
import com.apollographql.apollo3.testing.MapTestNetworkTransport
import com.apollographql.apollo3.testing.registerTestResponse
import kotlinx.coroutines.joinAll
Expand Down
4 changes: 1 addition & 3 deletions gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ apollo-api = { group = "com.apollographql.apollo3", name = "apollo-api", version
apollo-api-java = { group = "com.apollographql.apollo3", name = "apollo-api-java", version.ref = "apollo" }
apollo-httpCache = { group = "com.apollographql.apollo3", name = "apollo-http-cache", version.ref = "apollo" }
apollo-idlingresource = { group = "com.apollographql.apollo3", name = "apollo-idling-resource", version.ref = "apollo" }
apollo-mockserver = { group = "com.apollographql.apollo3", name = "apollo-mockserver", version.ref = "apollo" }
# Used by the apollo-tooling project which uses a published version of Apollo
apollo-mockserver-published = { group = "com.apollographql.apollo3", name = "apollo-mockserver", version.ref = "apollo-published" }
apollo-mockserver = { group = "com.apollographql.mockserver", name = "apollo-mockserver", version = "0.0.1" }
apollo-mpputils = { group = "com.apollographql.apollo3", name = "apollo-mpp-utils", version.ref = "apollo" }
apollo-normalizedcache = { group = "com.apollographql.apollo3", name = "apollo-normalized-cache", version.ref = "apollo" }
apollo-normalizedcache-incubating = { group = "com.apollographql.apollo3", name = "apollo-normalized-cache-incubating", version.ref = "apollo" }
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-http-cache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
implementation(libs.moshi)
implementation(libs.kotlinx.datetime)

testImplementation(project(":apollo-mockserver"))
testImplementation(libs.apollo.mockserver)
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.truth)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.apollographql.apollo3.api.http.HttpResponse
import com.apollographql.apollo3.api.http.valueOf
import com.apollographql.apollo3.cache.http.CachingHttpInterceptor
import com.apollographql.apollo3.exception.HttpCacheMissException
import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.enqueueString
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.enqueueString
import com.apollographql.apollo3.network.http.DefaultHttpEngine
import com.apollographql.apollo3.network.http.HttpInterceptorChain
import kotlinx.coroutines.Dispatchers
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kotlin {
}

fun KotlinDependencyHandler.commonTestDependencies() {
implementation(project(":apollo-mockserver"))
implementation(libs.apollo.mockserver)
implementation(libs.turbine)
implementation(project(":apollo-testing-support")) {
because("runTest")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.test.platform.app.InstrumentationRegistry
import com.apollographql.apollo3.api.http.HttpRequest
import com.apollographql.apollo3.api.http.HttpResponse
import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.mockserver.assertNoRequest
import com.apollographql.apollo3.mockserver.enqueueString
import com.apollographql.mockserver.assertNoRequest
import com.apollographql.mockserver.enqueueString
import com.apollographql.apollo3.network.NetworkMonitor
import com.apollographql.apollo3.network.http.DefaultHttpEngine
import com.apollographql.apollo3.network.http.HttpEngine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.apollographql.apollo3.network.http

import com.apollographql.apollo3.api.http.HttpMethod
import com.apollographql.apollo3.api.http.HttpRequest
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.enqueueString
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.enqueueString
import com.apollographql.apollo3.testing.internal.runTest
import platform.Foundation.NSURLSessionConfiguration
import kotlin.test.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.apollographql.apollo3.api.Operation
import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.interceptor.ApolloInterceptor
import com.apollographql.apollo3.interceptor.ApolloInterceptorChain
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.assertNoRequest
import com.apollographql.apollo3.mockserver.enqueueString
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.assertNoRequest
import com.apollographql.mockserver.enqueueString
import com.apollographql.apollo3.network.NetworkMonitor
import com.apollographql.apollo3.testing.FooQuery
import com.apollographql.apollo3.testing.internal.runTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package test.network

import com.apollographql.apollo3.exception.ApolloException
import com.apollographql.apollo3.mockserver.CloseFrame
import com.apollographql.apollo3.mockserver.DataMessage
import com.apollographql.apollo3.mockserver.MockRequestBase
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.PingFrame
import com.apollographql.apollo3.mockserver.PongFrame
import com.apollographql.apollo3.mockserver.TextMessage
import com.apollographql.apollo3.mockserver.WebSocketBody
import com.apollographql.apollo3.mockserver.WebSocketMessage
import com.apollographql.apollo3.mockserver.WebsocketMockRequest
import com.apollographql.apollo3.mockserver.awaitWebSocketRequest
import com.apollographql.apollo3.mockserver.enqueueWebSocket
import com.apollographql.mockserver.CloseFrame
import com.apollographql.mockserver.DataMessage
import com.apollographql.mockserver.MockRequestBase
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.PingFrame
import com.apollographql.mockserver.PongFrame
import com.apollographql.mockserver.TextMessage
import com.apollographql.mockserver.WebSocketBody
import com.apollographql.mockserver.WebSocketMessage
import com.apollographql.mockserver.WebsocketMockRequest
import com.apollographql.mockserver.awaitWebSocketRequest
import com.apollographql.mockserver.enqueueWebSocket
import com.apollographql.apollo3.mpp.Platform
import com.apollographql.apollo3.mpp.platform
import com.apollographql.apollo3.network.websocket.WebSocket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import com.apollographql.apollo3.exception.ApolloWebSocketClosedException
import com.apollographql.apollo3.exception.DefaultApolloException
import com.apollographql.apollo3.exception.SubscriptionOperationException
import com.apollographql.apollo3.interceptor.addRetryOnErrorInterceptor
import com.apollographql.apollo3.mockserver.CloseFrame
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.TextMessage
import com.apollographql.apollo3.mockserver.WebSocketBody
import com.apollographql.apollo3.mockserver.WebsocketMockRequest
import com.apollographql.apollo3.mockserver.awaitWebSocketRequest
import com.apollographql.apollo3.mockserver.enqueueWebSocket
import com.apollographql.mockserver.CloseFrame
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.TextMessage
import com.apollographql.mockserver.WebSocketBody
import com.apollographql.mockserver.WebsocketMockRequest
import com.apollographql.mockserver.awaitWebSocketRequest
import com.apollographql.mockserver.enqueueWebSocket
import com.apollographql.apollo3.mpp.Platform
import com.apollographql.apollo3.mpp.platform
import com.apollographql.apollo3.network.websocket.WebSocketNetworkTransport
Expand All @@ -23,7 +23,6 @@ import com.apollographql.apollo3.testing.FooSubscription
import com.apollographql.apollo3.testing.FooSubscription.Companion.completeMessage
import com.apollographql.apollo3.testing.FooSubscription.Companion.errorMessage
import com.apollographql.apollo3.testing.FooSubscription.Companion.nextMessage
import com.apollographql.apollo3.testing.awaitSubscribe
import com.apollographql.apollo3.testing.connectionAckMessage
import com.apollographql.apollo3.testing.internal.runTest
import kotlinx.coroutines.CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package test.network

import com.apollographql.apollo3.annotations.ApolloExperimental
import com.apollographql.apollo3.api.json.jsonReader
import com.apollographql.apollo3.api.json.readAny
import com.apollographql.mockserver.TextMessage
import com.apollographql.mockserver.WebsocketMockRequest
import okio.Buffer
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

suspend fun WebsocketMockRequest.awaitSubscribe(timeout: Duration = 1.seconds, messagesToIgnore: Set<String> = emptySet()): String {
while(true) {
val message = awaitMessage(timeout)
if (message !is TextMessage) {
TODO()
}
val map = (Buffer().writeUtf8(message.text).jsonReader().readAny() as Map<*, *>)

if (messagesToIgnore.contains(map["type"])) {
continue
}
check(map["type"] == "subscribe") {
"Expected subscribe, got '${map.get("type")}'"
}
return map.get("id") as String
}
}

/**
* Extracts the operationId from a graphql-ws message, ignores "complete messages"
*/
@ApolloExperimental
suspend fun WebsocketMockRequest.awaitComplete(timeout: Duration = 1.seconds) {
val message = awaitMessage(timeout)
if (message !is TextMessage) {
TODO()
}
val map = (Buffer().writeUtf8(message.text).jsonReader().readAny() as Map<*, *>)

check(map["type"] == "complete") {
"Expected complete, got '${map.get("type")}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import com.apollographql.apollo3.api.Subscription
import com.apollographql.apollo3.exception.ApolloHttpException
import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.interceptor.addRetryOnErrorInterceptor
import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.awaitWebSocketRequest
import com.apollographql.apollo3.mockserver.enqueueWebSocket
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.awaitWebSocketRequest
import com.apollographql.mockserver.enqueueWebSocket
import com.apollographql.apollo3.network.websocket.WebSocketNetworkTransport
import com.apollographql.apollo3.testing.FooQuery
import com.apollographql.apollo3.testing.FooSubscription
import com.apollographql.apollo3.testing.FooSubscription.Companion.completeMessage
import com.apollographql.apollo3.testing.FooSubscription.Companion.nextMessage
import com.apollographql.apollo3.testing.awaitSubscribe
import com.apollographql.apollo3.testing.connectionAckMessage
import com.apollographql.apollo3.testing.internal.runTest
import kotlinx.coroutines.CoroutineScope
Expand All @@ -31,6 +30,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlin.test.assertNotEquals
import kotlin.time.Duration.Companion.seconds
import test.network.awaitSubscribe

class RetryWebSocketsTest {
@Test
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-tooling/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {

testImplementation(libs.junit)
testImplementation(libs.truth)
testImplementation(libs.apollo.mockserver.published)
testImplementation(libs.apollo.mockserver)
testImplementation(libs.apollo.testingsupport.published)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.apollographql.apollo3.tooling

import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.enqueueString
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.enqueueString
import com.apollographql.apollo3.testing.internal.runTest
import com.google.common.truth.Truth
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.apollographql.apollo3.tooling

import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.enqueueString
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.enqueueString
import com.apollographql.apollo3.testing.internal.runTest
import com.apollographql.apollo3.testing.pathToUtf8
import org.junit.Assert.assertEquals
Expand Down
2 changes: 1 addition & 1 deletion tests/defer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ kotlin {
findByName("commonTest")?.apply {
dependencies {
implementation(libs.apollo.normalizedcache)
implementation(libs.apollo.mockserver)
implementation(libs.apollo.testingsupport)
implementation(libs.apollo.mockserver)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import com.apollographql.apollo3.exception.ApolloException
import com.apollographql.apollo3.exception.ApolloHttpException
import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.exception.CacheMissException
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.assertNoRequest
import com.apollographql.apollo3.mockserver.awaitRequest
import com.apollographql.apollo3.mockserver.enqueueError
import com.apollographql.apollo3.mockserver.enqueueMultipart
import com.apollographql.apollo3.mockserver.enqueueStrings
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.assertNoRequest
import com.apollographql.mockserver.awaitRequest
import com.apollographql.mockserver.enqueueError
import com.apollographql.mockserver.enqueueMultipart
import com.apollographql.mockserver.enqueueStrings
import com.apollographql.apollo3.mpp.Platform
import com.apollographql.apollo3.mpp.platform
import com.apollographql.apollo3.network.NetworkTransport
Expand Down
8 changes: 4 additions & 4 deletions tests/defer/src/commonTest/kotlin/test/DeferTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.ApolloResponse
import com.apollographql.apollo3.api.Error
import com.apollographql.apollo3.autoPersistedQueryInfo
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.enqueueMultipart
import com.apollographql.apollo3.mockserver.enqueueString
import com.apollographql.apollo3.mockserver.enqueueStrings
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.enqueueMultipart
import com.apollographql.mockserver.enqueueString
import com.apollographql.mockserver.enqueueStrings
import com.apollographql.apollo3.mpp.Platform
import com.apollographql.apollo3.mpp.currentTimeMillis
import com.apollographql.apollo3.mpp.platform
Expand Down
4 changes: 2 additions & 2 deletions tests/defer/src/jvmTest/kotlin/test/DeferJvmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.cache.http.HttpFetchPolicy
import com.apollographql.apollo3.cache.http.httpCache
import com.apollographql.apollo3.cache.http.httpFetchPolicy
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.enqueueMultipart
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.enqueueMultipart
import com.apollographql.apollo3.mpp.currentTimeMillis
import com.apollographql.apollo3.testing.awaitElement
import com.apollographql.apollo3.testing.internal.runTest
Expand Down
2 changes: 1 addition & 1 deletion tests/engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ kotlin {

val commonTest = getByName("commonTest").apply {
dependencies {
implementation(libs.apollo.mockserver)
implementation(libs.apollo.testingsupport)
implementation(libs.apollo.mockserver)
implementation(libs.turbine)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/engine/src/commonTest/kotlin/GzipTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.apollo3.network.http.DefaultHttpEngine
import com.apollographql.apollo3.network.http.HttpEngine
import com.apollographql.apollo3.network.http.get
Expand Down
8 changes: 4 additions & 4 deletions tests/engine/src/commonTest/kotlin/HttpEngineTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import com.apollographql.apollo3.api.http.HttpMethod
import com.apollographql.apollo3.api.http.HttpRequest
import com.apollographql.apollo3.api.http.valueOf
import com.apollographql.apollo3.exception.ApolloException
import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.awaitRequest
import com.apollographql.apollo3.mockserver.enqueueString
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.awaitRequest
import com.apollographql.mockserver.enqueueString
import com.apollographql.apollo3.testing.internal.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down
12 changes: 6 additions & 6 deletions tests/engine/src/commonTest/kotlin/WebSocketEngineTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import com.apollographql.apollo3.api.http.HttpHeader
import com.apollographql.apollo3.exception.ApolloException
import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.exception.ApolloWebSocketClosedException
import com.apollographql.apollo3.mockserver.CloseFrame
import com.apollographql.apollo3.mockserver.DataMessage
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.apollo3.mockserver.TextMessage
import com.apollographql.apollo3.mockserver.awaitWebSocketRequest
import com.apollographql.apollo3.mockserver.enqueueWebSocket
import com.apollographql.mockserver.CloseFrame
import com.apollographql.mockserver.DataMessage
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.TextMessage
import com.apollographql.mockserver.awaitWebSocketRequest
import com.apollographql.mockserver.enqueueWebSocket
import com.apollographql.apollo3.mpp.Platform
import com.apollographql.apollo3.mpp.platform
import com.apollographql.apollo3.testing.internal.runTest
Expand Down
1 change: 1 addition & 0 deletions tests/gzip/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ kotlin {
findByName("commonTest")?.apply {
dependencies {
implementation(libs.apollo.testingsupport)
implementation(libs.apollo.mockserver)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/gzip/src/commonTest/kotlin/test/GzipTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package test

import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.mockserver.MockResponse
import com.apollographql.apollo3.mockserver.MockServer
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.apollo3.testing.HostFileSystem
import com.apollographql.apollo3.testing.internal.runTest
import com.apollographql.apollo3.testing.testsPath
Expand Down
Loading

0 comments on commit e9f2620

Please sign in to comment.