Search in sources :

Example 21 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 22 with EJBCronTrigger

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

the class EJBCronTriggerTest method testCompoundListDayOfWeek.

@Test(timeout = 5000)
public void testCompoundListDayOfWeek() throws ParseException {
    final String[] dayOfWeeks = { "tue,wed,thu-fri", "wed,thu-fri,tue", "tue,wed,thu,thu-fri,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 23 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 24 with EJBCronTrigger

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

the class EJBCronTriggerTest method testInvalidListInputs.

@Test(timeout = 500)
public void testInvalidListInputs() throws ParseException {
    // invalid day of month
    final String invalid_day_of_month = "2ndXXX,-8";
    ScheduleExpression expr = new ScheduleExpression().dayOfMonth("1stsun,4,6," + invalid_day_of_month).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
    final String invalid_years = "19876,87";
    expr = new ScheduleExpression().year("1999,2012" + invalid_years).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
    final String invalid_month = "XXX,14";
    expr = new ScheduleExpression().month("1,2,4,sep," + invalid_month).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
    final String invalid_days_in_week = "8,WEEE";
    expr = new ScheduleExpression().month(5).dayOfWeek("SUN,4,5," + invalid_days_in_week).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  hours
    final String invalid_hours = "15,-2";
    expr = new ScheduleExpression().dayOfMonth(6).hour("1,5,9,18,22," + invalid_hours).minute(1).second(59).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  minute
    final String invalid_minutes = "61,-4";
    expr = new ScheduleExpression().dayOfMonth(6).hour(2).minute("1,45,58," + invalid_minutes).second(59).start(new Date(0));
    parseExceptionThrown = false;
    try {
        new EJBCronTrigger(expr);
    } catch (final ParseException e) {
        parseExceptionThrown = true;
    }
    assertTrue(parseExceptionThrown);
    // invalid  second
    final String invalid_seconds = "61,-4";
    expr = new ScheduleExpression().dayOfMonth(6).hour(2).minute(1).second("1,45,58," + invalid_seconds).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 25 with EJBCronTrigger

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

the class EJBCronTriggerTest method testOrdinalNumbersDayOfMonthE.

@Test(timeout = 5000)
public void testOrdinalNumbersDayOfMonthE() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfMonth("5th Sun-Last Sun").hour(23).minute(1).second(59);
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2100, 0, 31, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2100, 0, 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)

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