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