Skip to content

Commit a2e78e8

Browse files
authored
breaking: move baseUrl to httpClient system options (#494)
1 parent fbad811 commit a2e78e8

File tree

11 files changed

+155
-102
lines changed

11 files changed

+155
-102
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ kotlin-ide/
8383

8484
# Ignore Gradle build output directory
8585
build
86+
.kotlin

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Frameworks:
4141
### Setting-up all the physical dependencies with application
4242

4343
```kotlin
44-
TestSystem(baseUrl = "http://localhost:8001") {
44+
TestSystem() {
4545
if (isRunningLocally()) {
4646
enableReuseForTestContainers()
4747
keepDendenciesRunning() // this will keep the dependencies running after the tests are finished, so next run will be blazing fast :)
@@ -50,7 +50,11 @@ TestSystem(baseUrl = "http://localhost:8001") {
5050
// Enables http client
5151
// to make real http calls
5252
// against the application under test
53-
http()
53+
httpClient {
54+
HttpClientSystemOptions(
55+
baseUrl = "http://localhost:8001",
56+
)
57+
}
5458

5559
// Enables Couchbase physically
5660
// and exposes the configuration

docs/how-to-write-tests/1.Application-Aware/1.Spring-Boot/0002-initial-configuration.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ it is time to run your application for the first time from the test-context with
1717
class TestSystemConfig : AbstractProjectConfig() {
1818

1919
override suspend fun beforeProject(): Unit =
20-
TestSystem(baseUrl = "http://localhost:8001")
20+
TestSystem()
2121
.with {
22-
httpClient()
22+
httpClient {
23+
HttpClientSystemOptions {
24+
baseUrl = "http://localhost:8001"
25+
}
26+
}
2327
springBoot(
2428
runner = { parameters ->
2529
/*
@@ -49,9 +53,13 @@ it is time to run your application for the first time from the test-context with
4953

5054
@BeforeAll
5155
fun beforeProject() = runBlocking {
52-
TestSystem(baseUrl = "http://localhost:8001")
56+
TestSystem()
5357
.with {
54-
httpClient()
58+
httpClient {
59+
HttpClientSystemOptions {
60+
baseUrl = "http://localhost:8001"
61+
}
62+
}
5563
springBoot(
5664
runner = { parameters ->
5765
/*

docs/how-to-write-tests/1.Application-Aware/2.Ktor/index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
## Example Setup
2626

2727
```kotlin
28-
TestSystem(baseUrl = "http://localhost:8080")
28+
TestSystem()
2929
.with {
30-
httpClient()
30+
httpClient {
31+
HttpClientSystemOptions {
32+
baseUrl = "http://localhost:8080"
33+
}
34+
}
3135
bridge()
3236
postgresql {
3337
PostgresqlOptions(configureExposedConfiguration = { cfg ->

examples/ktor-example/src/test/kotlin/com/stove/ktor/example/e2e/TestSystemConfig.kt

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.stove.ktor.example.e2e
22

33
import com.trendol.stove.testing.e2e.rdbms.postgres.*
44
import com.trendyol.stove.testing.e2e.*
5-
import com.trendyol.stove.testing.e2e.http.httpClient
5+
import com.trendyol.stove.testing.e2e.http.*
66
import com.trendyol.stove.testing.e2e.standalone.kafka.*
77
import com.trendyol.stove.testing.e2e.system.*
88
import com.trendyol.stove.testing.e2e.system.abstractions.*
@@ -31,57 +31,59 @@ class GitlabStateStorageFactory : StateStorageFactory {
3131
class TestSystemConfig : AbstractProjectConfig() {
3232
private val logger: Logger = LoggerFactory.getLogger("WireMockMonitor")
3333

34-
override suspend fun beforeProject() =
35-
TestSystem(baseUrl = "http://localhost:8080") {
36-
// this.stateStorage(GitlabStateStorageFactory())
37-
if (this.isRunningLocally()) {
38-
enableReuseForTestContainers()
39-
keepDependenciesRunning()
40-
}
41-
}.with {
42-
httpClient()
43-
bridge()
44-
postgresql {
45-
PostgresqlOptions(configureExposedConfiguration = { cfg ->
46-
listOf(
47-
"database.jdbcUrl=${cfg.jdbcUrl}",
48-
"database.host=${cfg.host}",
49-
"database.port=${cfg.port}",
50-
"database.name=${cfg.database}",
51-
"database.username=${cfg.username}",
52-
"database.password=${cfg.password}"
53-
)
54-
})
55-
}
56-
kafka {
57-
stoveKafkaObjectMapperRef = objectMapperRef
58-
KafkaSystemOptions {
59-
listOf(
60-
"kafka.bootstrapServers=${it.bootstrapServers}",
61-
"kafka.interceptorClasses=${it.interceptorClass}"
62-
)
63-
}
64-
}
65-
wiremock {
66-
WireMockSystemOptions(
67-
port = 9090,
68-
removeStubAfterRequestMatched = true,
69-
afterRequest = { e, _ ->
70-
logger.info(e.request.toString())
71-
}
34+
override suspend fun beforeProject() = TestSystem {
35+
if (this.isRunningLocally()) {
36+
enableReuseForTestContainers()
37+
keepDependenciesRunning()
38+
}
39+
}.with {
40+
httpClient {
41+
HttpClientSystemOptions(
42+
baseUrl = "http://localhost:8080"
43+
)
44+
}
45+
bridge()
46+
postgresql {
47+
PostgresqlOptions(configureExposedConfiguration = { cfg ->
48+
listOf(
49+
"database.jdbcUrl=${cfg.jdbcUrl}",
50+
"database.host=${cfg.host}",
51+
"database.port=${cfg.port}",
52+
"database.name=${cfg.database}",
53+
"database.username=${cfg.username}",
54+
"database.password=${cfg.password}"
55+
)
56+
})
57+
}
58+
kafka {
59+
stoveKafkaObjectMapperRef = objectMapperRef
60+
KafkaSystemOptions {
61+
listOf(
62+
"kafka.bootstrapServers=${it.bootstrapServers}",
63+
"kafka.interceptorClasses=${it.interceptorClass}"
7264
)
7365
}
74-
ktor(
75-
withParameters = listOf(
76-
"port=8080"
77-
),
78-
runner = { parameters ->
79-
stove.ktor.example.run(parameters) {
80-
addTestSystemDependencies()
81-
}
66+
}
67+
wiremock {
68+
WireMockSystemOptions(
69+
port = 9090,
70+
removeStubAfterRequestMatched = true,
71+
afterRequest = { e, _ ->
72+
logger.info(e.request.toString())
8273
}
8374
)
84-
}.run()
75+
}
76+
ktor(
77+
withParameters = listOf(
78+
"port=8080"
79+
),
80+
runner = { parameters ->
81+
stove.ktor.example.run(parameters) {
82+
addTestSystemDependencies()
83+
}
84+
}
85+
)
86+
}.run()
8587

8688
override suspend fun afterProject() {
8789
TestSystem.stop()

examples/spring-example/src/test/kotlin/com/stove/spring/example/e2e/TestSystemConfig.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.stove.spring.example.e2e
22

33
import com.trendyol.stove.testing.e2e.*
44
import com.trendyol.stove.testing.e2e.couchbase.*
5-
import com.trendyol.stove.testing.e2e.http.httpClient
5+
import com.trendyol.stove.testing.e2e.http.*
66
import com.trendyol.stove.testing.e2e.kafka.*
77
import com.trendyol.stove.testing.e2e.system.TestSystem
88
import com.trendyol.stove.testing.e2e.wiremock.*
@@ -12,10 +12,15 @@ import org.slf4j.*
1212
class TestSystemConfig : AbstractProjectConfig() {
1313
private val logger: Logger = LoggerFactory.getLogger("WireMockMonitor")
1414

15+
@Suppress("LongMethod")
1516
override suspend fun beforeProject(): Unit =
16-
TestSystem(baseUrl = "http://localhost:8001")
17+
TestSystem()
1718
.with {
18-
httpClient()
19+
httpClient {
20+
HttpClientSystemOptions(
21+
baseUrl = "http://localhost:8001"
22+
)
23+
}
1924
couchbase {
2025
CouchbaseSystemOptions(
2126
"Stove",

examples/spring-standalone-example/src/test/kotlin/com/stove/spring/standalone/example/e2e/TestSystemConfig.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.stove.spring.standalone.example.e2e
22

33
import com.trendyol.stove.testing.e2e.*
44
import com.trendyol.stove.testing.e2e.couchbase.*
5-
import com.trendyol.stove.testing.e2e.http.httpClient
5+
import com.trendyol.stove.testing.e2e.http.*
66
import com.trendyol.stove.testing.e2e.standalone.kafka.*
77
import com.trendyol.stove.testing.e2e.system.TestSystem
88
import com.trendyol.stove.testing.e2e.wiremock.*
@@ -13,10 +13,15 @@ import stove.spring.standalone.example.infrastructure.ObjectMapperConfig
1313
class TestSystemConfig : AbstractProjectConfig() {
1414
private val logger: Logger = LoggerFactory.getLogger("WireMockMonitor")
1515

16+
@Suppress("LongMethod")
1617
override suspend fun beforeProject(): Unit =
17-
TestSystem(baseUrl = "http://localhost:8001")
18+
TestSystem()
1819
.with {
19-
httpClient()
20+
httpClient {
21+
HttpClientSystemOptions(
22+
baseUrl = "http://localhost:8001"
23+
)
24+
}
2025
couchbase {
2126
CouchbaseSystemOptions(
2227
"Stove",

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ projectUrl=https://github.com/Trendyol/stove
66
licenceUrl=https://github.com/Trendyol/stove/blob/master/LICENCE
77
licence=Apache-2.0 license
88
snapshot=1.0.0-SNAPSHOT
9+
kotlin.daemon.jvmargs=-Xmx1536m
910

lib/stove-testing-e2e-http/src/main/kotlin/com/trendyol/stove/testing/e2e/http/HttpSystem.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ import kotlin.time.Duration.Companion.seconds
2525
import kotlin.time.toJavaDuration
2626

2727
@HttpDsl
28-
data class HttpClientSystemOptions(val objectMapper: ObjectMapper = StoveObjectMapper.Default) : SystemOptions
28+
data class HttpClientSystemOptions(
29+
val baseUrl: String,
30+
val objectMapper: ObjectMapper = StoveObjectMapper.Default
31+
) : SystemOptions
2932

30-
internal fun TestSystem.withHttpClient(options: HttpClientSystemOptions = HttpClientSystemOptions()): TestSystem {
31-
this.getOrRegister(HttpSystem(this, options.objectMapper))
33+
internal fun TestSystem.withHttpClient(options: HttpClientSystemOptions): TestSystem {
34+
this.getOrRegister(HttpSystem(this, options))
3235
return this
3336
}
3437

@@ -37,7 +40,7 @@ internal fun TestSystem.http(): HttpSystem = getOrNone<HttpSystem>().getOrElse {
3740
}
3841

3942
@StoveDsl
40-
fun WithDsl.httpClient(configure: @StoveDsl () -> HttpClientSystemOptions = { HttpClientSystemOptions() }): TestSystem =
43+
fun WithDsl.httpClient(configure: @StoveDsl () -> HttpClientSystemOptions): TestSystem =
4144
this.testSystem.withHttpClient(configure())
4245

4346
@StoveDsl
@@ -48,7 +51,7 @@ suspend fun ValidationDsl.http(
4851
@HttpDsl
4952
class HttpSystem(
5053
override val testSystem: TestSystem,
51-
@PublishedApi internal val objectMapper: ObjectMapper
54+
@PublishedApi internal val options: HttpClientSystemOptions
5255
) : PluggedSystem {
5356
private val logger: org.slf4j.Logger = LoggerFactory.getLogger(javaClass)
5457

@@ -232,7 +235,7 @@ class HttpSystem(
232235
}
233236

234237
@PublishedApi
235-
internal fun relative(uri: String): Url = URLBuilder(testSystem.baseUrl)
238+
internal fun relative(uri: String): Url = URLBuilder(options.baseUrl)
236239
.apply { appendEncodedPathSegments(uri) }.build()
237240

238241
@PublishedApi
@@ -281,7 +284,7 @@ class HttpSystem(
281284
}
282285

283286
install(ContentNegotiation) {
284-
register(ContentType.Application.Json, JacksonConverter(objectMapper))
287+
register(ContentType.Application.Json, JacksonConverter(options.objectMapper))
285288
}
286289

287290
defaultRequest {

lib/stove-testing-e2e-http/src/test/kotlin/com/trendyol/stove/testing/e2e/http/HttpSystemTests.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ class NoApplication : ApplicationUnderTest<Unit> {
2525

2626
class TestConfig : AbstractProjectConfig() {
2727
override suspend fun beforeProject(): Unit =
28-
TestSystem("http://localhost:8086")
28+
TestSystem()
2929
.with {
3030
httpClient {
3131
HttpClientSystemOptions(
32+
baseUrl = "http://localhost:8086",
3233
objectMapper = StoveObjectMapper.byConfiguring {
3334
findAndRegisterModules()
3435
}

0 commit comments

Comments
 (0)