Search in sources :

Example 1 with ParseException

use of org.apache.openejb.core.timer.EJBCronTrigger.ParseException 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 2 with ParseException

use of org.apache.openejb.core.timer.EJBCronTrigger.ParseException 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

Date (java.util.Date)2 ScheduleExpression (javax.ejb.ScheduleExpression)2 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)2 ParseException (org.apache.openejb.core.timer.EJBCronTrigger.ParseException)2 Test (org.junit.Test)2