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);
}
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()));
}
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()));
}
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()));
}
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);
}
Aggregations