Search in sources :

Example 6 with EJBCronTrigger

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

the class EJBCronTriggerTest method testListDayOfWeekA.

@Test(timeout = 5000)
public void testListDayOfWeekA() throws ParseException {
    final String[] dayOfWeeks = { "tue,wed,thu,fri", "wed,tue,thu,fri", "tue,wed,thu,fri,tue" };
    for (final String dayOfWeek : dayOfWeeks) {
        final ScheduleExpression expr = new ScheduleExpression().dayOfWeek(dayOfWeek).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, 6, 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 7 with EJBCronTrigger

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

the class EJBCronTriggerTest method testBothDayOfMonthAndDayOfWeekF.

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

Example 8 with EJBCronTrigger

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

the class EJBCronTriggerTest method testWeekdaysA.

@Test(timeout = 1000)
public void testWeekdaysA() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2008).dayOfWeek("Wed").start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    // Should fire on January 16th
    Calendar calendar = new GregorianCalendar(2008, 0, 16);
    final Date startTime = new Date(calendar.getTimeInMillis() - 1000);
    assertEquals(calendar.getTime(), trigger.getFireTimeAfter(startTime));
    // And for the last time, on the 31st of December
    calendar = new GregorianCalendar(2008, 11, 31);
    final Date expectedTime = calendar.getTime();
    assertEquals(expectedTime, trigger.getFinalFireTime());
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 9 with EJBCronTrigger

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

the class EJBCronTriggerTest method testBothDayOfMonthAndDayOfWeekB.

@Test(timeout = 5000)
public void testBothDayOfMonthAndDayOfWeekB() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfMonth("last").dayOfWeek("3").year(2011).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 4, 11, 0, 0, 0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 7, 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 10 with EJBCronTrigger

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

the class EJBCronTriggerTest method testBothDayOfMonthAndDayOfWeekG.

@Test(timeout = 5000)
public void testBothDayOfMonthAndDayOfWeekG() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2011).dayOfMonth("12").dayOfWeek("6").hour(20).minute(59).second(59).start(new GregorianCalendar(2011, 5, 11, 20, 59, 58).getTime());
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    //assertEquals(new GregorianCalendar(2011, 5, 11, 20, 59, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 5, 11, 20, 59, 58).getTime()));
    assertEquals(new GregorianCalendar(2011, 5, 12, 20, 59, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 5, 11, 20, 59, 59).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) 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