Search in sources :

Example 26 with JobDetail

use of org.quartz.JobDetail in project camel by apache.

the class QuartzJobRouteUnderscoreTest method testQuartzRoute.

@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.getName());
}
Also used : JobDetail(org.quartz.JobDetail) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 27 with JobDetail

use of org.quartz.JobDetail in project camel by apache.

the class QuartzRouteFireNowTest method testQuartzRoute.

@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();
    JobDetail job = resultEndpoint.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
    assertNotNull(job);
    assertEquals("simple", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE));
    assertEquals(25000L, job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL));
    assertEquals(2, job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER));
}
Also used : JobDetail(org.quartz.JobDetail) Test(org.junit.Test)

Example 28 with JobDetail

use of org.quartz.JobDetail in project camel by apache.

the class QuartzCronRouteTest method testQuartzCronRoute.

@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));
    Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE).equals("cron"), CoreMatchers.is(true));
    Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION).equals("0/2 * * * * ?"), CoreMatchers.is(true));
}
Also used : CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 29 with JobDetail

use of org.quartz.JobDetail in project camel by apache.

the class QuartzCronTriggerRouteTest method testQuartzCronRoute.

@Test
public void testQuartzCronRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(3);
    assertMockEndpointsSatisfied();
    JobDetail job = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
    assertNotNull(job);
    assertEquals("cron", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE));
    assertEquals("UTC", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_TIMEZONE));
    assertEquals("0/2 * * * * ?", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION));
}
Also used : JobDetail(org.quartz.JobDetail) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 30 with JobDetail

use of org.quartz.JobDetail in project camel by apache.

the class QuartzEndpointConfigureTest method testConfigureGroupAndName.

@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());
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Aggregations

JobDetail (org.quartz.JobDetail)122 SchedulerException (org.quartz.SchedulerException)56 Trigger (org.quartz.Trigger)47 Scheduler (org.quartz.Scheduler)33 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)25 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)21 JobDataMap (org.quartz.JobDataMap)18 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)14 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 IOException (java.io.IOException)5 Serializable (java.io.Serializable)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4