@@ -19,7 +19,6 @@ import org.junit.jupiter.api.extension.ExtendWith
19
19
import org.slf4j.LoggerFactory
20
20
import org.springframework.beans.factory.annotation.Autowired
21
21
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
22
- import org.testcontainers.containers.PostgreSQLContainer.POSTGRESQL_PORT
23
22
import org.springframework.http.HttpHeaders
24
23
import org.springframework.restdocs.RestDocumentationContextProvider
25
24
import org.springframework.restdocs.RestDocumentationExtension
@@ -33,8 +32,9 @@ import org.springframework.test.web.servlet.MockMvc
33
32
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder
34
33
import org.springframework.test.web.servlet.setup.MockMvcBuilders
35
34
import org.springframework.web.context.WebApplicationContext
36
- import org.testcontainers.junit.jupiter.Testcontainers
37
35
import org.testcontainers.containers.PostgreSQLContainer
36
+ import org.testcontainers.containers.PostgreSQLContainer.POSTGRESQL_PORT
37
+ import org.testcontainers.junit.jupiter.Testcontainers
38
38
import org.testcontainers.utility.MountableFile
39
39
40
40
@Testcontainers
@@ -101,77 +101,76 @@ abstract class ControllerTestBase : AbstractTestcontainersRedisTestBase() {
101
101
private const val DEFAULT_REDIS_PORT = 6379
102
102
private const val REDIS_STACK_LASTEST_TAG_WITH_GRAPH = " 6.2.6-v18"
103
103
104
+ var postgres: PostgreSQLContainer <* > =
105
+ PostgreSQLContainer (" postgres:alpine3.19" )
106
+ .withCopyFileToContainer(
107
+ MountableFile .forClasspathResource(" init-db.sql" ), " /docker-entrypoint-initdb.d/" )
104
108
105
- var postgres: PostgreSQLContainer <* > =
106
- PostgreSQLContainer (" postgres:alpine3.19" )
107
- .withCopyFileToContainer(
108
- MountableFile .forClasspathResource(" init-db.sql" ), " /docker-entrypoint-initdb.d/" )
109
-
110
- var redisStackServer =
109
+ var redisStackServer =
111
110
RedisStackContainer (
112
111
RedisStackContainer .DEFAULT_IMAGE_NAME .withTag(REDIS_STACK_LASTEST_TAG_WITH_GRAPH ))
113
112
114
- init {
115
- redisStackServer.start()
116
- postgres.start()
117
- }
113
+ init {
114
+ redisStackServer.start()
115
+ postgres.start()
116
+ }
118
117
119
118
@JvmStatic
120
119
@DynamicPropertySource
121
120
fun connectionProperties (registry : DynamicPropertyRegistry ) {
122
121
initPostgresConfiguration(registry)
123
- initRedisConfiguration(registry)
124
- }
125
-
126
- private fun initRedisConfiguration (registry : DynamicPropertyRegistry ) {
127
- val containerIp =
128
- redisStackServer.containerInfo.networkSettings.networks.entries
129
- .elementAt(0 )
130
- .value
131
- .ipAddress
132
-
133
- registry.add(" spring.data.redis.host" ) { containerIp }
134
- registry.add(" spring.data.redis.port" ) { DEFAULT_REDIS_PORT }
135
- }
136
-
137
- private fun initPostgresConfiguration (registry : DynamicPropertyRegistry ) {
138
- registry.add(" csm.platform.internalResultServices.storage.host" ) { postgres.host }
139
- registry.add(" csm.platform.internalResultServices.storage.port" ) {
140
- postgres.getMappedPort(POSTGRESQL_PORT )
141
- }
142
- registry.add(" csm.platform.internalResultServices.storage.admin.username" ) {
143
- ADMIN_USER_CREDENTIALS
144
- }
145
- registry.add(" csm.platform.internalResultServices.storage.admin.password" ) {
146
- ADMIN_USER_CREDENTIALS
147
- }
148
- registry.add(" csm.platform.internalResultServices.storage.writer.username" ) {
149
- WRITER_USER_CREDENTIALS
150
- }
151
- registry.add(" csm.platform.internalResultServices.storage.writer.password" ) {
152
- WRITER_USER_CREDENTIALS
153
- }
154
- registry.add(" csm.platform.internalResultServices.storage.reader.username" ) {
155
- READER_USER_CREDENTIALS
156
- }
157
- registry.add(" csm.platform.internalResultServices.storage.reader.password" ) {
158
- READER_USER_CREDENTIALS
159
- }
160
- }
122
+ initRedisConfiguration(registry)
161
123
}
162
124
163
- @BeforeAll
164
- fun beforeAll () {
165
- redisStackServer.start()
166
- postgres.start()
167
- }
125
+ private fun initRedisConfiguration (registry : DynamicPropertyRegistry ) {
126
+ val containerIp =
127
+ redisStackServer.containerInfo.networkSettings.networks.entries
128
+ .elementAt(0 )
129
+ .value
130
+ .ipAddress
168
131
169
- @AfterAll
170
- fun afterAll () {
171
- postgres.stop()
132
+ registry.add(" spring.data.redis.host" ) { containerIp }
133
+ registry.add(" spring.data.redis.port" ) { DEFAULT_REDIS_PORT }
172
134
}
173
135
174
- override fun redisServers (): MutableCollection <RedisServer > {
175
- return mutableListOf (redisStackServer)
136
+ private fun initPostgresConfiguration (registry : DynamicPropertyRegistry ) {
137
+ registry.add(" csm.platform.internalResultServices.storage.host" ) { postgres.host }
138
+ registry.add(" csm.platform.internalResultServices.storage.port" ) {
139
+ postgres.getMappedPort(POSTGRESQL_PORT )
140
+ }
141
+ registry.add(" csm.platform.internalResultServices.storage.admin.username" ) {
142
+ ADMIN_USER_CREDENTIALS
143
+ }
144
+ registry.add(" csm.platform.internalResultServices.storage.admin.password" ) {
145
+ ADMIN_USER_CREDENTIALS
146
+ }
147
+ registry.add(" csm.platform.internalResultServices.storage.writer.username" ) {
148
+ WRITER_USER_CREDENTIALS
149
+ }
150
+ registry.add(" csm.platform.internalResultServices.storage.writer.password" ) {
151
+ WRITER_USER_CREDENTIALS
152
+ }
153
+ registry.add(" csm.platform.internalResultServices.storage.reader.username" ) {
154
+ READER_USER_CREDENTIALS
155
+ }
156
+ registry.add(" csm.platform.internalResultServices.storage.reader.password" ) {
157
+ READER_USER_CREDENTIALS
158
+ }
176
159
}
160
+ }
161
+
162
+ @BeforeAll
163
+ fun beforeAll () {
164
+ redisStackServer.start()
165
+ postgres.start()
166
+ }
167
+
168
+ @AfterAll
169
+ fun afterAll () {
170
+ postgres.stop()
171
+ }
172
+
173
+ override fun redisServers (): MutableCollection <RedisServer > {
174
+ return mutableListOf (redisStackServer)
175
+ }
177
176
}
0 commit comments