Repository navigation
test(spring): [Sample Tests 28] Move the Spring 7 WAR sample's tests into the module #6320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
runningcode
wants to merge
1
commit into
no/spring-jakarta-integration-test
Choose a base branch
from
no/spring-7-integration-test
base: no/spring-jakarta-integration-test
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
sentry-samples/sentry-samples-spring-7/src/test/kotlin/io/sentry/DummyTest.kt
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
...samples/sentry-samples-spring-7/src/test/kotlin/io/sentry/systemtest/MetricsSystemTest.kt
This file was deleted.
Oops, something went wrong.
85 changes: 0 additions & 85 deletions
85
...-samples/sentry-samples-spring-7/src/test/kotlin/io/sentry/systemtest/PersonSystemTest.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...-spring-7/src/integrationTest/kotlin/io/sentry/spring7/integrationtest/IntegrationTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package io.sentry.spring7.integrationtest | ||
|
|
||
| import io.sentry.test.MockSentryServer | ||
| import jakarta.servlet.ServletContainerInitializer | ||
| import java.nio.file.Files | ||
| import java.util.ServiceLoader | ||
| import org.apache.catalina.startup.Tomcat | ||
| import org.junit.Before | ||
| import org.springframework.http.client.ClientHttpResponse | ||
| import org.springframework.web.client.DefaultResponseErrorHandler | ||
| import org.springframework.web.client.RestTemplate | ||
| import org.springframework.web.util.DefaultUriBuilderFactory | ||
|
|
||
| /** | ||
| * Drives [AppInitializer]'s app over HTTP and asserts what reaches [server]. | ||
| * | ||
| * Subclasses share one app and one server. Envelopes that arrive late can outlive [server]'s reset, | ||
| * so tests match on values only they produce. | ||
| */ | ||
| abstract class IntegrationTest { | ||
| val server = TomcatApp.server | ||
| val restTemplate = TomcatApp.restTemplate | ||
|
|
||
| @Before | ||
| fun resetServer() { | ||
| server.reset() | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The app in an embedded Tomcat, with no Spring Boot on the classpath, so Sentry takes the same | ||
| * path as in a WAR. Tomcat starts once per test JVM. | ||
| */ | ||
| object TomcatApp { | ||
| val server = MockSentryServer() | ||
|
|
||
| init { | ||
| System.setProperty("sentry.dsn", server.dsn) | ||
| // The profiler rejects a traces path with a dot anywhere in it, which the module's absolute | ||
| // path can have. | ||
| System.setProperty( | ||
| "sentry.profiling-traces-dir-path", | ||
| "${System.getProperty("java.io.tmpdir")}/sentry-integration-test/profiling-traces", | ||
| ) | ||
| } | ||
|
|
||
| private val tomcat = | ||
| Tomcat().apply { | ||
| setBaseDir(Files.createTempDirectory("tomcat").toString()) | ||
| setPort(0) | ||
| // Creates the default connector. | ||
| connector | ||
| val context = addContext("", Files.createTempDirectory("docbase").toString()) | ||
| // As Tomcat does for a WAR, runs each initializer the classpath registers: Spring's starts | ||
| // AppInitializer's app, and Sentry's adds SentrySpringFilter. Only Spring's uses the set. | ||
| ServiceLoader.load(ServletContainerInitializer::class.java).forEach { | ||
| context.addServletContainerInitializer(it, setOf(AppInitializer::class.java)) | ||
| } | ||
| start() | ||
| } | ||
|
|
||
| val restTemplate = | ||
| RestTemplate().apply { | ||
| uriTemplateHandler = | ||
| DefaultUriBuilderFactory("http://localhost:${tomcat.connector.localPort}") | ||
| // Returns error responses rather than throwing them, so tests can check a failed request. | ||
| errorHandler = | ||
| object : DefaultResponseErrorHandler() { | ||
| override fun hasError(response: ClientHttpResponse): Boolean = false | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with this PR, no more python needed for spring 7!