Search in sources :

Example 16 with IntegerFieldValue

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

the class ValidationFieldExpressionVisitorTest method testVisitBetween.

@Test
public void testVisitBetween() {
    Between between = new Between(new IntegerFieldValue(LOW), new IntegerFieldValue(MIDDLE));
    assertEquals(between, between.accept(strictVisitor));
    assertEquals(between, between.accept(visitor));
    between = new Between(new IntegerFieldValue(LOW), new SpecialCharFieldValue(SpecialChar.L));
    assertEquals(between, between.accept(strictVisitor));
    assertEquals(between, between.accept(visitor));
    between = new Between(new SpecialCharFieldValue(SpecialChar.L), new IntegerFieldValue(MIDDLE));
    assertEquals(between, between.accept(strictVisitor));
    assertEquals(between, between.accept(visitor));
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) Test(org.junit.Test)

Example 17 with IntegerFieldValue

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

the class ValidationFieldExpressionVisitorTest method testVisitAnd.

@Test
public void testVisitAnd() {
    final ValidationFieldExpressionVisitor spy = Mockito.spy(visitor);
    final ValidationFieldExpressionVisitor strictSpy = Mockito.spy(strictVisitor);
    And and = new And();
    final Between b1 = new Between(new IntegerFieldValue(LOW), new IntegerFieldValue(MIDDLE));
    final Between b2 = new Between(new IntegerFieldValue(MIDDLE), new IntegerFieldValue(HIGH));
    final On on = new On(new IntegerFieldValue(LOW));
    and.and(b1).and(b2).and(b2).and(on);
    assertEquals(and, and.accept(spy));
    assertEquals(and, and.accept(strictSpy));
    b1.accept(verify(spy, times(1)));
    b2.accept(verify(spy, times(2)));
    on.accept(verify(spy, times(1)));
    b1.accept(verify(strictSpy, times(1)));
    b2.accept(verify(strictSpy, times(2)));
    on.accept(verify(strictSpy, times(1)));
}
Also used : IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) Test(org.junit.Test)

Example 18 with IntegerFieldValue

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

the class ValidationFieldExpressionVisitorTest method testStrictVisitBadExp.

@Test(expected = IllegalArgumentException.class)
public void testStrictVisitBadExp() {
    final FieldExpression exp = new Between(new IntegerFieldValue(HIGH), new IntegerFieldValue(LOW));
    exp.accept(strictVisitor);
}
Also used : IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) Test(org.junit.Test)

Example 19 with IntegerFieldValue

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

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

the class FieldParser method parseOnWithLW.

@VisibleForTesting
protected On parseOnWithLW(final String exp) {
    final SpecialCharFieldValue specialChar = new SpecialCharFieldValue(LW);
    final String lwExpression = exp.replace(LW_STRING, EMPTY_STRING);
    if (EMPTY_STRING.equals(lwExpression)) {
        return new On(new IntegerFieldValue(-1), specialChar, new IntegerFieldValue(-1));
    } else {
        throw new IllegalArgumentException(String.format("Expected: LW, found: %s", lwExpression));
    }
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) VisibleForTesting(com.cronutils.utils.VisibleForTesting)

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