Search in sources :

Example 41 with EJBCronTrigger

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

the class EJBCronTriggerTest method testLastDayOfMonthB.

@Test(timeout = 5000)
public void testLastDayOfMonthB() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2011).month(6).dayOfMonth("Last").hour(23).minute(59).second(59).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 5, 30, 23, 59, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 1, 1, 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 42 with EJBCronTrigger

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

the class EJBCronTriggerTest method testIncrementsB.

@Test(timeout = 1000)
public void testIncrementsB() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2011).month(5).dayOfMonth(5).hour("23").minute("25/35").start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 4, 5, 23, 25, 0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 22, 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 43 with EJBCronTrigger

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

the class EJBCronTriggerTest method testListDayOfMonth.

@Test(timeout = 5000)
public void testListDayOfMonth() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfMonth("5,10,24").hour(23).minute(1).second(59).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2010, 6, 5, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 10, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 5, 23, 2, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 6, 24, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 24, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2010, 7, 5, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 24, 23, 3, 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 44 with EJBCronTrigger

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

the class EJBCronTriggerTest method testListDayOfWeekB.

@Test(timeout = 5000)
public void testListDayOfWeekB() throws ParseException {
    final String[] dayOfWeeks = { "2,3,4,5", "3,2,4,5", "2,3,4,5,2" };
    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)

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