Search in sources :

Example 31 with EJBCronTrigger

use of org.apache.openejb.core.timer.EJBCronTrigger in project tomee by apache.

the class EJBCronTriggerTest method testRangeYearsA.

@Test(timeout = 5000)
public void testRangeYearsA() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year("2009-2013").month(2).dayOfMonth(29).hour(23).minute(1).second(0).start(new Date(0));
    ;
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2012, 1, 29, 23, 1, 0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2009, 1, 1, 23, 0, 0).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 32 with EJBCronTrigger

use of org.apache.openejb.core.timer.EJBCronTrigger in project tomee by apache.

the class EJBCronTriggerTest method testBothDayOfMonthAndDayOfWeekD.

@Test(timeout = 5000)
public void testBothDayOfMonthAndDayOfWeekD() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2011).dayOfMonth("19").dayOfWeek("3").hour(23).minute(59).second(59).start(new GregorianCalendar(2011, 4, 18, 23, 59, 58).getTime());
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 4, 18, 23, 59, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 18, 23, 59, 58).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Example 33 with EJBCronTrigger

use of org.apache.openejb.core.timer.EJBCronTrigger in project tomee by apache.

the class EJBCronTriggerTest method testMinusDayOfMonth.

@Test(timeout = 5000)
public void testMinusDayOfMonth() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfMonth(-2).hour(23).minute(1).second(59).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2009, 1, 26, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2009, 1, 1, 0, 0, 0).getTime()));
    // Test Leap year
    assertEquals(new GregorianCalendar(2000, 1, 27, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2000, 1, 26, 0, 0, 0).getTime()));
    // Test next month
    assertEquals(new GregorianCalendar(2000, 1, 27, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2000, 1, 26, 0, 0, 0).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 34 with EJBCronTrigger

use of org.apache.openejb.core.timer.EJBCronTrigger in project tomee by apache.

the class EJBCronTriggerTest method testRangeDayOfWeekB.

@Test(timeout = 5000000)
public void testRangeDayOfWeekB() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfWeek("fri-tue").hour(23).minute(1).second(59).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2010, 5, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 2, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 3, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 3, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 2, 0).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 35 with EJBCronTrigger

use of org.apache.openejb.core.timer.EJBCronTrigger in project tomee by apache.

the class EJBCronTriggerTest method testRangeDayOfMonthB.

@Test(timeout = 5000)
public void testRangeDayOfMonthB() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfMonth("27-3").hour(23).minute(1).second(59).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2010, 6, 1, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 2, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 27, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 26, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 27, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 27, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 28, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 27, 23, 2, 0).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ScheduleExpression (javax.ejb.ScheduleExpression)44 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)44 Test (org.junit.Test)44 GregorianCalendar (java.util.GregorianCalendar)42 Date (java.util.Date)34 Calendar (java.util.Calendar)4 ParseException (org.apache.openejb.core.timer.EJBCronTrigger.ParseException)2