Search in sources :

Example 11 with SingleCron

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

use of com.cronutils.model.SingleCron in project cron-utils by jmrozanec.

the class CronDescriptorTest method testDescribeAtXTimeBetweenDaysOfWeek.

@Test
public void testDescribeAtXTimeBetweenDaysOfWeek() {
    final int hour = 11;
    final int minute = 30;
    final int start = 2;
    final int end = 6;
    final Between expression = new Between(new IntegerFieldValue(start), new IntegerFieldValue(end));
    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, expression, nullFieldConstraints));
    assertEquals(String.format("at %s:%s every day between Tuesday and Saturday", hour, minute), descriptor.describe(new SingleCron(mockDefinition, results)));
}
Also used : Between(com.cronutils.model.field.expression.Between) 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 13 with SingleCron

use of com.cronutils.model.SingleCron 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)

Aggregations

SingleCron (com.cronutils.model.SingleCron)13 CronField (com.cronutils.model.field.CronField)13 ArrayList (java.util.ArrayList)11 IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)10 Test (org.junit.Test)10 On (com.cronutils.model.field.expression.On)9 SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)4 Between (com.cronutils.model.field.expression.Between)3 CompositeCron (com.cronutils.model.CompositeCron)2 CronFieldName (com.cronutils.model.field.CronFieldName)2 Cron (com.cronutils.model.Cron)1 Every (com.cronutils.model.field.expression.Every)1