From 389e935f1903821b9cafc4e5a64e44736832b03a Mon Sep 17 00:00:00 2001 From: JinyuChen97 Date: Tue, 14 Jul 2026 15:12:59 +0100 Subject: [PATCH] Migrate Quarkus-interop tests from extensions/extensions-jvm to integration-tests/integration-tests-jvm Migrate QuarkusUnitTest-based tests that cover interoperability with Quarkus or non-Camel transitives out of the deployment modules and into their respective integration-tests modules using @QuarkusTest + @TestProfile, so that they can be exercised when running the test suite against alternate Quarkus platform BOMs. quartz (integration-tests/quartz): - Migrated: QuartzNotAutowiredTest, QuartzNoQuarkusSchedulerAutowiredTest, QuartzQuarkusSchedulerAutowiredTest, QuartzQuarkusSchedulerNotAutowiredTest, QuartzQuarkusCustomSchedulerAutowiredTest, QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest - Not migrated: QuartzQuarkusSchedulerAmbiguousAutowiredTest (startup failure asserted via setExpectedException, no @QuarkusTest equivalent) --- ...QuartzNoQuarkusSchedulerAutowiredTest.java | 44 ----------- .../deployment/QuartzNotAutowiredTest.java | 45 ----------- ...tzQuarkusCustomSchedulerAutowiredTest.java | 58 -------------- .../QuartzQuarkusSchedulerAutowiredTest.java | 45 ----------- ...hedulerAutowiredWithSchedulerBeanTest.java | 75 ------------------- ...uartzQuarkusSchedulerNotAutowiredTest.java | 45 ----------- ...ion-configuration-not-autowired.properties | 17 ----- ...quarkus-scheduler-not-autowired.properties | 18 ----- integration-tests/quartz/pom.xml | 1 - .../quartz/it/CustomSchedulerProducer.java | 44 +++++++++++ .../component/quartz/it/QuartzResource.java | 8 ++ .../quartz/it/QuartzSchedulerBeanProfile.java | 68 +++++++++++++++++ ...QuartzNoQuarkusSchedulerAutowiredTest.java | 48 ++++++++++++ .../quartz/it/QuartzNotAutowiredTest.java | 47 ++++++++++++ ...tzQuarkusCustomSchedulerAutowiredTest.java | 52 +++++++++++++ .../QuartzQuarkusSchedulerAutowiredTest.java | 47 ++++++++++++ ...hedulerAutowiredWithSchedulerBeanTest.java | 57 ++++++++++++++ ...uartzQuarkusSchedulerNotAutowiredTest.java | 49 ++++++++++++ 18 files changed, 420 insertions(+), 348 deletions(-) delete mode 100644 extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNoQuarkusSchedulerAutowiredTest.java delete mode 100644 extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNotAutowiredTest.java delete mode 100644 extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusCustomSchedulerAutowiredTest.java delete mode 100644 extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredTest.java delete mode 100644 extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest.java delete mode 100644 extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerNotAutowiredTest.java delete mode 100644 extensions/quartz/deployment/src/test/resources/application-configuration-not-autowired.properties delete mode 100644 extensions/quartz/deployment/src/test/resources/application-configuration-quarkus-scheduler-not-autowired.properties create mode 100644 integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/CustomSchedulerProducer.java create mode 100644 integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/QuartzSchedulerBeanProfile.java create mode 100644 integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzNoQuarkusSchedulerAutowiredTest.java create mode 100644 integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzNotAutowiredTest.java create mode 100644 integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusCustomSchedulerAutowiredTest.java create mode 100644 integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerAutowiredTest.java create mode 100644 integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest.java create mode 100644 integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerNotAutowiredTest.java diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNoQuarkusSchedulerAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNoQuarkusSchedulerAutowiredTest.java deleted file mode 100644 index be9bf21d6bd9..000000000000 --- a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNoQuarkusSchedulerAutowiredTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.component.quartz.deployment; - -import io.quarkus.test.QuarkusUnitTest; -import jakarta.inject.Inject; -import org.apache.camel.CamelContext; -import org.apache.camel.component.quartz.QuartzComponent; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class QuartzNoQuarkusSchedulerAutowiredTest { - - @RegisterExtension - static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() - .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); - - @Inject - CamelContext context; - - @Test - public void testQuarkusQuartzSchedulerNotAutowired() throws Exception { - QuartzComponent component = context.getComponent("quartz", QuartzComponent.class); - assertEquals("DefaultQuartzScheduler-camel-1", component.getScheduler().getSchedulerName()); - } -} diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNotAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNotAutowiredTest.java deleted file mode 100644 index 059ea2890a57..000000000000 --- a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNotAutowiredTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.component.quartz.deployment; - -import io.quarkus.test.QuarkusUnitTest; -import jakarta.inject.Inject; -import org.apache.camel.CamelContext; -import org.apache.camel.component.quartz.QuartzComponent; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class QuartzNotAutowiredTest { - - @RegisterExtension - static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() - .withConfigurationResource("application-configuration-not-autowired.properties") - .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); - - @Inject - CamelContext context; - - @Test - public void testQuarkusQuartzSchedulerNotAutowired() throws Exception { - QuartzComponent component = context.getComponent("quartz", QuartzComponent.class); - assertEquals("DefaultQuartzScheduler-camel-1", component.getScheduler().getSchedulerName()); - } -} diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusCustomSchedulerAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusCustomSchedulerAutowiredTest.java deleted file mode 100644 index 27bdaa2837a3..000000000000 --- a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusCustomSchedulerAutowiredTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.component.quartz.deployment; - -import java.util.Properties; - -import io.quarkus.test.QuarkusUnitTest; -import jakarta.enterprise.inject.Produces; -import jakarta.inject.Inject; -import org.apache.camel.CamelContext; -import org.apache.camel.component.quartz.QuartzComponent; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.quartz.impl.StdSchedulerFactory; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class QuartzQuarkusCustomSchedulerAutowiredTest { - - @RegisterExtension - static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() - .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); - - @Inject - CamelContext context; - - @Test - public void testCustomSchedulerAutowired() throws Exception { - QuartzComponent component = context.getComponent("quartz", QuartzComponent.class); - assertEquals("customScheduler", component.getScheduler().getSchedulerName()); - } - - @Produces - public Scheduler produceScheduler() throws SchedulerException { - Properties prop = new Properties(); - prop.setProperty("org.quartz.scheduler.instanceName", "customScheduler"); - prop.setProperty("org.quartz.threadPool.threadCount", "2"); - return new StdSchedulerFactory(prop).getScheduler(); - } -} diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredTest.java deleted file mode 100644 index 55617f3eed29..000000000000 --- a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.component.quartz.deployment; - -import io.quarkus.test.QuarkusUnitTest; -import jakarta.inject.Inject; -import org.apache.camel.CamelContext; -import org.apache.camel.component.quartz.QuartzComponent; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class QuartzQuarkusSchedulerAutowiredTest { - - @RegisterExtension - static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() - .withConfigurationResource("application-configuration-quartz-scheduler.properties") - .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); - - @Inject - CamelContext context; - - @Test - public void testQuarkusSchedulerAutowired() throws Exception { - QuartzComponent component = context.getComponent("quartz", QuartzComponent.class); - assertEquals("QuarkusQuartzScheduler", component.getScheduler().getSchedulerName()); - } -} diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest.java deleted file mode 100644 index 20111e4b87d9..000000000000 --- a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.component.quartz.deployment; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import io.quarkus.scheduler.Scheduled; -import io.quarkus.test.QuarkusUnitTest; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; -import org.apache.camel.CamelContext; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.quartz.QuartzComponent; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest { - - @RegisterExtension - static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() - .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); - - @Inject - CamelContext context; - - private static final CountDownLatch quarkusQuartzLatch = new CountDownLatch(1); - private static final CountDownLatch camelQuartzLatch = new CountDownLatch(1); - - @Test - public void testQuarkusSchedulerAutowired() throws Exception { - QuartzComponent component = context.getComponent("quartz", QuartzComponent.class); - assertEquals("QuarkusQuartzScheduler", component.getScheduler().getSchedulerName()); - assertTrue(quarkusQuartzLatch.await(10, TimeUnit.SECONDS)); - assertTrue(camelQuartzLatch.await(10, TimeUnit.SECONDS)); - } - - @ApplicationScoped - static final class SchedulerBean { - @Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) - public void scheduledQuarkusJob() { - quarkusQuartzLatch.countDown(); - } - } - - @ApplicationScoped - static final class Routes extends RouteBuilder { - @Override - public void configure() throws Exception { - from("quartz://scheduledCamelJob?cron=0/1+*+*+*+*+?") - .process(exchange -> { - camelQuartzLatch.countDown(); - }); - } - } -} diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerNotAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerNotAutowiredTest.java deleted file mode 100644 index b1c6c08da151..000000000000 --- a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerNotAutowiredTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.component.quartz.deployment; - -import io.quarkus.test.QuarkusUnitTest; -import jakarta.inject.Inject; -import org.apache.camel.CamelContext; -import org.apache.camel.component.quartz.QuartzComponent; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class QuartzQuarkusSchedulerNotAutowiredTest { - - @RegisterExtension - static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() - .withConfigurationResource("application-configuration-quarkus-scheduler-not-autowired.properties") - .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); - - @Inject - CamelContext context; - - @Test - public void testQuarkusQuartzSchedulerNotAutowired() throws Exception { - QuartzComponent component = context.getComponent("quartz", QuartzComponent.class); - assertEquals("DefaultQuartzScheduler-camel-1", component.getScheduler().getSchedulerName()); - } -} diff --git a/extensions/quartz/deployment/src/test/resources/application-configuration-not-autowired.properties b/extensions/quartz/deployment/src/test/resources/application-configuration-not-autowired.properties deleted file mode 100644 index 54cddcf948d3..000000000000 --- a/extensions/quartz/deployment/src/test/resources/application-configuration-not-autowired.properties +++ /dev/null @@ -1,17 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- -camel.component.quartz.autowired-enabled = false \ No newline at end of file diff --git a/extensions/quartz/deployment/src/test/resources/application-configuration-quarkus-scheduler-not-autowired.properties b/extensions/quartz/deployment/src/test/resources/application-configuration-quarkus-scheduler-not-autowired.properties deleted file mode 100644 index 312f03092c38..000000000000 --- a/extensions/quartz/deployment/src/test/resources/application-configuration-quarkus-scheduler-not-autowired.properties +++ /dev/null @@ -1,18 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- -camel.component.quartz.autowired-enabled = false -quarkus.scheduler.start-mode=forced \ No newline at end of file diff --git a/integration-tests/quartz/pom.xml b/integration-tests/quartz/pom.xml index 3df5565d92a4..60b11fcd6f1d 100644 --- a/integration-tests/quartz/pom.xml +++ b/integration-tests/quartz/pom.xml @@ -65,7 +65,6 @@ - native diff --git a/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/CustomSchedulerProducer.java b/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/CustomSchedulerProducer.java new file mode 100644 index 000000000000..d26ca8f5ae6c --- /dev/null +++ b/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/CustomSchedulerProducer.java @@ -0,0 +1,44 @@ +/* + * 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.component.quartz.it; + +import java.util.Properties; + +import io.quarkus.arc.profile.IfBuildProfile; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Singleton; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.impl.StdSchedulerFactory; + +/** + * Produces a custom {@link Scheduler} bean active only under the + * {@code quartz-custom-scheduler} build profile (used by + * {@link org.apache.camel.quarkus.component.quartz.it.QuartzQuarkusCustomSchedulerAutowiredTest}). + */ +public class CustomSchedulerProducer { + + @Produces + @Singleton + @IfBuildProfile("quartz-custom-scheduler") + public Scheduler customScheduler() throws SchedulerException { + Properties props = new Properties(); + props.setProperty("org.quartz.scheduler.instanceName", "customScheduler"); + props.setProperty("org.quartz.threadPool.threadCount", "2"); + return new StdSchedulerFactory(props).getScheduler(); + } +} diff --git a/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/QuartzResource.java b/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/QuartzResource.java index 45f3b0b2716e..5b9ea0c4afa4 100644 --- a/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/QuartzResource.java +++ b/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/QuartzResource.java @@ -50,6 +50,14 @@ public QuartzComponent createQuartzFromProperties() { return new QuartzComponent(); } + @Path("/scheduler-name") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getSchedulerName() throws Exception { + QuartzComponent component = camelContext.getComponent("quartz", QuartzComponent.class); + return component.getScheduler().getSchedulerName(); + } + @Path("/getNameAndResult") @GET @Produces(MediaType.APPLICATION_JSON) diff --git a/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/QuartzSchedulerBeanProfile.java b/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/QuartzSchedulerBeanProfile.java new file mode 100644 index 000000000000..4ba334c0f54b --- /dev/null +++ b/integration-tests/quartz/src/main/java/org/apache/camel/quarkus/component/quartz/it/QuartzSchedulerBeanProfile.java @@ -0,0 +1,68 @@ +/* + * 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.component.quartz.it; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import io.quarkus.arc.profile.IfBuildProfile; +import io.quarkus.scheduler.Scheduled; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Singleton; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import org.apache.camel.builder.RouteBuilder; + +/** + * Beans active only under the {@code quartz-scheduler-bean} build profile, + * used by {@link org.apache.camel.quarkus.component.quartz.it.QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest}. + */ +@ApplicationScoped +@IfBuildProfile("quartz-scheduler-bean") +public class QuartzSchedulerBeanProfile { + + static final CountDownLatch QUARKUS_LATCH = new CountDownLatch(1); + static final CountDownLatch CAMEL_LATCH = new CountDownLatch(1); + + @Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) + void scheduledQuarkusJob() { + QUARKUS_LATCH.countDown(); + } + + @Singleton + @IfBuildProfile("quartz-scheduler-bean") + public static class Routes extends RouteBuilder { + @Override + public void configure() { + from("quartz://schedulerBeanCamelJob?cron=0/1+*+*+*+*+?") + .process(exchange -> CAMEL_LATCH.countDown()); + } + } + + @Path("/quartz/scheduler-bean") + public static class Resource { + @GET + @Path("/fired") + @Produces(MediaType.TEXT_PLAIN) + public boolean fired() throws InterruptedException { + return QUARKUS_LATCH.await(10, TimeUnit.SECONDS) + && CAMEL_LATCH.await(10, TimeUnit.SECONDS); + } + } +} diff --git a/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzNoQuarkusSchedulerAutowiredTest.java b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzNoQuarkusSchedulerAutowiredTest.java new file mode 100644 index 000000000000..df3bf7c90094 --- /dev/null +++ b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzNoQuarkusSchedulerAutowiredTest.java @@ -0,0 +1,48 @@ +/* + * 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.component.quartz.it; + +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.QuarkusTestProfile; +import io.quarkus.test.junit.TestProfile; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.startsWith; + +@QuarkusTest +@TestProfile(QuartzNoQuarkusSchedulerAutowiredTest.Profile.class) +class QuartzNoQuarkusSchedulerAutowiredTest { + + @Test + void testQuarkusQuartzSchedulerNotAutowired() { + RestAssured.get("/quartz/scheduler-name") + .then() + .statusCode(200) + .body(startsWith("DefaultQuartzScheduler")); + } + + public static class Profile implements QuarkusTestProfile { + @Override + public Map getConfigOverrides() { + return Map.of( + "camel.component.quartzFromProperties.propertiesFile", ""); + } + } +} diff --git a/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzNotAutowiredTest.java b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzNotAutowiredTest.java new file mode 100644 index 000000000000..a3e9b9185d48 --- /dev/null +++ b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzNotAutowiredTest.java @@ -0,0 +1,47 @@ +/* + * 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.component.quartz.it; + +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.QuarkusTestProfile; +import io.quarkus.test.junit.TestProfile; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.startsWith; + +@QuarkusTest +@TestProfile(QuartzNotAutowiredTest.Profile.class) +class QuartzNotAutowiredTest { + + @Test + void testQuarkusQuartzSchedulerNotAutowired() { + RestAssured.get("/quartz/scheduler-name") + .then() + .statusCode(200) + .body(startsWith("DefaultQuartzScheduler")); + } + + public static class Profile implements QuarkusTestProfile { + @Override + public Map getConfigOverrides() { + return Map.of("camel.component.quartz.autowired-enabled", "false"); + } + } +} diff --git a/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusCustomSchedulerAutowiredTest.java b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusCustomSchedulerAutowiredTest.java new file mode 100644 index 000000000000..aab433d2770b --- /dev/null +++ b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusCustomSchedulerAutowiredTest.java @@ -0,0 +1,52 @@ +/* + * 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.component.quartz.it; + +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.QuarkusTestProfile; +import io.quarkus.test.junit.TestProfile; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.is; + +@QuarkusTest +@TestProfile(QuartzQuarkusCustomSchedulerAutowiredTest.Profile.class) +class QuartzQuarkusCustomSchedulerAutowiredTest { + + @Test + void testCustomSchedulerAutowired() { + RestAssured.get("/quartz/scheduler-name") + .then() + .statusCode(200) + .body(is("customScheduler")); + } + + public static class Profile implements QuarkusTestProfile { + @Override + public String getConfigProfile() { + return "quartz-custom-scheduler"; + } + + @Override + public Map getConfigOverrides() { + return Map.of("camel.component.quartzFromProperties.propertiesFile", ""); + } + } +} diff --git a/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerAutowiredTest.java b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerAutowiredTest.java new file mode 100644 index 000000000000..feee98df7e73 --- /dev/null +++ b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerAutowiredTest.java @@ -0,0 +1,47 @@ +/* + * 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.component.quartz.it; + +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.QuarkusTestProfile; +import io.quarkus.test.junit.TestProfile; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.is; + +@QuarkusTest +@TestProfile(QuartzQuarkusSchedulerAutowiredTest.Profile.class) +class QuartzQuarkusSchedulerAutowiredTest { + + @Test + void testQuarkusSchedulerAutowired() { + RestAssured.get("/quartz/scheduler-name") + .then() + .statusCode(200) + .body(is("QuarkusQuartzScheduler")); + } + + public static class Profile implements QuarkusTestProfile { + @Override + public Map getConfigOverrides() { + return Map.of("quarkus.scheduler.start-mode", "forced"); + } + } +} diff --git a/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest.java b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest.java new file mode 100644 index 000000000000..3428b8fff546 --- /dev/null +++ b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest.java @@ -0,0 +1,57 @@ +/* + * 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.component.quartz.it; + +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.QuarkusTestProfile; +import io.quarkus.test.junit.TestProfile; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.is; + +@QuarkusTest +@TestProfile(QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest.Profile.class) +class QuartzQuarkusSchedulerAutowiredWithSchedulerBeanTest { + + @Test + void testQuarkusSchedulerAutowired() { + RestAssured.get("/quartz/scheduler-name") + .then() + .statusCode(200) + .body(is("QuarkusQuartzScheduler")); + + RestAssured.get("/quartz/scheduler-bean/fired") + .then() + .statusCode(200) + .body(is("true")); + } + + public static class Profile implements QuarkusTestProfile { + @Override + public String getConfigProfile() { + return "quartz-scheduler-bean"; + } + + @Override + public Map getConfigOverrides() { + return Map.of("camel.component.quartzFromProperties.propertiesFile", ""); + } + } +} diff --git a/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerNotAutowiredTest.java b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerNotAutowiredTest.java new file mode 100644 index 000000000000..e65a9a7a4cf6 --- /dev/null +++ b/integration-tests/quartz/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzQuarkusSchedulerNotAutowiredTest.java @@ -0,0 +1,49 @@ +/* + * 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.component.quartz.it; + +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.QuarkusTestProfile; +import io.quarkus.test.junit.TestProfile; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.startsWith; + +@QuarkusTest +@TestProfile(QuartzQuarkusSchedulerNotAutowiredTest.Profile.class) +class QuartzQuarkusSchedulerNotAutowiredTest { + + @Test + void testQuarkusQuartzSchedulerNotAutowired() { + RestAssured.get("/quartz/scheduler-name") + .then() + .statusCode(200) + .body(startsWith("DefaultQuartzScheduler")); + } + + public static class Profile implements QuarkusTestProfile { + @Override + public Map getConfigOverrides() { + return Map.of( + "camel.component.quartz.autowired-enabled", "false", + "quarkus.scheduler.start-mode", "forced"); + } + } +}