Package org.apache.openejb.core.timer

Examples of org.apache.openejb.core.timer.EJBCronTrigger


public class EJBCronTriggerTest {

  @Test(timeout = 1000)
  public void testSimpleDate() throws ParseException {
    ScheduleExpression expr = new ScheduleExpression().year(2008).month(12).dayOfMonth(1).start(new Date(0));
    EJBCronTrigger trigger = new EJBCronTrigger(expr);
    Calendar calendar = new GregorianCalendar(2008, 1, 1);
    Date firstTime = trigger.getFireTimeAfter(calendar.getTime());
    Date finalTime = trigger.getFinalFireTime();

    // The trigger only fires once so these should be the same
    assertEquals(firstTime, finalTime);

    // Let's make sure that single fire time is what we wanted
View Full Code Here


  }

  @Test(timeout = 1000)
  public void testWeekdaysA() throws ParseException {
    ScheduleExpression expr = new ScheduleExpression().year(2008).dayOfWeek("Wed").start(new Date(0));
    EJBCronTrigger trigger = new EJBCronTrigger(expr);

    // Should fire on January 16th
    Calendar calendar = new GregorianCalendar(2008, 0, 16);
    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);
    Date expectedTime = calendar.getTime();
    assertEquals(expectedTime, trigger.getFinalFireTime());
  }
View Full Code Here

  @Test(timeout = 1000)
  public void testIncrementsA() throws ParseException {
    ScheduleExpression expr = new ScheduleExpression().year(2008).month(1).dayOfMonth(20)
        .hour("6/3").minute(30).start(new Date(0));
    EJBCronTrigger trigger = new EJBCronTrigger(expr);

    // Should fire on Sunday, January 20th, first at 6:30
    Calendar calendar = new GregorianCalendar(2008, 0, 20);
    Date startTime = new Date(calendar.getTimeInMillis() - 1000);
    calendar.set(Calendar.HOUR_OF_DAY, 6);
    calendar.set(Calendar.MINUTE, 30);
    assertEquals(calendar.getTime(), trigger.getFireTimeAfter(startTime));

    // Next on 9:30
    startTime = new Date(calendar.getTimeInMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 9);
    assertEquals(calendar.getTime(), trigger.getFireTimeAfter(startTime));

    // Won't be fired after the 20th so it should return null
    calendar = new GregorianCalendar(2008, 0, 21);
    startTime = new Date(calendar.getTimeInMillis());
    assertNull(trigger.getFireTimeAfter(startTime));
  }
View Full Code Here

  }
 
  @Test(timeout = 1000)
    public void testIncrementsB() throws ParseException {
        ScheduleExpression expr = new ScheduleExpression().year(2011).month(5).dayOfMonth(5).hour("23").minute("25/35").start(new Date(0));
        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()));
    }
View Full Code Here

    }
 
   @Test(timeout = 1000)
    public void testIncrementsC() throws ParseException {
        ScheduleExpression expr = new ScheduleExpression().year(2011).month(5).dayOfMonth(5).hour("*").minute("20/40").start(new GregorianCalendar(2011, 4, 5, 10, 21, 0).getTime());
        EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2011, 4, 5, 11, 20, 0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 10, 21, 0).getTime()));
    }
View Full Code Here

 
  @Test(timeout = 1000)
  public void testEndTime() throws ParseException {
    ScheduleExpression expr = new ScheduleExpression().dayOfMonth(20).dayOfWeek("sat").start(new Date(0));
    EJBCronTrigger trigger = new EJBCronTrigger(expr);

    // Should not be fired at all since the first Saturday the 20th is in September
    Calendar calendar = new GregorianCalendar(2008, 0, 4);
    trigger.setEndTime(calendar.getTime());
    calendar = new GregorianCalendar(2008, 0, 1);
    assertNull(trigger.getFireTimeAfter(calendar.getTime()));
    //Since we did not specify the start time, the trigger will backward until finding the target time
    //assertNull(trigger.getFinalFireTime());
  }
View Full Code Here

  }

  @Test(timeout = 5000)
  public void testSecond() throws ParseException {
      ScheduleExpression expr = new ScheduleExpression().hour("*").minute("*").second(5).start(new Date(0));
        EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2011, 1, 5, 0, 0, 5).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 1, 5, 0, 0, 4).getTime()));
        assertEquals(new GregorianCalendar(2011, 1, 5, 0, 1, 5).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 1, 5, 0, 0, 6).getTime()));
  }
View Full Code Here

 

  @Test(timeout = 5000)
    public void testBothDayOfMonthAndDayOfWeekA() throws ParseException {
        ScheduleExpression expr = new ScheduleExpression().dayOfMonth("5").dayOfWeek("6").year(2010).start(new Date(0));
        EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2010, 6, 3, 0, 0, 0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 0, 0, 0).getTime()));
    }
View Full Code Here

    }

  @Test(timeout = 5000)
    public void testBothDayOfMonthAndDayOfWeekB() throws ParseException {
        ScheduleExpression expr = new ScheduleExpression().dayOfMonth("last").dayOfWeek("3").year(2011).start(new Date(0));
        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()));
    }
View Full Code Here

    }
 
   @Test(timeout = 5000)
    public void testBothDayOfMonthAndDayOfWeekC() throws ParseException {
        ScheduleExpression expr = new ScheduleExpression().year(2011).dayOfMonth("18").dayOfWeek("3").hour(23).minute(59).second(58).start(new Date(0));
        EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2011, 4, 25, 23, 59, 58).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 18, 23, 59, 59).getTime()));
   
View Full Code Here

TOP

Related Classes of org.apache.openejb.core.timer.EJBCronTrigger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.