-
Notifications
You must be signed in to change notification settings - Fork 3
/
MyApplicationIntegrationTest.kt
56 lines (47 loc) 路 1.87 KB
/
MyApplicationIntegrationTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.rogervinas.multibinder
import com.rogervinas.multibinder.helper.DockerComposeContainerHelper
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
import org.springframework.boot.test.system.CapturedOutput
import org.springframework.boot.test.system.OutputCaptureExtension
import org.springframework.test.web.reactive.server.WebTestClient
import org.testcontainers.junit.jupiter.Container
import org.testcontainers.junit.jupiter.Testcontainers
import org.testcontainers.shaded.org.awaitility.Awaitility.await
import org.testcontainers.shaded.org.awaitility.Durations.ONE_MINUTE
@SpringBootTest(webEnvironment = RANDOM_PORT)
@Testcontainers
@ExtendWith(OutputCaptureExtension::class)
internal class MyApplicationIntegrationTest {
companion object {
@Container
val container = DockerComposeContainerHelper().createContainer()
}
@Value("http://localhost:\${local.server.port}")
lateinit var localUrl: String
@Autowired
lateinit var webClient: WebTestClient
@Test
fun `should process text lengths`(capturedOutput: CapturedOutput) {
postText("Do")
postText("or do not")
postText("there is no try")
await().atMost(ONE_MINUTE).untilAsserted {
assertThat(capturedOutput.out).contains("Consumed length [2]")
assertThat(capturedOutput.out).contains("Consumed length [9]")
assertThat(capturedOutput.out).contains("Consumed length [15]")
}
}
private fun postText(text: String) {
webClient.post()
.uri("/text")
.bodyValue(text)
.exchange()
.expectStatus().isOk
}
}