Search in sources :

Example 16 with EJBCronTrigger

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

the class EJBCronTriggerTest method testIncrementsC.

@Test(timeout = 1000)
public void testIncrementsC() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2011).month(5).dayOfMonth(5).hour("*").minute("20/40").start(new GregorianCalendar(2011, 4, 5, 10, 21, 0).getTime());
    final 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()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Example 17 with EJBCronTrigger

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

the class EJBCronTriggerTest method testInvalidSingleInputs.

@Test(timeout = 500)
public void testInvalidSingleInputs() throws ParseException {
    // invalid day of month
    ScheduleExpression expr = new ScheduleExpression().dayOfMonth(-8).hour(23).minute(1).second(59).start(new Date(0));
    boolean parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  year
    expr = new ScheduleExpression().year(98).month(5).dayOfMonth(6).hour(2).minute(1).second(59).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  month
    expr = new ScheduleExpression().month(-4).dayOfMonth(6).hour(2).minute(1).second(59).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  days in week
    expr = new ScheduleExpression().month(-4).dayOfWeek(9).hour(2).minute(1).second(59).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  month
    expr = new ScheduleExpression().month("XXXX").dayOfMonth(6).hour(2).minute(1).second(59).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  hour
    expr = new ScheduleExpression().dayOfMonth(6).hour("-4").minute(1).second(59).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  hour
    expr = new ScheduleExpression().dayOfMonth(6).hour("24/2").minute(1).second(59).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  minute
    expr = new ScheduleExpression().dayOfMonth(6).hour(2).minute(-1).second(59).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  second
    expr = new ScheduleExpression().dayOfMonth(6).hour(2).minute(1).second(-4).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) ParseException(org.apache.openejb.core.timer.EJBCronTrigger.ParseException) Date(java.util.Date) Test(org.junit.Test)

Example 18 with EJBCronTrigger

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

the class EJBCronTriggerTest method testOrdinalNumbersDayOfMonthC.

@Test(timeout = 5000)
public void testOrdinalNumbersDayOfMonthC() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfMonth("last sun").hour(23).minute(1).second(59);
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2100, 1, 28, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2100, 1, 1, 0, 0, 0).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Example 19 with EJBCronTrigger

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

the class EJBCronTriggerTest method testRangeDayOfMonthC.

@Test(timeout = 500)
public void testRangeDayOfMonthC() throws ParseException {
    //7-27
    final ScheduleExpression expr = new ScheduleExpression().dayOfMonth("1st Sat - 4th FRI").hour(23).minute(1).second(59).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 4, 7, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 1, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2011, 4, 9, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 8, 23, 2, 0).getTime()));
    assertEquals(new GregorianCalendar(2011, 4, 18, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 18, 23, 0, 0).getTime()));
    assertEquals(new GregorianCalendar(2011, 4, 27, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 26, 23, 3, 0).getTime()));
    assertEquals(new GregorianCalendar(2011, 5, 4, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 28, 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 20 with EJBCronTrigger

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

the class EJBCronTriggerTest method testSimpleDayOfWeekC.

@Test(timeout = 5000)
public void testSimpleDayOfWeekC() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2011).month(6).dayOfWeek("3").hour(22).minute(1).second(1).start(new Date(0));
    ;
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(null, trigger.getFireTimeAfter(new GregorianCalendar(2011, 5, 29, 23, 1, 1).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