dmcg
04/17/2024, 12:33 PMcustomerStorage
I have removed the application.conf
and changed the startup to
fun main() {
embeddedServer(
Netty,
port = System.getenv("PORT")?.toInt() ?: 8080,
module = { module(customerStorage) }
).start(wait = true)
}
fun Application.module(customers: MutableList<Customer>) {
configureRouting(customers)
configureSerialization()
}
How can I now use the this new Application::module
in my tests? At the moment there is
class OrderRouteTests {
@Test
fun testGetOrder() = testApplication {
val response = client.get("/order/2020-04-06-01")
assertEquals(
"""{"number":"2020-04-06-01","contents":[{"item":"Ham Sandwich","amount":2,"price":5.5},{"item":"Water","amount":1,"price":1.5},{"item":"Beer","amount":3,"price":2.3},{"item":"Cheesecake","amount":1,"price":3.75}]}""",
response.bodyAsText()
)
assertEquals(HttpStatusCode.OK, response.status)
}
}
but I can’t see how to create a testApplication
block that builds the app with Application.module(customers: MutableList<Customer>)
Is this the right tack, or maybe I’m barking up the wrong tree?dmcg
04/17/2024, 12:37 PMtestApplication {
application {
module(customerStorage)
}
val response = client.get("/order/2020-04-06-01")
assertEquals(
"""{"number":"2020-04-06-01","contents":[{"item":"Ham Sandwich","amount":2,"price":5.5},{"item":"Water","amount":1,"price":1.5},{"item":"Beer","amount":3,"price":2.3},{"item":"Cheesecake","amount":1,"price":3.75}]}""",
response.bodyAsText()
)
assertEquals(HttpStatusCode.OK, response.status)
}
StackOverflow isn’t dead yet!