Search in sources :

Example 11 with SpecialCharFieldValue

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

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

Example 13 with SpecialCharFieldValue

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

the class CronDescriptorTest method testNthDayOfWeekInMonth.

@Test
public void testNthDayOfWeekInMonth() {
    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.HASH), new IntegerFieldValue(dayOfWeek)), nullFieldConstraints));
    assertEquals(String.format("at %s:%s Tuesday %s of every month", hour, minute, dayOfWeek), 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 14 with SpecialCharFieldValue

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

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

the class OnTest method testAsStringSpecialCharW.

@Test
public void testAsStringSpecialCharW() {
    final String expression = "1W";
    assertEquals(expression, new On(new IntegerFieldValue(1), new SpecialCharFieldValue(SpecialChar.W)).asString());
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) Test(org.junit.Test)

Aggregations

SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)23 Test (org.junit.Test)17 IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)16 CronField (com.cronutils.model.field.CronField)5 On (com.cronutils.model.field.expression.On)5 SingleCron (com.cronutils.model.SingleCron)4 ArrayList (java.util.ArrayList)4 SpecialChar (com.cronutils.model.field.value.SpecialChar)3 VisibleForTesting (com.cronutils.utils.VisibleForTesting)3 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)1 Before (org.junit.Before)1