@@ -20,10 +20,8 @@ import io.github.nstdio.http.ext.Assertions.awaitFor
20
20
import io.github.nstdio.http.ext.Compression.deflate
21
21
import io.github.nstdio.http.ext.Compression.gzip
22
22
import io.kotest.matchers.collections.shouldContainExactly
23
- import io.kotest.matchers.maps.shouldContain
24
- import io.kotest.matchers.nulls.shouldNotBeNull
23
+ import io.kotest.matchers.maps.shouldContainAll
25
24
import io.kotest.matchers.should
26
- import io.kotest.matchers.shouldBe
27
25
import io.kotest.property.Arb
28
26
import io.kotest.property.arbitrary.next
29
27
import io.kotest.property.arbitrary.string
@@ -37,6 +35,7 @@ import java.net.http.HttpResponse.BodyHandlers
37
35
import java.net.http.HttpResponse.BodyHandlers.discarding
38
36
import java.util.*
39
37
import java.util.concurrent.LinkedBlockingDeque
38
+ import java.util.function.Supplier
40
39
41
40
@MockWebServerTest
42
41
internal class ExtendedHttpClientIntegrationTest (private val mockWebServer : MockWebServer ) {
@@ -133,11 +132,15 @@ internal class ExtendedHttpClientIntegrationTest(private val mockWebServer: Mock
133
132
@Test
134
133
fun `Should add default headers` () {
135
134
// given
136
- val client : HttpClient = ExtendedHttpClient .newBuilder()
137
- .defaultHeader( " X-Testing-Value " , " 1 " )
138
- .defaultHeader( " X-Testing-Supplier " ) { " 2 " }
139
- .build()
135
+ val builder = ExtendedHttpClient .newBuilder()
136
+
137
+ val headers = ( 0 .. 4 ).associate { " X-Testing-Value- $it " to it.toString() }
138
+ val headersSuppliers = ( 0 .. 4 ).associate { " X-Testing-Supplier- $it " to Supplier { it.toString() } }
140
139
140
+ headers.forEach { (k, v) -> builder.defaultHeader(k, v) }
141
+ headersSuppliers.forEach { (k, v) -> builder.defaultHeader(k, v) }
142
+
143
+ val client = builder.build()
141
144
val request = HttpRequest .newBuilder(mockWebServer.url(" /test" ).toUri()).build()
142
145
mockWebServer.enqueue(MockResponse ().setResponseCode(200 ))
143
146
@@ -146,19 +149,14 @@ internal class ExtendedHttpClientIntegrationTest(private val mockWebServer: Mock
146
149
147
150
// then
148
151
response.request().headers().map().should {
149
- it.shouldContain( " X-Testing-Value " , listOf ( " 1 " ))
150
- it.shouldContain( " X-Testing-Supplier " , listOf ( " 2 " ))
152
+ it.shouldContainAll(headers.toMultimap( ))
153
+ it.shouldContainAll(headersSuppliers.withResolvedValues().toMultimap( ))
151
154
}
152
155
153
156
val actualRequest = mockWebServer.takeRequest()
154
- actualRequest.headers.should {
155
- it[" X-Testing-Value" ]
156
- .shouldNotBeNull()
157
- .shouldBe(" 1" )
158
-
159
- it[" X-Testing-Supplier" ]
160
- .shouldNotBeNull()
161
- .shouldBe(" 2" )
157
+ actualRequest.headers.toMap().should {
158
+ it.shouldContainAll(headers)
159
+ it.shouldContainAll(headersSuppliers.withResolvedValues().toMap())
162
160
}
163
161
}
164
162
@@ -186,4 +184,10 @@ internal class ExtendedHttpClientIntegrationTest(private val mockWebServer: Mock
186
184
headerValues.shouldContainExactly(requestIds)
187
185
}
188
186
}
187
+
188
+ private fun <K , V > Map <K , V >.toMultimap (): Map <K , List <V >> =
189
+ asSequence().map { e -> e.key to listOf (e.value) }.toMap()
190
+
191
+ private fun <K , V > Map <K , Supplier <V >>.withResolvedValues (): Map <K , V > =
192
+ asSequence().map { e -> e.key to e.value.get() }.toMap()
189
193
}
0 commit comments