Skip to content

Commit 1d02f13

Browse files
authored
Bump Spring Boot 4 to RC1 (#4835)
* Bump Spring Boot 4 to RC1 * fix tests * fix test assertions * fix more test assertions
1 parent b6702b0 commit 1d02f13

File tree

9 files changed

+329
-258
lines changed

9 files changed

+329
-258
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ retrofit = "2.9.0"
3131
slf4j = "1.7.30"
3232
springboot2 = "2.7.18"
3333
springboot3 = "3.5.0"
34-
springboot4 = "4.0.0-M3"
34+
springboot4 = "4.0.0-RC1"
3535
# Android
3636
targetSdk = "34"
3737
compileSdk = "34"
@@ -166,6 +166,7 @@ springboot3-starter-security = { module = "org.springframework.boot:spring-boot-
166166
springboot3-starter-jdbc = { module = "org.springframework.boot:spring-boot-starter-jdbc", version.ref = "springboot3" }
167167
springboot3-starter-actuator = { module = "org.springframework.boot:spring-boot-starter-actuator", version.ref = "springboot3" }
168168
springboot4-otel = { module = "io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter", version.ref = "otelInstrumentation" }
169+
springboot4-resttestclient = { module = "org.springframework.boot:spring-boot-resttestclient", version.ref = "springboot4" }
169170
springboot4-starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "springboot4" }
170171
springboot4-starter-graphql = { module = "org.springframework.boot:spring-boot-starter-graphql", version.ref = "springboot4" }
171172
springboot4-starter-quartz = { module = "org.springframework.boot:spring-boot-starter-quartz", version.ref = "springboot4" }

sentry-spring-7/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ dependencies {
7575
testImplementation(libs.springboot4.starter.webflux)
7676
testImplementation(libs.springboot4.starter.restclient)
7777
testImplementation(libs.springboot4.starter.webclient)
78+
testImplementation(libs.springboot4.resttestclient)
7879
testImplementation(projects.sentryReactor)
7980
}
8081

sentry-spring-7/src/test/kotlin/io/sentry/spring7/graphql/SentrySpringSubscriptionHandlerTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class SentrySpringSubscriptionHandlerTest {
4040
whenever(parameters.environment).thenReturn(dataFetchingEnvironment)
4141
val resultObject =
4242
SentrySpringSubscriptionHandler()
43-
.onSubscriptionResult(Flux.error<Any?>(exception), scopes, exceptionReporter, parameters)
44-
assertThrows<IllegalStateException> { (resultObject as Flux<Any?>).blockFirst() }
43+
.onSubscriptionResult(Flux.error<Any>(exception), scopes, exceptionReporter, parameters)
44+
assertThrows<IllegalStateException> { (resultObject as Flux<Any>).blockFirst() }
4545

4646
verify(exceptionReporter)
4747
.captureThrowable(
@@ -77,12 +77,12 @@ class SentrySpringSubscriptionHandlerTest {
7777
val resultObject =
7878
SentrySpringSubscriptionHandler()
7979
.onSubscriptionResult(
80-
Flux.error<Any?>(wrappedException),
80+
Flux.error<Any>(wrappedException),
8181
scopes,
8282
exceptionReporter,
8383
parameters,
8484
)
85-
assertThrows<SubscriptionPublisherException> { (resultObject as Flux<Any?>).blockFirst() }
85+
assertThrows<SubscriptionPublisherException> { (resultObject as Flux<Any>).blockFirst() }
8686

8787
verify(exceptionReporter)
8888
.captureThrowable(

sentry-spring-7/src/test/kotlin/io/sentry/spring7/mvc/SentrySpringIntegrationTest.kt

Lines changed: 109 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ import org.mockito.kotlin.verify
4242
import org.mockito.kotlin.whenever
4343
import org.springframework.beans.factory.annotation.Autowired
4444
import org.springframework.boot.autoconfigure.SpringBootApplication
45+
import org.springframework.boot.resttestclient.TestRestTemplate
4546
import org.springframework.boot.test.context.SpringBootTest
46-
import org.springframework.boot.web.server.test.LocalServerPort
47-
import org.springframework.boot.web.server.test.client.TestRestTemplate
47+
import org.springframework.boot.test.web.server.LocalServerPort
4848
import org.springframework.boot.web.servlet.FilterRegistrationBean
4949
import org.springframework.context.annotation.Bean
5050
import org.springframework.context.annotation.Configuration
@@ -80,13 +80,15 @@ import org.springframework.web.reactive.function.client.WebClient
8080
class SentrySpringIntegrationTest {
8181

8282
companion object {
83+
@JvmStatic
8384
@BeforeClass
84-
fun `configure awaitlity`() {
85+
fun `configure awaitlity`(): Unit {
8586
Awaitility.setDefaultTimeout(500, TimeUnit.MILLISECONDS)
8687
}
8788

89+
@JvmStatic
8890
@AfterClass
89-
fun `reset awaitility`() {
91+
fun `reset awaitility`(): Unit {
9092
Awaitility.reset()
9193
}
9294
}
@@ -115,17 +117,19 @@ class SentrySpringIntegrationTest {
115117

116118
restTemplate.exchange("http://localhost:$port/hello", HttpMethod.GET, entity, Void::class.java)
117119

118-
verify(transport)
119-
.send(
120-
checkEvent { event ->
121-
assertThat(event.request).isNotNull()
122-
assertThat(event.request!!.url).isEqualTo("http://localhost:$port/hello")
123-
assertThat(event.user).isNotNull()
124-
assertThat(event.user!!.username).isEqualTo("user")
125-
assertThat(event.user!!.ipAddress).isEqualTo("169.128.0.1")
126-
},
127-
anyOrNull(),
128-
)
120+
await.untilAsserted {
121+
verify(transport)
122+
.send(
123+
checkEvent { event ->
124+
assertThat(event.request).isNotNull()
125+
assertThat(event.request!!.url).isEqualTo("http://localhost:$port/hello")
126+
assertThat(event.user).isNotNull()
127+
assertThat(event.user!!.username).isEqualTo("user")
128+
assertThat(event.user!!.ipAddress).isEqualTo("169.128.0.1")
129+
},
130+
anyOrNull(),
131+
)
132+
}
129133
}
130134

131135
@Test
@@ -140,14 +144,16 @@ class SentrySpringIntegrationTest {
140144
Void::class.java,
141145
)
142146

143-
verify(transport)
144-
.send(
145-
checkEvent { event ->
146-
assertThat(event.request).isNotNull()
147-
assertThat(event.request!!.data).isEqualTo("""{"body":"content"}""")
148-
},
149-
anyOrNull(),
150-
)
147+
await.untilAsserted {
148+
verify(transport)
149+
.send(
150+
checkEvent { event ->
151+
assertThat(event.request).isNotNull()
152+
assertThat(event.request!!.data).isEqualTo("""{"body":"content"}""")
153+
},
154+
anyOrNull(),
155+
)
156+
}
151157
}
152158

153159
@Test
@@ -162,14 +168,16 @@ class SentrySpringIntegrationTest {
162168
Void::class.java,
163169
)
164170

165-
verify(transport)
166-
.send(
167-
checkEvent { event ->
168-
assertThat(event.request).isNotNull()
169-
assertThat(event.request!!.data).isEqualTo("""{"body":"content"}""")
170-
},
171-
anyOrNull(),
172-
)
171+
await.untilAsserted {
172+
verify(transport)
173+
.send(
174+
checkEvent { event ->
175+
assertThat(event.request).isNotNull()
176+
assertThat(event.request!!.data).isEqualTo("""{"body":"content"}""")
177+
},
178+
anyOrNull(),
179+
)
180+
}
173181
}
174182

175183
@Test
@@ -181,14 +189,16 @@ class SentrySpringIntegrationTest {
181189

182190
restTemplate.exchange("http://localhost:$port/hello", HttpMethod.GET, entity, Void::class.java)
183191

184-
verify(transport)
185-
.send(
186-
checkEvent { event ->
187-
assertThat(event.user).isNotNull()
188-
assertThat(event.user!!.ipAddress).isEqualTo("169.128.0.1")
189-
},
190-
anyOrNull(),
191-
)
192+
await.untilAsserted {
193+
verify(transport)
194+
.send(
195+
checkEvent { event ->
196+
assertThat(event.user).isNotNull()
197+
assertThat(event.user!!.ipAddress).isEqualTo("169.128.0.1")
198+
},
199+
anyOrNull(),
200+
)
201+
}
192202
}
193203

194204
@Test
@@ -197,18 +207,20 @@ class SentrySpringIntegrationTest {
197207

198208
restTemplate.getForEntity("http://localhost:$port/throws", String::class.java)
199209

200-
verify(transport)
201-
.send(
202-
checkEvent { event ->
203-
assertThat(event.exceptions).isNotNull().isNotEmpty
204-
val ex = event.exceptions!!.first()
205-
assertThat(ex.value).isEqualTo("something went wrong")
206-
assertThat(ex.mechanism).isNotNull()
207-
assertThat(ex.mechanism!!.isHandled).isFalse()
208-
assertThat(ex.mechanism!!.type).isEqualTo(SentryExceptionResolver.MECHANISM_TYPE)
209-
},
210-
anyOrNull(),
211-
)
210+
await.untilAsserted {
211+
verify(transport)
212+
.send(
213+
checkEvent { event ->
214+
assertThat(event.exceptions).isNotNull().isNotEmpty
215+
val ex = event.exceptions!!.first()
216+
assertThat(ex.value).isEqualTo("something went wrong")
217+
assertThat(ex.mechanism).isNotNull()
218+
assertThat(ex.mechanism!!.isHandled).isFalse()
219+
assertThat(ex.mechanism!!.type).isEqualTo(SentryExceptionResolver.MECHANISM_TYPE)
220+
},
221+
anyOrNull(),
222+
)
223+
}
212224
}
213225

214226
@Test
@@ -217,11 +229,13 @@ class SentrySpringIntegrationTest {
217229

218230
restTemplate.getForEntity("http://localhost:$port/throws", String::class.java)
219231

220-
verify(transport)
221-
.send(
222-
checkEvent { event -> assertThat(event.transaction).isEqualTo("GET /throws") },
223-
anyOrNull(),
224-
)
232+
await.untilAsserted {
233+
verify(transport)
234+
.send(
235+
checkEvent { event -> assertThat(event.transaction).isEqualTo("GET /throws") },
236+
anyOrNull(),
237+
)
238+
}
225239
}
226240

227241
@Test
@@ -230,7 +244,7 @@ class SentrySpringIntegrationTest {
230244

231245
restTemplate.getForEntity("http://localhost:$port/throws-handled", String::class.java)
232246

233-
await.during(Duration.ofSeconds(2)).untilAsserted {
247+
await.atMost(3, TimeUnit.SECONDS).during(Duration.ofSeconds(2)).untilAsserted {
234248
verify(transport, never())
235249
.send(checkEvent { event -> assertThat(event).isNotNull() }, anyOrNull())
236250
}
@@ -240,29 +254,35 @@ class SentrySpringIntegrationTest {
240254
fun `calling a method annotated with @SentryCaptureException captures exception`() {
241255
val exception = java.lang.RuntimeException("test exception")
242256
anotherService.aMethodThatTakesAnException(exception)
243-
verify(transport)
244-
.send(
245-
checkEvent { assertThat(it.exceptions!!.first().value).isEqualTo(exception.message) },
246-
anyOrNull(),
247-
)
257+
await.untilAsserted {
258+
verify(transport)
259+
.send(
260+
checkEvent { assertThat(it.exceptions!!.first().value).isEqualTo(exception.message) },
261+
anyOrNull(),
262+
)
263+
}
248264
}
249265

250266
@Test
251267
fun `calling a method annotated with @SentryCaptureException captures exception in later param`() {
252268
val exception = java.lang.RuntimeException("test exception")
253269
anotherService.aMethodThatTakesAnExceptionAsLaterParam("a", "b", exception)
254-
verify(transport)
255-
.send(
256-
checkEvent { assertThat(it.exceptions!!.first().value).isEqualTo(exception.message) },
257-
anyOrNull(),
258-
)
270+
await.untilAsserted {
271+
verify(transport)
272+
.send(
273+
checkEvent { assertThat(it.exceptions!!.first().value).isEqualTo(exception.message) },
274+
anyOrNull(),
275+
)
276+
}
259277
}
260278

261279
@Test
262280
fun `calling a method annotated with @SentryTransaction creates transaction`() {
263281
someService.aMethod()
264-
verify(transport)
265-
.send(checkTransaction { assertThat(it.status).isEqualTo(SpanStatus.OK) }, anyOrNull())
282+
await.untilAsserted {
283+
verify(transport)
284+
.send(checkTransaction { assertThat(it.status).isEqualTo(SpanStatus.OK) }, anyOrNull())
285+
}
266286
}
267287

268288
@Test
@@ -272,14 +292,16 @@ class SentrySpringIntegrationTest {
272292
} catch (e: Exception) {
273293
scopes.captureException(e)
274294
}
275-
verify(transport)
276-
.send(
277-
checkEvent {
278-
assertThat(it.contexts.trace).isNotNull
279-
assertThat(it.contexts.trace!!.operation).isEqualTo("bean")
280-
},
281-
anyOrNull(),
282-
)
295+
await.untilAsserted {
296+
verify(transport)
297+
.send(
298+
checkEvent {
299+
assertThat(it.contexts.trace).isNotNull
300+
assertThat(it.contexts.trace!!.operation).isEqualTo("bean")
301+
},
302+
anyOrNull(),
303+
)
304+
}
283305
}
284306

285307
@Test
@@ -289,14 +311,16 @@ class SentrySpringIntegrationTest {
289311
} catch (e: Exception) {
290312
scopes.captureException(e)
291313
}
292-
verify(transport)
293-
.send(
294-
checkEvent {
295-
assertThat(it.contexts.trace).isNotNull
296-
assertThat(it.contexts.trace!!.operation).isEqualTo("child-op")
297-
},
298-
anyOrNull(),
299-
)
314+
await.untilAsserted {
315+
verify(transport)
316+
.send(
317+
checkEvent {
318+
assertThat(it.contexts.trace).isNotNull
319+
assertThat(it.contexts.trace!!.operation).isEqualTo("child-op")
320+
},
321+
anyOrNull(),
322+
)
323+
}
300324
}
301325

302326
@Test

sentry-spring-7/src/test/kotlin/io/sentry/spring7/webflux/SentryWebfluxIntegrationTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import org.mockito.kotlin.whenever
2727
import org.springframework.beans.factory.annotation.Autowired
2828
import org.springframework.boot.ApplicationRunner
2929
import org.springframework.boot.autoconfigure.SpringBootApplication
30-
import org.springframework.boot.security.autoconfigure.reactive.ReactiveSecurityAutoConfiguration
31-
import org.springframework.boot.security.autoconfigure.servlet.SecurityAutoConfiguration
30+
import org.springframework.boot.security.autoconfigure.SecurityAutoConfiguration
31+
import org.springframework.boot.security.autoconfigure.web.reactive.ReactiveWebSecurityAutoConfiguration
3232
import org.springframework.boot.test.context.SpringBootTest
33-
import org.springframework.boot.web.server.test.LocalServerPort
33+
import org.springframework.boot.test.web.server.LocalServerPort
3434
import org.springframework.context.annotation.Bean
3535
import org.springframework.http.ResponseEntity
3636
import org.springframework.test.context.junit4.SpringRunner
@@ -136,7 +136,7 @@ class SentryWebfluxIntegrationTest {
136136
}
137137

138138
@SpringBootApplication(
139-
exclude = [ReactiveSecurityAutoConfiguration::class, SecurityAutoConfiguration::class]
139+
exclude = [ReactiveWebSecurityAutoConfiguration::class, SecurityAutoConfiguration::class]
140140
)
141141
open class App {
142142
private val transport = mock<ITransport>().also { whenever(it.isHealthy).thenReturn(true) }

sentry-spring-boot-4/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ dependencies {
102102
testImplementation(libs.springboot4.starter.webflux)
103103
testImplementation(libs.springboot4.starter.restclient)
104104
testImplementation(libs.springboot4.starter.webclient)
105+
testImplementation(libs.springboot4.resttestclient)
105106
}
106107

107108
configure<SourceSetContainer> { test { java.srcDir("src/test/java") } }

sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/it/SentrySpringIntegrationTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import org.mockito.kotlin.whenever
2424
import org.slf4j.LoggerFactory
2525
import org.springframework.beans.factory.annotation.Autowired
2626
import org.springframework.boot.autoconfigure.SpringBootApplication
27+
import org.springframework.boot.resttestclient.TestRestTemplate
2728
import org.springframework.boot.test.context.SpringBootTest
28-
import org.springframework.boot.web.server.test.LocalServerPort
29-
import org.springframework.boot.web.server.test.client.TestRestTemplate
29+
import org.springframework.boot.test.web.server.LocalServerPort
3030
import org.springframework.context.annotation.Bean
3131
import org.springframework.context.annotation.Configuration
3232
import org.springframework.http.HttpEntity

0 commit comments

Comments
 (0)