From de95bb0728e5d5b9611db21a132e5b0dac565e14 Mon Sep 17 00:00:00 2001 From: Renette Ros Date: Wed, 8 Jan 2025 09:00:34 +0200 Subject: [PATCH] Fix failing Spring 6 tests --- .../Spring6ServerAnnotatedInstrumentationTest.java | 6 ++++++ .../Spring6ServerFunctionalInstrumentationTest.java | 5 +++++ .../agent/springwebflux/Spring6ServletContainerTest.java | 6 ++++++ .../springwebflux/AbstractServerInstrumentationTest.java | 9 +++++++-- .../apm/agent/springwebflux/ServletContainerTest.java | 3 ++- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java index b30ca5b06f..e8573ff2b5 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java @@ -19,6 +19,7 @@ package co.elastic.apm.agent.springwebflux; import co.elastic.apm.agent.testutils.Java17OnlyTest; +import org.junit.jupiter.api.BeforeEach; public class Spring6ServerAnnotatedInstrumentationTest extends Java17OnlyTest { @@ -27,5 +28,10 @@ public Spring6ServerAnnotatedInstrumentationTest() { } public static class Impl extends ServerAnnotatedInstrumentationTest { + + @BeforeEach + void setUp() { + expectedFrameworkVersion = "6.2.0"; + } } } diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerFunctionalInstrumentationTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerFunctionalInstrumentationTest.java index c593194b20..552cdab016 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerFunctionalInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerFunctionalInstrumentationTest.java @@ -19,6 +19,7 @@ package co.elastic.apm.agent.springwebflux; import co.elastic.apm.agent.testutils.Java17OnlyTest; +import org.junit.jupiter.api.BeforeEach; public class Spring6ServerFunctionalInstrumentationTest extends Java17OnlyTest { @@ -27,5 +28,9 @@ public Spring6ServerFunctionalInstrumentationTest() { } public static class Impl extends ServerFunctionalInstrumentationTest { + @BeforeEach + void setUp() { + expectedFrameworkVersion = "6.2.0"; + } } } diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServletContainerTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServletContainerTest.java index a62c7a2e4b..bbb72e829b 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServletContainerTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServletContainerTest.java @@ -18,9 +18,15 @@ */ package co.elastic.apm.agent.springwebflux; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.JRE; @EnabledForJreRange(min = JRE.JAVA_17) public class Spring6ServletContainerTest extends ServletContainerTest { + + @BeforeEach + void setUp() { + expectedFrameworkVersion = "6.2.0"; + } } diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java index a9f51f17bb..fe5d641a1e 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java @@ -58,6 +58,7 @@ public abstract class AbstractServerInstrumentationTest extends AbstractInstrume private static final String BASIC_AUTH_HEADER_VALUE = "Basic ZWxhc3RpYzpjaGFuZ2VtZQ=="; protected static WebFluxApplication.App app; + protected String expectedFrameworkVersion = "5.3.30"; protected GreetingWebClient client; @BeforeAll @@ -451,7 +452,11 @@ protected ErrorCaptureImpl getFirstError() { return reporter.getFirstError(200); } - static TransactionImpl checkTransaction(TransactionImpl transaction, String expectedName, String expectedMethod, int expectedStatus) { + TransactionImpl checkTransaction(TransactionImpl transaction, String expectedName, String expectedMethod, int expectedStatus) { + return checkTransaction(transaction, expectedName, expectedMethod, expectedStatus, expectedFrameworkVersion); + } + + static TransactionImpl checkTransaction(TransactionImpl transaction, String expectedName, String expectedMethod, int expectedStatus, String expectedFrameworkVersion) { assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getNameAsString()).isEqualTo(expectedName); @@ -468,7 +473,7 @@ static TransactionImpl checkTransaction(TransactionImpl transaction, String expe .isEqualTo("Spring Webflux"); assertThat(transaction.getFrameworkVersion()) - .isEqualTo("5.3.30"); + .isEqualTo(expectedFrameworkVersion); return transaction; } diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/ServletContainerTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/ServletContainerTest.java index f1c1c75e9c..23cd8d9432 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/ServletContainerTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/ServletContainerTest.java @@ -34,6 +34,7 @@ public class ServletContainerTest extends AbstractInstrumentationTest { protected static WebFluxApplication.App app; protected static GreetingWebClient client; + protected String expectedFrameworkVersion = "5.3.30"; @BeforeAll static void startApp() { @@ -74,7 +75,7 @@ void shouldOnlyCreateOneTransaction() throws InterruptedException { TransactionImpl transaction = reporter.getFirstTransaction(200); // transaction naming should be set by webflux instrumentation - AbstractServerInstrumentationTest.checkTransaction(transaction, "GET /functional/with-parameters/{id}", "GET", 200); + AbstractServerInstrumentationTest.checkTransaction(transaction, "GET /functional/with-parameters/{id}", "GET", 200, expectedFrameworkVersion); // transaction HTTP part should be provided by servlet instrumentation AbstractServerInstrumentationTest.checkUrl(client, transaction, "/with-parameters/42");