-
-
Notifications
You must be signed in to change notification settings - Fork 465
Add E2E tests for the spring sample #4640
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b2c1466
Add E2E tests for the spring sample
alexander-alderman-webb f50e57b
Apply spotless and revert controller logic change
alexander-alderman-webb d4492cc
merge commit
alexander-alderman-webb b26c940
Revert target JVM version
alexander-alderman-webb 028237d
Merge branch 'main' into webb/e2e_tests_spring
alexander-alderman-webb acdd35e
set source compat version to jdk 8 as well
adinauer 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,65 +1,90 @@ | ||
| import org.jetbrains.kotlin.config.KotlinCompilerVersion | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
| import org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.springboot2) apply false | ||
| alias(libs.plugins.spring.dependency.management) | ||
| alias(libs.plugins.kotlin.jvm) | ||
| alias(libs.plugins.kotlin.spring) | ||
| id("war") | ||
| alias(libs.plugins.gretty) | ||
| application | ||
| alias(libs.plugins.springboot2) apply false | ||
| alias(libs.plugins.spring.dependency.management) | ||
| alias(libs.plugins.kotlin.jvm) | ||
| alias(libs.plugins.kotlin.spring) | ||
| id("war") | ||
| alias(libs.plugins.gretty) | ||
| } | ||
|
|
||
| application { mainClass.set("io.sentry.samples.spring.Main") } | ||
|
|
||
| // Ensure WAR is up to date before run task | ||
| tasks.named("run") { dependsOn(tasks.named("war")) } | ||
|
|
||
| group = "io.sentry.sample.spring" | ||
|
|
||
| version = "0.0.1-SNAPSHOT" | ||
|
|
||
| java { | ||
| sourceCompatibility = JavaVersion.VERSION_1_8 | ||
| targetCompatibility = JavaVersion.VERSION_1_8 | ||
| sourceCompatibility = JavaVersion.VERSION_1_8 | ||
| targetCompatibility = JavaVersion.VERSION_1_8 | ||
| } | ||
|
|
||
| spotless { | ||
| kotlinGradle { | ||
| // This file throws an unclear error | ||
| targetExclude("build.gradle.kts") | ||
| } | ||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
| repositories { mavenCentral() } | ||
|
|
||
| dependencyManagement { | ||
| imports { | ||
| mavenBom(BOM_COORDINATES) | ||
| } | ||
| imports { | ||
| mavenBom(BOM_COORDINATES) | ||
| mavenBom(libs.kotlin.bom.get().toString()) | ||
| mavenBom(libs.jackson.bom.get().toString()) | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(Config.Libs.springWeb) | ||
| implementation(Config.Libs.springAop) | ||
| implementation(Config.Libs.aspectj) | ||
| implementation(Config.Libs.springSecurityWeb) | ||
| implementation(Config.Libs.springSecurityConfig) | ||
| implementation(Config.Libs.kotlinReflect) | ||
| implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION)) | ||
| implementation(projects.sentrySpring) | ||
| implementation(projects.sentryLogback) | ||
| implementation(libs.logback.classic) | ||
| implementation(libs.servlet.api) | ||
| testImplementation(libs.springboot.starter.test) { | ||
| exclude(group = "org.junit.vintage", module = "junit-vintage-engine") | ||
| } | ||
| } | ||
| implementation(Config.Libs.springWeb) | ||
| implementation(Config.Libs.springAop) | ||
| implementation(Config.Libs.aspectj) | ||
| implementation(Config.Libs.springSecurityWeb) | ||
| implementation(Config.Libs.springSecurityConfig) | ||
| implementation(Config.Libs.kotlinReflect) | ||
| implementation(kotlin(Config.kotlinStdLib)) | ||
| implementation(projects.sentrySpring) | ||
| implementation(projects.sentryLogback) | ||
| implementation(libs.jackson.databind) | ||
| implementation(libs.logback.classic) | ||
| implementation(libs.servlet.api) | ||
|
|
||
| tasks.withType<Test>().configureEach { | ||
| useJUnitPlatform() | ||
| implementation(libs.tomcat.catalina) | ||
| implementation(libs.tomcat.embed.jasper) | ||
|
|
||
| testImplementation(projects.sentrySystemTestSupport) | ||
| testImplementation(libs.kotlin.test.junit) | ||
| testImplementation(libs.springboot.starter.test) { | ||
| exclude(group = "org.junit.vintage", module = "junit-vintage-engine") | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<KotlinCompile>().configureEach { | ||
| kotlin { | ||
| compilerOptions.freeCompilerArgs = listOf("-Xjsr305=strict") | ||
| compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 | ||
| } | ||
| kotlin { | ||
| compilerOptions.freeCompilerArgs = listOf("-Xjsr305=strict") | ||
| compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 | ||
| } | ||
| } | ||
|
|
||
| configure<SourceSetContainer> { test { java.srcDir("src/test/java") } } | ||
|
|
||
| tasks.register<Test>("systemTest").configure { | ||
| group = "verification" | ||
| description = "Runs the System tests" | ||
|
|
||
| outputs.upToDateWhen { false } | ||
|
|
||
| maxParallelForks = 1 | ||
|
|
||
| // Cap JVM args per test | ||
| minHeapSize = "128m" | ||
| maxHeapSize = "1g" | ||
|
|
||
| filter { includeTestsMatching("io.sentry.systemtest*") } | ||
| } | ||
|
|
||
| tasks.named("test").configure { | ||
| require(this is Test) | ||
|
|
||
| filter { excludeTestsMatching("io.sentry.systemtest.*") } | ||
| } |
32 changes: 32 additions & 0 deletions
32
sentry-samples/sentry-samples-spring/src/main/java/io/sentry/samples/spring/Main.java
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,32 @@ | ||
| package io.sentry.samples.spring; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import org.apache.catalina.LifecycleException; | ||
| import org.apache.catalina.startup.Tomcat; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) throws LifecycleException, IOException { | ||
| File webappsDirectory = new File("./tomcat.8080/webapps"); | ||
| if (!webappsDirectory.exists()) { | ||
| boolean didCreateDirectories = webappsDirectory.mkdirs(); | ||
| if (!didCreateDirectories) { | ||
| throw new RuntimeException( | ||
| "Failed to create directory required by Tomcat: " + webappsDirectory.getAbsolutePath()); | ||
| } | ||
| } | ||
|
|
||
| String pathToWar = "./build/libs"; | ||
| String warName = "sentry-samples-spring-0.0.1-SNAPSHOT"; | ||
| File war = new File(pathToWar + "/" + warName + ".war"); | ||
|
|
||
| Tomcat tomcat = new Tomcat(); | ||
| tomcat.setPort(8080); | ||
| tomcat.getConnector(); | ||
|
|
||
| tomcat.addWebapp("/" + warName, war.getCanonicalPath()); | ||
| tomcat.start(); | ||
| tomcat.getServer().await(); | ||
| } | ||
| } |
7 changes: 6 additions & 1 deletion
7
sentry-samples/sentry-samples-spring/src/main/java/io/sentry/samples/spring/web/Person.java
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: 12 additions & 0 deletions
12
sentry-samples/sentry-samples-spring/src/test/kotlin/io/sentry/DummyTest.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,12 @@ | ||
| package io.sentry | ||
|
|
||
| import kotlin.test.Test | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class DummyTest { | ||
| @Test | ||
| fun `the only test`() { | ||
| // only needed to have more than 0 tests and not fail the build | ||
| assertTrue(true) | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
...ry-samples/sentry-samples-spring/src/test/kotlin/io/sentry/systemtest/PersonSystemTest.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,46 @@ | ||
| package io.sentry.systemtest | ||
|
|
||
| import io.sentry.systemtest.util.TestHelper | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import org.junit.Before | ||
|
|
||
| class PersonSystemTest { | ||
| lateinit var testHelper: TestHelper | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| testHelper = TestHelper("http://localhost:8080/sentry-samples-spring-0.0.1-SNAPSHOT") | ||
| testHelper.reset() | ||
| } | ||
|
|
||
| @Test | ||
| fun `get person fails`() { | ||
| val restClient = testHelper.restClient | ||
| restClient.getPerson(11L) | ||
| assertEquals(500, restClient.lastKnownStatusCode) | ||
|
|
||
| testHelper.ensureTransactionReceived { transaction, envelopeHeader -> | ||
| testHelper.doesTransactionHaveOp(transaction, "http.server") | ||
| } | ||
|
|
||
| Thread.sleep(10000) | ||
|
|
||
| testHelper.ensureLogsReceived { logs, envelopeHeader -> | ||
| testHelper.doesContainLogWithBody(logs, "warn Sentry logging") && | ||
| testHelper.doesContainLogWithBody(logs, "error Sentry logging") && | ||
| testHelper.doesContainLogWithBody(logs, "hello there world!") | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `create person works`() { | ||
| val restClient = testHelper.restClient | ||
| val person = Person("firstA", "lastB") | ||
| val returnedPerson = restClient.createPerson(person) | ||
| assertEquals(200, restClient.lastKnownStatusCode) | ||
|
|
||
| assertEquals(person.firstName, returnedPerson!!.firstName) | ||
| assertEquals(person.lastName, returnedPerson!!.lastName) | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -9,12 +9,12 @@ plugins { | |
| } | ||
|
|
||
| configure<JavaPluginExtension> { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| sourceCompatibility = JavaVersion.VERSION_1_8 | ||
| targetCompatibility = JavaVersion.VERSION_1_8 | ||
| } | ||
|
|
||
| tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach { | ||
| compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 | ||
| compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Java Compatibility Mismatch Causes Compilation FailuresThe |
||
| compilerOptions.languageVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9 | ||
| compilerOptions.apiVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9 | ||
| } | ||
|
|
@@ -26,10 +26,8 @@ dependencies { | |
|
|
||
| compileOnly(libs.jetbrains.annotations) | ||
| compileOnly(libs.nopen.annotations) | ||
| compileOnly(libs.springboot3.starter.test) { | ||
| exclude(group = "org.junit.vintage", module = "junit-vintage-engine") | ||
| } | ||
| compileOnly(libs.springboot3.starter.web) | ||
|
|
||
| compileOnly(libs.springboot.starter.web) | ||
|
|
||
| implementation(libs.jackson.databind) | ||
| implementation(libs.jackson.kotlin) | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.