Search in sources :

Example 31 with ScheduleExpression

use of javax.ejb.ScheduleExpression 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 32 with ScheduleExpression

use of javax.ejb.ScheduleExpression 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 33 with ScheduleExpression

use of javax.ejb.ScheduleExpression 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 34 with ScheduleExpression

use of javax.ejb.ScheduleExpression 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)

Example 35 with ScheduleExpression

use of javax.ejb.ScheduleExpression 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)

Aggregations

ScheduleExpression (javax.ejb.ScheduleExpression)75 GregorianCalendar (java.util.GregorianCalendar)60 Test (org.junit.Test)52 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)44 Date (java.util.Date)34 Calendar (java.util.Calendar)21 CalendarBasedTimeout (org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout)17 TimerConfig (javax.ejb.TimerConfig)4 TimeZone (java.util.TimeZone)3 ArrayList (java.util.ArrayList)2 ParseException (org.apache.openejb.core.timer.EJBCronTrigger.ParseException)2 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 PostConstruct (javax.annotation.PostConstruct)1 EJBException (javax.ejb.EJBException)1 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)1 ScheduleData (org.apache.openejb.core.timer.ScheduleData)1 AutoTimer (org.jboss.as.ejb3.timerservice.AutoTimer)1 ModelNode (org.jboss.dmr.ModelNode)1