Search in sources :

Example 1 with WeekDay

use of com.cronutils.mapper.WeekDay in project cron-utils by jmrozanec.

the class EveryDayOfWeekValueGeneratorTest method setUp.

@Before
public void setUp() {
    FieldConstraints constraints = FieldConstraintsBuilder.instance().createConstraintsInstance();
    // every 2 days between 1-5
    final CronField cronField = new CronField(CronFieldName.DAY_OF_WEEK, new Every(new Between(new IntegerFieldValue(1), new IntegerFieldValue(5)), new IntegerFieldValue(2)), constraints);
    // Using monday = 1
    WeekDay mondayDoWValue = new WeekDay(1, false);
    // so MON-FRI/2, which should translate to MON,WED,FRI
    validDow = EnumSet.of(DayOfWeek.MONDAY, DayOfWeek.WEDNESDAY, DayOfWeek.FRIDAY);
    fieldValueGenerator = new EveryDayOfWeekValueGenerator(cronField, year, month, mondayDoWValue);
}
Also used : WeekDay(com.cronutils.mapper.WeekDay) Between(com.cronutils.model.field.expression.Between) Every(com.cronutils.model.field.expression.Every) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) CronField(com.cronutils.model.field.CronField) Before(org.junit.Before)

Example 2 with WeekDay

use of com.cronutils.mapper.WeekDay in project cron-utils by jmrozanec.

the class FieldValueGeneratorFactoryTest method testCreateDayOfWeekValueGeneratorInstanceBetween.

@Test
public void testCreateDayOfWeekValueGeneratorInstanceBetween() {
    final Between between = new Between(new IntegerFieldValue(1), new IntegerFieldValue(7));
    when(mockCronField.getField()).thenReturn(CronFieldName.DAY_OF_WEEK);
    when(mockCronField.getExpression()).thenReturn(between);
    assertEquals(BetweenDayOfWeekValueGenerator.class, FieldValueGeneratorFactory.createDayOfWeekValueGeneratorInstance(mockCronField, 2015, 1, new WeekDay(1, false)).getClass());
}
Also used : WeekDay(com.cronutils.mapper.WeekDay) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) Test(org.junit.Test)

Example 3 with WeekDay

use of com.cronutils.mapper.WeekDay in project cron-utils by jmrozanec.

the class FieldValueGeneratorFactoryTest method testCreateDayOfWeekValueGeneratorInstanceBadCronFieldName.

@Test(expected = IllegalArgumentException.class)
public void testCreateDayOfWeekValueGeneratorInstanceBadCronFieldName() {
    when(mockCronField.getField()).thenReturn(CronFieldName.YEAR);
    when(mockCronField.getExpression()).thenReturn(mock(On.class));
    FieldValueGeneratorFactory.createDayOfWeekValueGeneratorInstance(mockCronField, 2015, 1, new WeekDay(1, false));
}
Also used : WeekDay(com.cronutils.mapper.WeekDay) Test(org.junit.Test)

Example 4 with WeekDay

use of com.cronutils.mapper.WeekDay in project cron-utils by jmrozanec.

the class BetweenDayOfWeekValueGeneratorTest method testGenerateCandidatesNotIncludingIntervalExtremes.

@Test
public void testGenerateCandidatesNotIncludingIntervalExtremes() {
    // cron expression: DoW 1-5,
    // on February 2016: 1-5, 8-12, 15-19, 22-26, 29
    final CronField cronField = new CronField(CronFieldName.DAY_OF_WEEK, new Between(new IntegerFieldValue(1), new IntegerFieldValue(5)), FieldConstraintsBuilder.instance().createConstraintsInstance());
    final BetweenDayOfWeekValueGenerator generator = new BetweenDayOfWeekValueGenerator(cronField, 2016, 2, new WeekDay(1, true));
    final List<Integer> values = generator.generateCandidates(1, 29);
    validateInterval(1, 5, values);
    validateInterval(8, 12, values);
    validateInterval(15, 19, values);
    validateInterval(22, 26, values);
    assertTrue(values.contains(29));
}
Also used : WeekDay(com.cronutils.mapper.WeekDay) Between(com.cronutils.model.field.expression.Between) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) CronField(com.cronutils.model.field.CronField) Test(org.junit.Test)

Example 5 with WeekDay

use of com.cronutils.mapper.WeekDay in project cron-utils by jmrozanec.

the class OnDayOfWeekValueGeneratorTest method setUp.

@Before
public void setUp() {
    constraints = FieldConstraintsBuilder.instance().createConstraintsInstance();
    mondayDoWValue = new WeekDay(1, false);
    fieldValueGenerator = new OnDayOfWeekValueGenerator(new CronField(CronFieldName.DAY_OF_WEEK, new On(new IntegerFieldValue(3)), constraints), YEAR, MONTH, mondayDoWValue);
}
Also used : WeekDay(com.cronutils.mapper.WeekDay) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Before(org.junit.Before)

Aggregations

WeekDay (com.cronutils.mapper.WeekDay)7 Test (org.junit.Test)5 IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)4 CronField (com.cronutils.model.field.CronField)3 Between (com.cronutils.model.field.expression.Between)2 Before (org.junit.Before)2 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)1 Every (com.cronutils.model.field.expression.Every)1 On (com.cronutils.model.field.expression.On)1