This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch 2.13.x in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 8f4bd39223b500315fe10a6df7cccfcfddb1dcfe Author: JiriOndrusek <ondrusek.j...@gmail.com> AuthorDate: Wed Feb 15 10:08:20 2023 +0100 CamelQuarkusTestSupport: Lifecycle.PER_CLASS may cause following tests to fail #4569 --- .../DoubleRoutesPerClassTest.java | 61 ++++++++++++++++++++++ .../doubeRouteBuilderPerClass/FirstPerClassET.java | 60 +++++++++++++++++++++ .../RouteBuilderPerClass.java} | 26 +++------ .../SecondPerClassET.java | 60 +++++++++++++++++++++ .../camel/quarkus/test/AfterAllCallback.java | 6 ++- .../quarkus/test/CamelQuarkusTestSupport.java | 9 +++- .../test/common/CallbacksPerTestFalse02Test.java | 2 +- .../test/common/CallbacksPerTestTrue02Test.java | 2 +- .../AdviceInDoBeforeEachMethodsTest.java | 2 +- 9 files changed, 202 insertions(+), 26 deletions(-) diff --git a/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/DoubleRoutesPerClassTest.java b/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/DoubleRoutesPerClassTest.java new file mode 100644 index 0000000000..77baa4a278 --- /dev/null +++ b/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/DoubleRoutesPerClassTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.test.extensions.doubeRouteBuilderPerClass; + +import java.util.function.Supplier; + +import io.quarkus.test.ContinuousTestingTestUtils; +import io.quarkus.test.QuarkusDevModeTest; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +/** + * Test for https://github.com/apache/camel-quarkus/issues/4560 + */ +public class DoubleRoutesPerClassTest { + + @RegisterExtension + static final QuarkusDevModeTest TEST = new QuarkusDevModeTest() + .setArchiveProducer(new Supplier<>() { + @Override + public JavaArchive get() { + return ShrinkWrap.create(JavaArchive.class).addClass(RouteBuilderPerClass.class) + .add(new StringAsset( + ContinuousTestingTestUtils.appProperties("#")), + "application.properties"); + } + }) + .setTestArchiveProducer(new Supplier<>() { + @Override + public JavaArchive get() { + return ShrinkWrap.create(JavaArchive.class).addClasses(FirstPerClassET.class, SecondPerClassET.class); + } + }); + + @Test + public void checkTests() { + ContinuousTestingTestUtils utils = new ContinuousTestingTestUtils(); + ContinuousTestingTestUtils.TestStatus ts = utils.waitForNextCompletion(); + + Assertions.assertEquals(0L, ts.getTestsFailed()); + Assertions.assertEquals(4L, ts.getTestsPassed()); + } +} diff --git a/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/FirstPerClassET.java b/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/FirstPerClassET.java new file mode 100644 index 0000000000..759236ad4f --- /dev/null +++ b/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/FirstPerClassET.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.test.extensions.doubeRouteBuilderPerClass; + +import io.quarkus.test.junit.QuarkusTest; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.quarkus.test.CamelQuarkusTestSupport; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +@QuarkusTest +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class FirstPerClassET extends CamelQuarkusTestSupport { + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:startTest").to("direct:start").to("mock:result"); + } + }; + } + + @Test + public void someTestA() throws InterruptedException { + MockEndpoint mockEndpoint = getMockEndpoint("mock:result"); + mockEndpoint.expectedBodiesReceived("Some Value"); + + template.sendBody("direct:startTest", null); + + mockEndpoint.assertIsSatisfied(); + } + + @Test + public void someTestB() throws InterruptedException { + MockEndpoint mockEndpoint = getMockEndpoint("mock:result"); + mockEndpoint.expectedBodiesReceived("Some Value"); + + template.sendBody("direct:startTest", null); + + mockEndpoint.assertIsSatisfied(); + } +} diff --git a/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestTrue02Test.java b/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/RouteBuilderPerClass.java similarity index 53% copy from test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestTrue02Test.java copy to test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/RouteBuilderPerClass.java index 472d5d319f..a33b1d2b3e 100644 --- a/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestTrue02Test.java +++ b/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/RouteBuilderPerClass.java @@ -14,27 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.test.common; +package org.apache.camel.quarkus.test.extensions.doubeRouteBuilderPerClass; -import java.util.concurrent.TimeUnit; - -import io.quarkus.test.junit.QuarkusTest; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; - -import static org.awaitility.Awaitility.await; - -// replaces CreateCamelContextPerTestTrueTest -@QuarkusTest -public class CallbacksPerTestTrue02Test { - - @Test - public void testAfter01Class() { - - await().atMost(5, TimeUnit.SECONDS).until(() -> AbstractCallbacksTest.testFromAnotherClass( - CallbacksPerTestTrue02Test.class.getSimpleName(), - CallbacksPerTestTrue01Test.createAssertionConsumer()), - Matchers.is(AbstractCallbacksTest.Callback.values().length)); +public class RouteBuilderPerClass extends org.apache.camel.builder.RouteBuilder { + @Override + public void configure() throws Exception { + from("direct:start").setBody(constant("Some Value")).log("The body is: ${body}"); + from("timer:timeToAct?period=5000").routeId("TimerRoute").log("Calling direct:start").to("direct:start"); } } diff --git a/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/SecondPerClassET.java b/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/SecondPerClassET.java new file mode 100644 index 0000000000..563ebc565f --- /dev/null +++ b/test-framework/junit5-extension-tests/src/test/java/org/apache/camel/quarkus/test/extensions/doubeRouteBuilderPerClass/SecondPerClassET.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.test.extensions.doubeRouteBuilderPerClass; + +import io.quarkus.test.junit.QuarkusTest; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.quarkus.test.CamelQuarkusTestSupport; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +@QuarkusTest +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class SecondPerClassET extends CamelQuarkusTestSupport { + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:startTest").to("direct:start").to("mock:result"); + } + }; + } + + @Test + public void someTestA() throws InterruptedException { + MockEndpoint mockEndpoint = getMockEndpoint("mock:result"); + mockEndpoint.expectedBodiesReceived("Some Value"); + + template.sendBody("direct:startTest", null); + + mockEndpoint.assertIsSatisfied(); + } + + @Test + public void someTestB() throws InterruptedException { + MockEndpoint mockEndpoint = getMockEndpoint("mock:result"); + mockEndpoint.expectedBodiesReceived("Some Value"); + + template.sendBody("direct:startTest", null); + + mockEndpoint.assertIsSatisfied(); + } +} diff --git a/test-framework/junit5/src/main/java/org/apache/camel/quarkus/test/AfterAllCallback.java b/test-framework/junit5/src/main/java/org/apache/camel/quarkus/test/AfterAllCallback.java index f6cb1f84be..ca01e45172 100644 --- a/test-framework/junit5/src/main/java/org/apache/camel/quarkus/test/AfterAllCallback.java +++ b/test-framework/junit5/src/main/java/org/apache/camel/quarkus/test/AfterAllCallback.java @@ -18,6 +18,7 @@ package org.apache.camel.quarkus.test; import io.quarkus.test.junit.callback.QuarkusTestAfterAllCallback; import io.quarkus.test.junit.callback.QuarkusTestContext; +import org.junit.jupiter.api.extension.ExtensionContext; public class AfterAllCallback implements QuarkusTestAfterAllCallback { @@ -27,7 +28,10 @@ public class AfterAllCallback implements QuarkusTestAfterAllCallback { CamelQuarkusTestSupport testInstance = (CamelQuarkusTestSupport) context.getTestInstance(); if (CallbackUtil.isPerClass(testInstance)) { - testInstance.internalAfterAll(context); + ExtensionContext mockContext = new CallbackUtil.MockExtensionContext(CallbackUtil.getLifecycle(testInstance), + null); + + testInstance.internalAfterAll(context, mockContext); CallbackUtil.resetContext(testInstance); } diff --git a/test-framework/junit5/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java b/test-framework/junit5/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java index 50f6bd9c6e..eea4e71d43 100644 --- a/test-framework/junit5/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java +++ b/test-framework/junit5/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java @@ -282,10 +282,15 @@ public class CamelQuarkusTestSupport extends CamelTestSupport } } - void internalAfterAll(QuarkusTestContext context) { + void internalAfterAll(QuarkusTestContext context, ExtensionContext extensionContext) { try { - doPostTearDown(); + if (isCreateCamelContextPerClass()) { + super.afterAll(extensionContext); + } else { + doPostTearDown(); + } cleanupResources(); + } catch (Exception e) { // ignore } diff --git a/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestFalse02Test.java b/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestFalse02Test.java index 9bb7834a79..cfd85fff3e 100644 --- a/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestFalse02Test.java +++ b/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestFalse02Test.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import static org.awaitility.Awaitility.await; -// replaces CreateCamelContextPerTestTrueTest +// requires CallbacksPerTestFalse01Test to be run before @QuarkusTest public class CallbacksPerTestFalse02Test { diff --git a/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestTrue02Test.java b/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestTrue02Test.java index 472d5d319f..9bcf600cdb 100644 --- a/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestTrue02Test.java +++ b/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/common/CallbacksPerTestTrue02Test.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import static org.awaitility.Awaitility.await; -// replaces CreateCamelContextPerTestTrueTest +// requires CallbacksPerTestTrue01Test to be run before @QuarkusTest public class CallbacksPerTestTrue02Test { diff --git a/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/userTestCases/AdviceInDoBeforeEachMethodsTest.java b/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/userTestCases/AdviceInDoBeforeEachMethodsTest.java index d3df9b6662..1c27fcf7e8 100644 --- a/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/userTestCases/AdviceInDoBeforeEachMethodsTest.java +++ b/test-framework/junit5/src/test/java/org/apache/camel/quarkus/test/userTestCases/AdviceInDoBeforeEachMethodsTest.java @@ -52,7 +52,7 @@ public class AdviceInDoBeforeEachMethodsTest extends CamelQuarkusTestSupport { public void configure() { from("direct:start") .routeId("sampleRoute") - .to("file:samples/"); + .to("file:target/samples/"); } }; }