Search in sources :

Example 26 with IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue in project cron-utils by jmrozanec.

the class CronDescriptorTest method testLastDayOfWeekInMonth.

@Test
public void testLastDayOfWeekInMonth() {
    final int dayOfWeek = 2;
    final int hour = 10;
    final int minute = 15;
    final List<CronField> results = new ArrayList<>();
    results.add(new CronField(CronFieldName.HOUR, new On(new IntegerFieldValue(hour)), nullFieldConstraints));
    results.add(new CronField(CronFieldName.MINUTE, new On(new IntegerFieldValue(minute)), nullFieldConstraints));
    results.add(new CronField(CronFieldName.DAY_OF_WEEK, new On(new IntegerFieldValue(dayOfWeek), new SpecialCharFieldValue(SpecialChar.L)), nullFieldConstraints));
    assertEquals(String.format("at %s:%s last Tuesday of every month", hour, minute), descriptor.describe(new SingleCron(mockDefinition, results)));
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) ArrayList(java.util.ArrayList) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) SingleCron(com.cronutils.model.SingleCron) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Example 27 with IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue 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 28 with IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue in project cron-utils by jmrozanec.

the class BetweenFieldValueGeneratorTest method setUp.

@Before
public void setUp() {
    constraints = FieldConstraintsBuilder.instance().createConstraintsInstance();
    fieldValueGenerator = new BetweenFieldValueGenerator(new CronField(CronFieldName.HOUR, new Between(new IntegerFieldValue(FROM), new IntegerFieldValue(TO)), constraints));
}
Also used : Between(com.cronutils.model.field.expression.Between) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) CronField(com.cronutils.model.field.CronField) Before(org.junit.Before)

Example 29 with IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue in project cron-utils by jmrozanec.

the class OnDayOfMonthValueGeneratorTest method setUp.

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

Example 30 with IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue 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

IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)43 Test (org.junit.Test)32 CronField (com.cronutils.model.field.CronField)18 SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)16 On (com.cronutils.model.field.expression.On)13 SingleCron (com.cronutils.model.SingleCron)10 ArrayList (java.util.ArrayList)10 Between (com.cronutils.model.field.expression.Between)6 Before (org.junit.Before)6 WeekDay (com.cronutils.mapper.WeekDay)4 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)4 Every (com.cronutils.model.field.expression.Every)3 VisibleForTesting (com.cronutils.utils.VisibleForTesting)3 And (com.cronutils.model.field.expression.And)1 SpecialChar (com.cronutils.model.field.value.SpecialChar)1