You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/08/03 11:04:10 UTC
[4/6] CAMEL-4075 added camel-quartz2 component with thanks to Zemian
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/main/java/org/apache/camel/routepolicy/quartz2/SimpleScheduledRoutePolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/routepolicy/quartz2/SimpleScheduledRoutePolicy.java b/components/camel-quartz2/src/main/java/org/apache/camel/routepolicy/quartz2/SimpleScheduledRoutePolicy.java
new file mode 100644
index 0000000..bc93c57
--- /dev/null
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/routepolicy/quartz2/SimpleScheduledRoutePolicy.java
@@ -0,0 +1,222 @@
+/**
+ * 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.routepolicy.quartz2;
+
+import org.apache.camel.Route;
+import org.apache.camel.component.quartz2.QuartzComponent;
+import org.apache.camel.util.ObjectHelper;
+import org.quartz.*;
+
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+public class SimpleScheduledRoutePolicy extends ScheduledRoutePolicy {
+ private Date routeStartDate;
+ private int routeStartRepeatCount;
+ private long routeStartRepeatInterval;
+ private Date routeStopDate;
+ private int routeStopRepeatCount;
+ private long routeStopRepeatInterval;
+ private Date routeSuspendDate;
+ private int routeSuspendRepeatCount;
+ private long routeSuspendRepeatInterval;
+ private Date routeResumeDate;
+ private int routeResumeRepeatCount;
+ private long routeResumeRepeatInterval;
+
+ public void onInit(Route route) {
+ try {
+ doOnInit(route);
+ } catch (Exception e) {
+ throw ObjectHelper.wrapRuntimeCamelException(e);
+ }
+ }
+
+ protected void doOnInit(Route route) throws Exception {
+ QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz2", QuartzComponent.class);
+ setScheduler(quartz.getScheduler());
+
+ // Important: do not start scheduler as QuartzComponent does that automatic
+ // when CamelContext has been fully initialized and started
+
+ if (getRouteStopGracePeriod() == 0) {
+ setRouteStopGracePeriod(10000);
+ }
+
+ if (getTimeUnit() == null) {
+ setTimeUnit(TimeUnit.MILLISECONDS);
+ }
+
+ // validate time options has been configured
+ if ((getRouteStartDate() == null) && (getRouteStopDate() == null) && (getRouteSuspendDate() == null) && (getRouteResumeDate() == null)) {
+ throw new IllegalArgumentException("Scheduled Route Policy for route {} has no stop/stop/suspend/resume times specified");
+ }
+
+ registerRouteToScheduledRouteDetails(route);
+ if (getRouteStartDate() != null) {
+ scheduleRoute(Action.START, route);
+ }
+ if (getRouteStopDate() != null) {
+ scheduleRoute(Action.STOP, route);
+ }
+
+ if (getRouteSuspendDate() != null) {
+ scheduleRoute(Action.SUSPEND, route);
+ }
+ if (getRouteResumeDate() != null) {
+ scheduleRoute(Action.RESUME, route);
+ }
+ }
+
+ @Override
+ protected Trigger createTrigger(Action action, Route route) throws Exception {
+ SimpleTrigger trigger = null;
+
+ if (action == Action.START) {
+ trigger = TriggerBuilder.newTrigger()
+ .withIdentity(TRIGGER_START + route.getId(), TRIGGER_GROUP + route.getId())
+ .withSchedule(SimpleScheduleBuilder.simpleSchedule()
+ .withRepeatCount(getRouteStartRepeatCount())
+ .withIntervalInMilliseconds(getRouteStartRepeatInterval()))
+ .startAt(routeStartDate == null ? new Date() : routeStartDate)
+ .build();
+ } else if (action == Action.STOP) {
+ trigger = TriggerBuilder.newTrigger()
+ .withIdentity(TRIGGER_STOP + route.getId(), TRIGGER_GROUP + route.getId())
+ .withSchedule(SimpleScheduleBuilder.simpleSchedule()
+ .withRepeatCount(getRouteStopRepeatCount())
+ .withIntervalInMilliseconds(getRouteStopRepeatInterval()))
+ .startAt(routeStopDate == null ? new Date() : routeStopDate)
+ .build();
+ } else if (action == Action.SUSPEND) {
+ trigger = TriggerBuilder.newTrigger()
+ .withIdentity(TRIGGER_SUSPEND + route.getId(), TRIGGER_GROUP + route.getId())
+ .withSchedule(SimpleScheduleBuilder.simpleSchedule()
+ .withRepeatCount(getRouteSuspendRepeatCount())
+ .withIntervalInMilliseconds(getRouteSuspendRepeatInterval()))
+ .startAt(routeSuspendDate == null ? new Date() : routeSuspendDate)
+ .build();
+ } else if (action == Action.RESUME) {
+ trigger = TriggerBuilder.newTrigger()
+ .withIdentity(TRIGGER_RESUME + route.getId(), TRIGGER_GROUP + route.getId())
+ .withSchedule(SimpleScheduleBuilder.simpleSchedule()
+ .withRepeatCount(getRouteResumeRepeatCount())
+ .withIntervalInMilliseconds(getRouteResumeRepeatInterval()))
+ .startAt(routeResumeDate == null ? new Date() : routeResumeDate)
+ .build();
+ }
+
+ return trigger;
+ }
+
+ public Date getRouteStartDate() {
+ return routeStartDate;
+ }
+
+ public void setRouteStartDate(Date routeStartDate) {
+ this.routeStartDate = routeStartDate;
+ }
+
+ public Date getRouteStopDate() {
+ return routeStopDate;
+ }
+
+ public void setRouteStopDate(Date routeStopDate) {
+ this.routeStopDate = routeStopDate;
+ }
+
+ public Date getRouteSuspendDate() {
+ return routeSuspendDate;
+ }
+
+ public void setRouteSuspendDate(Date routeSuspendDate) {
+ this.routeSuspendDate = routeSuspendDate;
+ }
+
+ public int getRouteStartRepeatCount() {
+ return routeStartRepeatCount;
+ }
+
+ public void setRouteStartRepeatCount(int routeStartRepeatCount) {
+ this.routeStartRepeatCount = routeStartRepeatCount;
+ }
+
+ public long getRouteStartRepeatInterval() {
+ return routeStartRepeatInterval;
+ }
+
+ public void setRouteStartRepeatInterval(long routeStartRepeatInterval) {
+ this.routeStartRepeatInterval = routeStartRepeatInterval;
+ }
+
+ public int getRouteStopRepeatCount() {
+ return routeStopRepeatCount;
+ }
+
+ public void setRouteStopRepeatCount(int routeStopRepeatCount) {
+ this.routeStopRepeatCount = routeStopRepeatCount;
+ }
+
+ public long getRouteStopRepeatInterval() {
+ return routeStopRepeatInterval;
+ }
+
+ public void setRouteStopRepeatInterval(long routeStopRepeatInterval) {
+ this.routeStopRepeatInterval = routeStopRepeatInterval;
+ }
+
+ public int getRouteSuspendRepeatCount() {
+ return routeSuspendRepeatCount;
+ }
+
+ public void setRouteSuspendRepeatCount(int routeSuspendRepeatCount) {
+ this.routeSuspendRepeatCount = routeSuspendRepeatCount;
+ }
+
+ public long getRouteSuspendRepeatInterval() {
+ return routeSuspendRepeatInterval;
+ }
+
+ public void setRouteSuspendRepeatInterval(long routeSuspendRepeatInterval) {
+ this.routeSuspendRepeatInterval = routeSuspendRepeatInterval;
+ }
+
+ public void setRouteResumeDate(Date routeResumeDate) {
+ this.routeResumeDate = routeResumeDate;
+ }
+
+ public Date getRouteResumeDate() {
+ return routeResumeDate;
+ }
+
+ public void setRouteResumeRepeatCount(int routeResumeRepeatCount) {
+ this.routeResumeRepeatCount = routeResumeRepeatCount;
+ }
+
+ public int getRouteResumeRepeatCount() {
+ return routeResumeRepeatCount;
+ }
+
+ public void setRouteResumeRepeatInterval(long routeResumeRepeatInterval) {
+ this.routeResumeRepeatInterval = routeResumeRepeatInterval;
+ }
+
+ public long getRouteResumeRepeatInterval() {
+ return routeResumeRepeatInterval;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/resources/META-INF/LICENSE.txt b/components/camel-quartz2/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/components/camel-quartz2/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/resources/META-INF/NOTICE.txt b/components/camel-quartz2/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/components/camel-quartz2/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/main/resources/META-INF/services/org/apache/camel/component/quartz2
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/resources/META-INF/services/org/apache/camel/component/quartz2 b/components/camel-quartz2/src/main/resources/META-INF/services/org/apache/camel/component/quartz2
new file mode 100644
index 0000000..c1ffd5c
--- /dev/null
+++ b/components/camel-quartz2/src/main/resources/META-INF/services/org/apache/camel/component/quartz2
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.quartz2.QuartzComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAddDynamicRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAddDynamicRouteTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAddDynamicRouteTest.java
new file mode 100644
index 0000000..05bb827
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAddDynamicRouteTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class QuartzAddDynamicRouteTest extends CamelTestSupport {
+ protected MockEndpoint resultEndpoint;
+
+ @Test
+ public void testAddDynamicRoute() throws Exception {
+ resultEndpoint = getMockEndpoint("mock:result");
+ resultEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:foo", "Hello World");
+
+ resultEndpoint.assertIsSatisfied();
+
+ // reset and add a new dynamic route
+ resultEndpoint.reset();
+ resultEndpoint.expectedMessageCount(2);
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute")
+ .to("direct:foo");
+ }
+ });
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:foo").to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAddRoutesAfterCamelContextStartedTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAddRoutesAfterCamelContextStartedTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAddRoutesAfterCamelContextStartedTest.java
new file mode 100644
index 0000000..1f11d23
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAddRoutesAfterCamelContextStartedTest.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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class QuartzAddRoutesAfterCamelContextStartedTest extends CamelTestSupport {
+
+ @Test
+ public void testAddRoutes() throws Exception {
+ // camel context should already be started
+ assertTrue(context.getStatus().isStarted());
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(2);
+
+ // add the quartz router after CamelContext has been started
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?trigger.repeatInterval=1000&trigger.repeatCount=1").to("mock:result");
+ }
+ });
+
+ // it should also work
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAutoStartTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAutoStartTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAutoStartTest.java
new file mode 100644
index 0000000..e330413
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzAutoStartTest.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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class QuartzAutoStartTest extends CamelTestSupport {
+
+ @Test
+ public void testQuartzAutoStart() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:one");
+ mock.expectedMessageCount(0);
+
+ QuartzComponent quartz = context.getComponent("quartz2", QuartzComponent.class);
+ assertFalse("Should not have started scheduler", quartz.getScheduler().isStarted());
+
+ Thread.sleep(2000);
+
+ assertMockEndpointsSatisfied();
+
+ mock.reset();
+ mock.expectedMinimumMessageCount(1);
+
+ // start scheduler
+
+ quartz.getScheduler().start();
+
+ assertMockEndpointsSatisfied();
+ }
+
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?&autoStartScheduler=false").to("mock:one");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzComponentTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzComponentTest.java
new file mode 100644
index 0000000..a24b529
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzComponentTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * @version
+ */
+public class QuartzComponentTest extends CamelTestSupport {
+
+ @Test
+ public void testQuartzComponentCustomScheduler() throws Exception {
+ QuartzComponent comp = new QuartzComponent();
+ comp.setCamelContext(context);
+
+ SchedulerFactory fac = new StdSchedulerFactory();
+ comp.setSchedulerFactory(fac);
+ assertSame(fac, comp.getSchedulerFactory());
+
+ Scheduler sch = fac.getScheduler();
+ comp.setScheduler(sch);
+ assertSame(sch, comp.getScheduler());
+
+ comp.start();
+ comp.stop();
+ }
+
+ @Test
+ public void testQuartzComponent() throws Exception {
+ QuartzComponent comp = new QuartzComponent(context);
+ comp.start();
+ comp.stop();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteTest.java
new file mode 100644
index 0000000..9b2225b
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Test;
+import org.quartz.CronTrigger;
+import org.quartz.JobDetail;
+import org.quartz.Trigger;
+
+/**
+ * This test the CronTrigger as a timer endpoint in a route.
+ * @version
+ */
+public class QuartzCronRouteTest extends CamelTestSupport {
+
+ @Test
+ public void testQuartzCronRoute() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(3);
+
+ assertMockEndpointsSatisfied();
+
+ Trigger trigger = mock.getReceivedExchanges().get(0).getIn().getHeader("trigger", Trigger.class);
+ Assert.assertThat(trigger instanceof CronTrigger, CoreMatchers.is(true));
+
+ JobDetail detail = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
+ Assert.assertThat(detail.getJobClass().equals(CamelJob.class), CoreMatchers.is(true));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // triggers every 2th second at precise 00,02,04,06..58
+ // notice we must use + as space when configured using URI parameter
+ from("quartz2://myGroup/myTimerName?cron=0/2+*+*+*+*+?").to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteWithSmallCacheTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteWithSmallCacheTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteWithSmallCacheTest.java
new file mode 100644
index 0000000..d1ff451
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteWithSmallCacheTest.java
@@ -0,0 +1,69 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Endpoints are stored in a LRU list with a default capacity of 1000. If the list is full,
+ * then endpoints are removed and should be recreated.
+ * <p/>
+ * We simulate this behavior with a capacity of 1 element.
+ */
+public class QuartzCronRouteWithSmallCacheTest extends CamelTestSupport {
+
+ private final CountDownLatch latch = new CountDownLatch(3);
+
+ @Test
+ public void testQuartzCronRouteWithSmallCache() throws Exception {
+ boolean wait = latch.await(10, TimeUnit.SECONDS);
+ assertTrue(wait);
+ assertTrue("Quartz should trigger at least 3 times", latch.getCount() <= 0);
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ context.getProperties().put(Exchange.MAXIMUM_ENDPOINT_CACHE_SIZE, "1");
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:foo").to("log:foo");
+
+ from("quartz2://myGroup/myTimerName?cron=0/2+*+*+*+*+?").process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ latch.countDown();
+ template.sendBody("direct:foo", "Quartz triggered");
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzEndpointConfigureTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzEndpointConfigureTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzEndpointConfigureTest.java
new file mode 100644
index 0000000..6b7f9c5
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzEndpointConfigureTest.java
@@ -0,0 +1,160 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.quartz.*;
+
+/**
+ * @version
+ */
+public class QuartzEndpointConfigureTest extends CamelTestSupport {
+
+ @Test
+ public void testConfigureGroupAndName() throws Exception {
+ QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myName?trigger.repeatCount=3&trigger.repeatInterval=1000");
+
+ Scheduler scheduler = endpoint.getComponent().getScheduler();
+ TriggerKey triggerKey = endpoint.getTriggerKey();
+ Trigger trigger = scheduler.getTrigger(triggerKey);
+ JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
+
+ assertEquals("getName()", "myName", triggerKey.getName());
+ assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
+ assertEquals("getJobName", "myName", jobDetail.getKey().getName());
+ assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
+
+ SimpleTrigger simpleTrigger = assertIsInstanceOf(SimpleTrigger.class, trigger);
+ assertEquals("getRepeatCount()", 3, simpleTrigger.getRepeatCount());
+ }
+
+ @Test
+ public void testConfigureName() throws Exception {
+ QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myName");
+
+ Scheduler scheduler = endpoint.getComponent().getScheduler();
+ TriggerKey triggerKey = endpoint.getTriggerKey();
+ JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
+
+ assertEquals("getName()", "myName", triggerKey.getName());
+ assertEquals("getGroup()", "Camel", triggerKey.getGroup());
+ assertEquals("getJobName", "myName", jobDetail.getKey().getName());
+ assertEquals("getJobGroup", "Camel", jobDetail.getKey().getGroup());
+ }
+
+ @Test
+ public void testConfigureCronExpression() throws Exception {
+ QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI");
+
+ Scheduler scheduler = endpoint.getComponent().getScheduler();
+ TriggerKey triggerKey = endpoint.getTriggerKey();
+ Trigger trigger = scheduler.getTrigger(triggerKey);
+ JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
+
+ assertEquals("getName()", "myTimerName", triggerKey.getName());
+ assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
+ assertEquals("getJobName", "myTimerName", jobDetail.getKey().getName());
+ assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
+
+ assertIsInstanceOf(CronTrigger.class, trigger);
+ CronTrigger cronTrigger = (CronTrigger)trigger;
+ assertEquals("cron expression", "0 0/5 12-18 ? * MON-FRI", cronTrigger.getCronExpression());
+ }
+
+ @Test
+ public void testConfigureAnotherCronExpression() throws Exception {
+ QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myTimerName?cron=0+0+*+*+*+?");
+
+ Scheduler scheduler = endpoint.getComponent().getScheduler();
+ TriggerKey triggerKey = endpoint.getTriggerKey();
+ Trigger trigger = scheduler.getTrigger(triggerKey);
+ JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
+
+ assertEquals("getName()", "myTimerName", triggerKey.getName());
+ assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
+ assertEquals("getJobName", "myTimerName", jobDetail.getKey().getName());
+ assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
+
+ assertIsInstanceOf(CronTrigger.class, trigger);
+ CronTrigger cronTrigger = (CronTrigger)trigger;
+ assertEquals("cron expression", "0 0 * * * ?", cronTrigger.getCronExpression());
+ }
+
+ @Test
+ public void testConfigureJobName() throws Exception {
+ QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myTimerName?job.name=hadrian&cron=0+0+*+*+*+?");
+
+ Scheduler scheduler = endpoint.getComponent().getScheduler();
+ TriggerKey triggerKey = endpoint.getTriggerKey();
+ Trigger trigger = scheduler.getTrigger(triggerKey);
+ JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey("hadrian", triggerKey.getGroup()));
+
+ assertEquals("getName()", "myTimerName", triggerKey.getName());
+ assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
+ assertEquals("getJobName", "hadrian", jobDetail.getKey().getName());
+ assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
+
+ assertIsInstanceOf(CronTrigger.class, trigger);
+ }
+
+ @Test
+ public void testConfigureNoDoubleSlashNoCron() throws Exception {
+ QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2:myGroup/myTimerName");
+
+ TriggerKey triggerKey = endpoint.getTriggerKey();
+ assertEquals("getName()", "myTimerName", triggerKey.getName());
+ assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
+ }
+
+ @Test
+ public void testConfigureNoDoubleSlashQuestionCron() throws Exception {
+ QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2:myGroup/myTimerName?cron=0+0+*+*+*+?");
+
+ Scheduler scheduler = endpoint.getComponent().getScheduler();
+ TriggerKey triggerKey = endpoint.getTriggerKey();
+ Trigger trigger = scheduler.getTrigger(triggerKey);
+ JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
+
+ assertEquals("getName()", "myTimerName", triggerKey.getName());
+ assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
+ assertEquals("getJobName", "myTimerName", jobDetail.getKey().getName());
+ assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
+
+ assertIsInstanceOf(CronTrigger.class, trigger);
+ CronTrigger cronTrigger = (CronTrigger)trigger;
+ assertEquals("cron expression", "0 0 * * * ?", cronTrigger.getCronExpression());
+ }
+
+ @Test
+ public void testConfigureDeleteJob() throws Exception {
+ QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2:myGroup/myTimerName?cron=0+0+*+*+*+?");
+ assertEquals("cron expression", "0 0 * * * ?", endpoint.getCron());
+ assertEquals("deleteJob", true, endpoint.isDeleteJob());
+
+ endpoint = resolveMandatoryEndpoint("quartz2:myGroup/myTimerName2?cron=1+0+*+*+*+?&deleteJob=false");
+ assertEquals("cron expression", "1 0 * * * ?", endpoint.getCron());
+ assertEquals("deleteJob", false, endpoint.isDeleteJob());
+ }
+
+ @Override
+ protected QuartzEndpoint resolveMandatoryEndpoint(String uri) {
+ Endpoint endpoint = super.resolveMandatoryEndpoint(uri);
+ return assertIsInstanceOf(QuartzEndpoint.class, endpoint);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzJobRouteUnderscoreTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzJobRouteUnderscoreTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzJobRouteUnderscoreTest.java
new file mode 100644
index 0000000..d2e440c
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzJobRouteUnderscoreTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.quartz.JobDetail;
+
+/**
+ * @version
+ */
+public class QuartzJobRouteUnderscoreTest extends CamelTestSupport {
+
+ @Test
+ public void testQuartzRoute() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(2);
+ mock.message(0).header("triggerGroup").isEqualTo("my_group");
+ mock.message(0).header("triggerName").isEqualTo("my_timer");
+
+ assertMockEndpointsSatisfied();
+
+ JobDetail detail = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
+ assertNotNull(detail);
+ assertEquals("my_job", detail.getKey().getName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("quartz2://my_group/my_timer?trigger.repeatInterval=2&trigger.repeatCount=1&job.name=my_job")
+ .to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java
new file mode 100644
index 0000000..7027714
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java
@@ -0,0 +1,190 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.quartz.Scheduler;
+import org.quartz.Trigger;
+import org.quartz.TriggerKey;
+
+/**
+ * Check for duplicate name/group collision.
+ */
+public class QuartzNameCollisionTest {
+ private DefaultCamelContext camel1;
+ private DefaultCamelContext camel2;
+
+ @Test
+ public void testDupeName() throws Exception {
+ camel1 = new DefaultCamelContext();
+ camel1.setName("camel-1");
+ camel1.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
+ }
+ });
+ camel1.start();
+
+ try {
+ camel1.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?cron=0/2+*+*+*+*+?").to("log:two", "mock:two");
+ }
+ });
+ Assert.fail("Should have thrown an exception");
+ } catch (FailedToCreateRouteException e) {
+ String reason = e.getMessage();
+ Assert.assertEquals(reason.indexOf("Trigger key myGroup.myTimerName is already in used") >=0, true);
+ }
+ }
+
+ @Test
+ public void testDupeNameMultiContext() throws Exception {
+ camel1 = new DefaultCamelContext();
+ camel1.setName("camel-1");
+ camel1.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
+ }
+ });
+ camel1.start();
+
+ camel2 = new DefaultCamelContext();
+ camel2.setName("camel-2");
+ camel2.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName=0/2+*+*+*+*+?").to("log:two", "mock:two");
+ }
+ });
+ camel2.start();
+ }
+
+ /**
+ * Don't check for a name collision if the job is stateful.
+ */
+ @Test
+ public void testNoStatefulCollisionError() throws Exception {
+ camel1 = new DefaultCamelContext();
+ camel1.setName("camel-1");
+ camel1.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?stateful=true&cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
+ }
+ });
+ camel1.start();
+
+ camel2 = new DefaultCamelContext();
+ camel2.setName("camel-2");
+ camel2.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?stateful=true").to("log:two", "mock:two");
+ }
+ });
+ camel2.start();
+ // if no exception is thrown then this test passed.
+ }
+
+ /**
+ * Make sure a resume doesn't trigger a dupe name error.
+ */
+ @Test
+ public void testRestart() throws Exception {
+ DefaultCamelContext camel = new DefaultCamelContext();
+
+ camel.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
+ }
+ });
+
+ // traverse a litany of states
+ camel.start();
+ Thread.sleep(100);
+ camel.suspend();
+ Thread.sleep(100);
+ camel.resume();
+ Thread.sleep(100);
+ camel.stop();
+ Thread.sleep(100);
+ camel.start();
+ Thread.sleep(100);
+ camel.stop();
+ }
+
+
+ /**
+ * Confirm the quartz trigger is removed on route stop.
+ */
+ @Test
+ public void testRemoveJob() throws Exception {
+ camel1 = new DefaultCamelContext();
+ camel1.setName("camel-1");
+ camel1.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").id("route-1").to("log:one", "mock:one");
+ }
+ });
+
+ camel1.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup2/myTimerName?cron=0/1+*+*+*+*+?").id("route-2").to("log:one", "mock:one");
+ }
+ });
+
+ camel1.start();
+
+ QuartzComponent component = (QuartzComponent) camel1.getComponent("quartz2");
+ Scheduler scheduler = component.getScheduler();
+ TriggerKey triggerKey = TriggerKey.triggerKey("myTimerName", "myGroup");
+ Trigger trigger = scheduler.getTrigger(triggerKey);
+ Assert.assertNotNull(trigger);
+
+ camel1.stopRoute("route-1");
+
+ Trigger.TriggerState triggerState = component.getScheduler().getTriggerState(triggerKey);
+ Assert.assertNotNull(trigger);
+ Assert.assertEquals(Trigger.TriggerState.PAUSED, triggerState);
+ }
+
+ @After
+ public void cleanUp() throws Exception {
+ if (camel1 != null) {
+ camel1.stop();
+ camel1 = null;
+ }
+
+ if (camel2 != null) {
+ camel2.stop();
+ camel2 = null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzOneCamelContextRestartTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzOneCamelContextRestartTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzOneCamelContextRestartTest.java
new file mode 100644
index 0000000..5ae3845
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzOneCamelContextRestartTest.java
@@ -0,0 +1,69 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class QuartzOneCamelContextRestartTest {
+
+ private DefaultCamelContext camel1;
+
+ @Before
+ public void setUp() throws Exception {
+ camel1 = new DefaultCamelContext();
+ camel1.setName("camel-1");
+ camel1.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
+ }
+ });
+ camel1.start();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ camel1.stop();
+ }
+
+ @Test
+ public void testOneCamelContextSuspendResume() throws Exception {
+ MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
+ mock1.expectedMinimumMessageCount(2);
+ mock1.assertIsSatisfied();
+
+ camel1.stop();
+
+ // fetch mock endpoint again because we have stopped camel context
+ mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
+ // should resume triggers when we start camel 1 again
+ mock1.expectedMinimumMessageCount(3);
+ camel1.start();
+
+ mock1.assertIsSatisfied();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzOneCamelContextSuspendResumeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzOneCamelContextSuspendResumeTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzOneCamelContextSuspendResumeTest.java
new file mode 100644
index 0000000..8973df9
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzOneCamelContextSuspendResumeTest.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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class QuartzOneCamelContextSuspendResumeTest {
+
+ private DefaultCamelContext camel1;
+
+ @Before
+ public void setUp() throws Exception {
+ camel1 = new DefaultCamelContext();
+ camel1.setName("camel-1");
+ camel1.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("mock:one");
+ }
+ });
+ camel1.start();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ camel1.stop();
+ }
+
+ @Test
+ public void testOneCamelContextSuspendResume() throws Exception {
+ MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
+ mock1.expectedMinimumMessageCount(2);
+ mock1.assertIsSatisfied();
+
+ camel1.suspend();
+
+ // should resume triggers when we start camel 1 again
+ mock1.reset();
+ mock1.expectedMinimumMessageCount(2);
+ camel1.resume();
+
+ mock1.assertIsSatisfied();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzPropertiesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzPropertiesTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzPropertiesTest.java
new file mode 100644
index 0000000..9ba69cc
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzPropertiesTest.java
@@ -0,0 +1,85 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.quartz.SchedulerException;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * @version
+ */
+public class QuartzPropertiesTest extends CamelTestSupport {
+
+ private QuartzComponent quartz;
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ quartz.stop();
+ super.tearDown();
+ }
+
+ @Test
+ public void testQuartzPropertiesFile() throws Exception {
+ quartz = context.getComponent("quartz2", QuartzComponent.class);
+
+ quartz.setPropertiesFile("org/apache/camel/component/quartz2/myquartz.properties");
+
+ quartz.start();
+
+ assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+ assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
+ }
+
+ @Test
+ public void testQuartzPropertiesFileNotFound() throws Exception {
+ quartz = context.getComponent("quartz2", QuartzComponent.class);
+
+ quartz.setPropertiesFile("doesnotexist.properties");
+
+ try {
+ quartz.start();
+ fail("Should have thrown exception");
+ } catch (SchedulerException e) {
+ assertEquals("Quartz properties file not found in classpath: doesnotexist.properties", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testQuartzProperties() throws Exception {
+ quartz = context.getComponent("quartz2", QuartzComponent.class);
+
+ Properties prop = new Properties();
+ InputStream is = context.getClassResolver().loadResourceAsStream("org/apache/camel/component/quartz2/myquartz.properties");
+ prop.load(is);
+ quartz.setProperties(prop);
+
+ quartz.start();
+
+ assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+ assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteFireNowTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteFireNowTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteFireNowTest.java
new file mode 100644
index 0000000..f6d1c63
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteFireNowTest.java
@@ -0,0 +1,36 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version
+ */
+public class QuartzRouteFireNowTest extends QuartzRouteTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // START SNIPPET: example
+ from("quartz2://myGroup/myTimerName?fireNow=true&trigger.repeatInterval=25000&trigger.repeatCount=2").to("mock:result");
+ // END SNIPPET: example
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteRestartTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteRestartTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteRestartTest.java
new file mode 100644
index 0000000..8931c9f
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteRestartTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class QuartzRouteRestartTest extends CamelTestSupport {
+
+ @Test
+ public void testQuartzCronRoute() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(2);
+
+ assertMockEndpointsSatisfied();
+
+ // restart route
+ context().stopRoute("trigger");
+ mock.reset();
+ mock.expectedMessageCount(0);
+
+ // wait a bit
+ Thread.sleep(2000);
+
+ assertMockEndpointsSatisfied();
+
+ // start route, and we got messages again
+ mock.reset();
+ mock.expectedMinimumMessageCount(1);
+
+ context().startRoute("trigger");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("quartz2://groupName/timerName?cron=0/1+*+*+*+*+?").routeId("trigger")
+ .to("mock:result");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteTest.java
new file mode 100644
index 0000000..573521a
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class QuartzRouteTest extends CamelTestSupport {
+ protected MockEndpoint resultEndpoint;
+
+ @Test
+ public void testQuartzRoute() throws Exception {
+ resultEndpoint = getMockEndpoint("mock:result");
+ resultEndpoint.expectedMessageCount(2);
+ resultEndpoint.message(0).header("triggerName").isEqualTo("myTimerName");
+ resultEndpoint.message(0).header("triggerGroup").isEqualTo("myGroup");
+
+ // lets test the receive worked
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // START SNIPPET: example
+ from("quartz2://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute").to("mock:result");
+ // END SNIPPET: example
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzSimpleRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzSimpleRouteTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzSimpleRouteTest.java
new file mode 100644
index 0000000..a434cc5
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzSimpleRouteTest.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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Test;
+import org.quartz.CronTrigger;
+import org.quartz.JobDetail;
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+
+/**
+ * This not only set SimpleTrigger as a timer endpoint in a route, and also test the trigger.XXX properties setter.
+ * @version
+ */
+public class QuartzSimpleRouteTest extends CamelTestSupport {
+
+ @Test
+ public void testQuartzCronRoute() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(3);
+
+ assertMockEndpointsSatisfied();
+ Trigger trigger = mock.getReceivedExchanges().get(0).getIn().getHeader("trigger", Trigger.class);
+ Assert.assertThat(trigger instanceof SimpleTrigger, CoreMatchers.is(true));
+
+ JobDetail detail = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
+ Assert.assertThat(detail.getJobClass().equals(CamelJob.class), CoreMatchers.is(true));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("quartz2://myGroup/myTimerName?trigger.repeatInterval=2000&trigger.repeatCount=-1").to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedOptionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedOptionTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedOptionTest.java
new file mode 100644
index 0000000..a97c0f0
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedOptionTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class QuartzStartDelayedOptionTest extends CamelTestSupport {
+
+ @Test
+ public void testStartDelayed() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.setMinimumResultWaitTime(1900);
+ mock.setResultWaitTime(3000);
+ mock.expectedMessageCount(2);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("quartz2://myGroup/myTimerName?startDelayedSeconds=2&trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute")
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedTest.java
new file mode 100644
index 0000000..80d5d5d
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedTest.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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class QuartzStartDelayedTest extends CamelTestSupport {
+
+ @Test
+ public void testStartDelayed() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.setMinimumResultWaitTime(1900);
+ mock.setResultWaitTime(3000);
+ mock.expectedMessageCount(2);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ QuartzComponent quartz = context.getComponent("quartz2", QuartzComponent.class);
+ quartz.setStartDelayedSeconds(2);
+
+ from("quartz2://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute").to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e429d7c0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStatefulJobRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStatefulJobRouteTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStatefulJobRouteTest.java
new file mode 100644
index 0000000..d517659
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStatefulJobRouteTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Test;
+import org.quartz.CronTrigger;
+import org.quartz.JobDetail;
+import org.quartz.Trigger;
+
+/**
+ * This test the CronTrigger as a timer endpoint in a route.
+ * @version
+ */
+public class QuartzStatefulJobRouteTest extends CamelTestSupport {
+
+ @Test
+ public void testQuartzCronRoute() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(3);
+
+ assertMockEndpointsSatisfied();
+
+ Trigger trigger = mock.getReceivedExchanges().get(0).getIn().getHeader("trigger", Trigger.class);
+ Assert.assertThat(trigger instanceof CronTrigger, CoreMatchers.is(true));
+
+ JobDetail detail = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
+ Assert.assertThat(detail.getJobClass().equals(StatefulCamelJob.class), CoreMatchers.is(true));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // triggers every 2th second at precise 00,02,04,06..58
+ // notice we must use + as space when configured using URI parameter
+ from("quartz2://myGroup/myTimerName?cron=0/2+*+*+*+*+?&stateful=true").to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file