Search in sources :

Example 1 with FieldConstraints

use of com.cronutils.model.field.constraint.FieldConstraints 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 FieldConstraints

use of com.cronutils.model.field.constraint.FieldConstraints in project cron-utils by jmrozanec.

the class OnDayOfMonthValueGeneratorLTest method setUp.

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

Example 3 with FieldConstraints

use of com.cronutils.model.field.constraint.FieldConstraints in project cron-utils by jmrozanec.

the class ValidationFieldExpressionVisitorTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final int startRange = 0;
    final int endRange = 59;
    fieldConstraints = new FieldConstraints(Collections.emptyMap(), Collections.emptyMap(), Collections.emptySet(), startRange, endRange, true);
    when(stringValidations.removeValidChars(any(String.class))).thenReturn(StringUtils.EMPTY);
    when(invalidStringValidations.removeValidChars(any(String.class))).thenReturn("$$$");
    strictVisitor = new ValidationFieldExpressionVisitor(fieldConstraints, stringValidations);
    visitor = new ValidationFieldExpressionVisitor(fieldConstraints, stringValidations);
}
Also used : FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) Before(org.junit.Before)

Example 4 with FieldConstraints

use of com.cronutils.model.field.constraint.FieldConstraints in project cron-utils by jmrozanec.

the class ValidationFieldExpressionVisitorTest method testVisitBetweenOOOrderNonStrict.

@Test
public void testVisitBetweenOOOrderNonStrict() {
    final int startRange = 0;
    final int endRange = 59;
    fieldConstraints = new FieldConstraints(Collections.emptyMap(), Collections.emptyMap(), Collections.emptySet(), startRange, endRange, false);
    visitor = new ValidationFieldExpressionVisitor(fieldConstraints, stringValidations);
    final Between between = new Between(new IntegerFieldValue(HIGH), new IntegerFieldValue(LOW));
    assertEquals(between, between.accept(visitor));
}
Also used : IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) Test(org.junit.Test)

Example 5 with FieldConstraints

use of com.cronutils.model.field.constraint.FieldConstraints in project cron-utils by jmrozanec.

the class FieldDefinitionBuilderTest method testAnd.

@Test
public void testAnd() {
    final FieldConstraints constraints = mock(FieldConstraints.class);
    when(mockConstraintsBuilder.createConstraintsInstance()).thenReturn(constraints);
    final ArgumentCaptor<FieldDefinition> argument = ArgumentCaptor.forClass(FieldDefinition.class);
    fieldDefinitionBuilder.and();
    verify(mockParserBuilder).register(argument.capture());
    assertEquals(testFieldName, argument.getValue().getFieldName());
    verify(mockConstraintsBuilder).createConstraintsInstance();
}
Also used : FieldDefinition(com.cronutils.model.field.definition.FieldDefinition) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)9 CronField (com.cronutils.model.field.CronField)4 IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)4 Test (org.junit.Test)4 FieldDefinition (com.cronutils.model.field.definition.FieldDefinition)3 Before (org.junit.Before)3 On (com.cronutils.model.field.expression.On)2 WeekDay (com.cronutils.mapper.WeekDay)1 Between (com.cronutils.model.field.expression.Between)1 Every (com.cronutils.model.field.expression.Every)1 ValidationFieldExpressionVisitor (com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor)1 SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)1 VisibleForTesting (com.cronutils.utils.VisibleForTesting)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1