From 3221e8ef3422e609bd31db5ac4d12c73e5bd1de4 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 17 Sep 2021 10:21:25 +0300 Subject: [PATCH] Make @TestProfile work with integration tests Fixes: #20205 --- .../org/acme/quickstart/lra/AppTestProfile.java | 14 ++++++++++++++ .../acme/quickstart/lra/LRAParticipantTest.java | 4 ++-- .../quickstart/lra/LRAParticipantTestNativeIT.java | 2 ++ .../junit/QuarkusIntegrationTestExtension.java | 5 ++++- .../junit/QuarkusMainIntegrationTestExtension.java | 6 ++++-- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/AppTestProfile.java diff --git a/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/AppTestProfile.java b/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/AppTestProfile.java new file mode 100644 index 0000000000000..767def4dbccee --- /dev/null +++ b/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/AppTestProfile.java @@ -0,0 +1,14 @@ +package org.acme.quickstart.lra; + +import java.util.List; + +import io.quarkus.test.junit.QuarkusTestProfile; + +// we use a QuarkusTestProfile to ensure that QuarkusIntegrationTest works properly with them +public class AppTestProfile implements QuarkusTestProfile { + + @Override + public List testResources() { + return List.of(new TestResourceEntry(LRAParticipantTestResourceLifecycle.class)); + } +} diff --git a/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/LRAParticipantTest.java b/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/LRAParticipantTest.java index 7e2a4ec86344f..b915e1e3927bc 100644 --- a/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/LRAParticipantTest.java +++ b/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/LRAParticipantTest.java @@ -19,13 +19,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.common.http.TestHTTPEndpoint; import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; import io.restassured.response.Response; @QuarkusTest -@QuarkusTestResource(LRAParticipantTestResourceLifecycle.class) +@TestProfile(AppTestProfile.class) @TestHTTPEndpoint(TransactionalResource.class) public class LRAParticipantTest { private String coordinatorEndpoint; diff --git a/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/LRAParticipantTestNativeIT.java b/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/LRAParticipantTestNativeIT.java index 23bc259419cda..9d4b78bf1e3b9 100644 --- a/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/LRAParticipantTestNativeIT.java +++ b/integration-tests/narayana-lra/src/test/java/org/acme/quickstart/lra/LRAParticipantTestNativeIT.java @@ -1,7 +1,9 @@ package org.acme.quickstart.lra; import io.quarkus.test.junit.QuarkusIntegrationTest; +import io.quarkus.test.junit.TestProfile; @QuarkusIntegrationTest +@TestProfile(AppTestProfile.class) public class LRAParticipantTestNativeIT extends LRAParticipantTest { } 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 fdccc6794d873..4aee12aea1add 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 @@ -4,6 +4,7 @@ import static io.quarkus.test.junit.IntegrationTestUtil.determineTestProfileAndProperties; import static io.quarkus.test.junit.IntegrationTestUtil.doProcessTestInstance; import static io.quarkus.test.junit.IntegrationTestUtil.ensureNoInjectAnnotationIsUsed; +import static io.quarkus.test.junit.IntegrationTestUtil.getAdditionalTestResources; import static io.quarkus.test.junit.IntegrationTestUtil.getSysPropsToRestore; import static io.quarkus.test.junit.IntegrationTestUtil.handleDevServices; import static io.quarkus.test.junit.IntegrationTestUtil.readQuarkusArtifactProperties; @@ -132,7 +133,9 @@ private IntegrationTestExtensionState doProcessStart(Properties quarkusArtifactP TestProfileAndProperties testProfileAndProperties = determineTestProfileAndProperties(profile, sysPropRestore); testResourceManager = new TestResourceManager(requiredTestClass, quarkusTestProfile, - Collections.emptyList(), testProfileAndProperties.testProfile != null + getAdditionalTestResources(testProfileAndProperties.testProfile, + context.getRequiredTestClass().getClassLoader()), + testProfileAndProperties.testProfile != null && testProfileAndProperties.testProfile.disableGlobalTestResources(), devServicesProps); testResourceManager.init(); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java index 0b0460685efb3..05520715721a7 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java @@ -2,6 +2,7 @@ import static io.quarkus.test.junit.IntegrationTestUtil.determineBuildOutputDirectory; import static io.quarkus.test.junit.IntegrationTestUtil.determineTestProfileAndProperties; +import static io.quarkus.test.junit.IntegrationTestUtil.getAdditionalTestResources; import static io.quarkus.test.junit.IntegrationTestUtil.getSysPropsToRestore; import static io.quarkus.test.junit.IntegrationTestUtil.handleDevServices; import static io.quarkus.test.junit.IntegrationTestUtil.readQuarkusArtifactProperties; @@ -9,7 +10,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -114,7 +114,9 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S TestProfileAndProperties testProfileAndProperties = determineTestProfileAndProperties(profile, sysPropRestore); testResourceManager = new TestResourceManager(requiredTestClass, profile, - Collections.emptyList(), testProfileAndProperties.testProfile != null + getAdditionalTestResources(testProfileAndProperties.testProfile, + context.getRequiredTestClass().getClassLoader()), + testProfileAndProperties.testProfile != null && testProfileAndProperties.testProfile.disableGlobalTestResources()); testResourceManager.init(); Map additionalProperties = new HashMap<>(testProfileAndProperties.properties);