From 4c41b4bf63a258b36f7b96876ddd1ec2ad945e14 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 2 Aug 2022 12:39:11 +0300 Subject: [PATCH] Ensure that dev services properties are cleared in QuarkusIntegrationTestExtension This is needed to ensure the subsequent tests that need to relaunch dev-services because of the use a different test profile Fixes: #27075 (cherry picked from commit a6a2c5dd61e2db23343e895397b627d8e63cc32d) --- .../io/quarkus/it/mongodb/DummyTestProfile.java | 6 ++++++ .../it/mongodb/OtherProfileBookResourceIT.java | 7 +++++++ .../it/mongodb/OtherProfileBookResourceTest.java | 16 ++++++++++++++++ .../quarkus/test/junit/NativeTestExtension.java | 3 +++ .../junit/QuarkusIntegrationTestExtension.java | 6 +++++- 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/DummyTestProfile.java create mode 100644 integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/OtherProfileBookResourceIT.java create mode 100644 integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/OtherProfileBookResourceTest.java diff --git a/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/DummyTestProfile.java b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/DummyTestProfile.java new file mode 100644 index 0000000000000..258dded7b209c --- /dev/null +++ b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/DummyTestProfile.java @@ -0,0 +1,6 @@ +package io.quarkus.it.mongodb; + +import io.quarkus.test.junit.QuarkusTestProfile; + +public class DummyTestProfile implements QuarkusTestProfile { +} diff --git a/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/OtherProfileBookResourceIT.java b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/OtherProfileBookResourceIT.java new file mode 100644 index 0000000000000..1c16236d13fd2 --- /dev/null +++ b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/OtherProfileBookResourceIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.mongodb; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class OtherProfileBookResourceIT extends OtherProfileBookResourceTest { +} diff --git a/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/OtherProfileBookResourceTest.java b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/OtherProfileBookResourceTest.java new file mode 100644 index 0000000000000..64dc02f9e6724 --- /dev/null +++ b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/OtherProfileBookResourceTest.java @@ -0,0 +1,16 @@ +package io.quarkus.it.mongodb; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; + +@QuarkusTest +@TestProfile(DummyTestProfile.class) +public class OtherProfileBookResourceTest { + + @Test + public void testBlockingClient() { + Utils.callTheEndpoint("/books"); + } +} diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/NativeTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/NativeTestExtension.java index 7bad1f6b6cd01..972ff677683f1 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/NativeTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/NativeTestExtension.java @@ -120,6 +120,9 @@ private IntegrationTestExtensionState doNativeStart(ExtensionContext context, Cl Class requiredTestClass = context.getRequiredTestClass(); Map sysPropRestore = getSysPropsToRestore(); + for (String devServicesProp : devServicesProps.keySet()) { + sysPropRestore.put(devServicesProp, null); // used to signal that the property needs to be cleared + } TestProfileAndProperties testProfileAndProperties = determineTestProfileAndProperties(profile, sysPropRestore); testResourceManager = new TestResourceManager(requiredTestClass, quarkusTestProfile, diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java index 6537d1b7867bb..4bcd6ddcc43ee 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java @@ -149,6 +149,9 @@ private IntegrationTestExtensionState doProcessStart(Properties quarkusArtifactP Class requiredTestClass = context.getRequiredTestClass(); Map sysPropRestore = getSysPropsToRestore(); + for (String devServicesProp : devServicesProps.keySet()) { + sysPropRestore.put(devServicesProp, null); // used to signal that the property needs to be cleared + } TestProfileAndProperties testProfileAndProperties = determineTestProfileAndProperties(profile, sysPropRestore); testResourceManager = new TestResourceManager(requiredTestClass, quarkusTestProfile, @@ -175,7 +178,8 @@ private IntegrationTestExtensionState doProcessStart(Properties quarkusArtifactP System.setProperty(i.getKey(), i.getValue()); } } - context.getStore(ExtensionContext.Namespace.GLOBAL).put(QuarkusIntegrationTestExtension.class.getName() + ".systemProps", + context.getStore(ExtensionContext.Namespace.GLOBAL).put( + QuarkusIntegrationTestExtension.class.getName() + ".systemProps", new ExtensionContext.Store.CloseableResource() { @Override public void close() throws Throwable {