Search in sources :

Example 1 with EJBCronTrigger

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

the class EJBCronTriggerTest method testRangeCDayOfWeek.

@Test(timeout = 500)
public void testRangeCDayOfWeek() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfWeek("0-7").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, 5, 30, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 2, 0).getTime()));
    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, 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 2 with EJBCronTrigger

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

the class EJBCronTriggerTest method testSimpleDayOfWeekB.

@Test(timeout = 500)
public void testSimpleDayOfWeekB() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfWeek("5").hour(14).minute(1).second(59).start(new Date(0));
    ;
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 4, 6, 14, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 23, 1, 30).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 3 with EJBCronTrigger

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

the class EJBCronTriggerTest method testLastDayOfMonthA.

@Test(timeout = 5000)
public void testLastDayOfMonthA() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfMonth("Last").hour(23).minute(59).second(59).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2009, 1, 28, 23, 59, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2009, 1, 1, 0, 0, 0).getTime()));
    //Test Leap year
    assertEquals(new GregorianCalendar(2000, 1, 29, 23, 59, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2000, 1, 28, 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 4 with EJBCronTrigger

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

the class EJBCronTriggerTest method testRangeMonthA.

@Test(timeout = 500)
public void testRangeMonthA() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year("2011").month("dec-dec").dayOfMonth(29).hour(23).minute(1).second(0).start(new Date(0));
    ;
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 11, 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 5 with EJBCronTrigger

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

the class EJBCronTriggerTest method testSimpleDayOfWeekA.

@Test(timeout = 500)
public void testSimpleDayOfWeekA() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfWeek("0").hour(23).minute(1).second(59).start(new Date(0));
    ;
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 4, 8, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 23, 1, 30).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