Search in sources :

Example 31 with CronField

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

Example 32 with CronField

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

the class CronParserFieldTest method testParse.

@Test
public void testParse() {
    final String cron = UUID.randomUUID().toString();
    final CronField result = cronParserField.parse(cron);
    Assert.assertEquals(mockParseResponse, result.getExpression());
    Assert.assertEquals(testFieldName, result.getField());
    Mockito.verify(mockParser).parse(cron);
}
Also used : CronField(com.cronutils.model.field.CronField) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 33 with CronField

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

the class CronMapperTest method testReturnOnZeroExpression.

@Test
public void testReturnOnZeroExpression() {
    final Function<CronField, CronField> function = CronMapper.returnOnZeroExpression(testCronFieldName);
    assertEquals(testCronFieldName, function.apply(mockCronField).getField());
    final On result = (On) function.apply(mockCronField).getExpression();
    assertEquals(0, (int) result.getTime().getValue());
}
Also used : CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Example 34 with CronField

use of com.cronutils.model.field.CronField in project dolphinscheduler by apache.

the class CronUtilsTest method test2.

/**
 * test
 */
@Test
public void test2() {
    Cron cron1 = CronBuilder.cron(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)).withYear(always()).withDoW(questionMark()).withMonth(always()).withDoM(always()).withHour(always()).withMinute(every(5)).withSecond(on(0)).instance();
    // minute cycle
    String[] cronArayy = new String[] { "* * * * * ? *", "* 0 * * * ? *", "* 5 * * 3/5 ? *", "0 0 * * * ? *" };
    for (String minCrontab : cronArayy) {
        if (!org.quartz.CronExpression.isValidExpression(minCrontab)) {
            throw new RuntimeException(minCrontab + " verify failure, cron expression not valid");
        }
        Cron cron = CronUtils.parse2Cron(minCrontab);
        CronField minField = cron.retrieve(CronFieldName.MINUTE);
        logger.info("minField instanceof Between:" + (minField.getExpression() instanceof Between));
        logger.info("minField instanceof Every:" + (minField.getExpression() instanceof Every));
        logger.info("minField instanceof Always:" + (minField.getExpression() instanceof Always));
        logger.info("minField instanceof On:" + (minField.getExpression() instanceof On));
        logger.info("minField instanceof And:" + (minField.getExpression() instanceof And));
        CronField hourField = cron.retrieve(CronFieldName.HOUR);
        logger.info("hourField instanceof Between:" + (hourField.getExpression() instanceof Between));
        logger.info("hourField instanceof Always:" + (hourField.getExpression() instanceof Always));
        logger.info("hourField instanceof Every:" + (hourField.getExpression() instanceof Every));
        logger.info("hourField instanceof On:" + (hourField.getExpression() instanceof On));
        logger.info("hourField instanceof And:" + (hourField.getExpression() instanceof And));
        CronField dayOfMonthField = cron.retrieve(CronFieldName.DAY_OF_MONTH);
        logger.info("dayOfMonthField instanceof Between:" + (dayOfMonthField.getExpression() instanceof Between));
        logger.info("dayOfMonthField instanceof Always:" + (dayOfMonthField.getExpression() instanceof Always));
        logger.info("dayOfMonthField instanceof Every:" + (dayOfMonthField.getExpression() instanceof Every));
        logger.info("dayOfMonthField instanceof On:" + (dayOfMonthField.getExpression() instanceof On));
        logger.info("dayOfMonthField instanceof And:" + (dayOfMonthField.getExpression() instanceof And));
        logger.info("dayOfMonthField instanceof QuestionMark:" + (dayOfMonthField.getExpression() instanceof QuestionMark));
        CronField monthField = cron.retrieve(CronFieldName.MONTH);
        logger.info("monthField instanceof Between:" + (monthField.getExpression() instanceof Between));
        logger.info("monthField instanceof Always:" + (monthField.getExpression() instanceof Always));
        logger.info("monthField instanceof Every:" + (monthField.getExpression() instanceof Every));
        logger.info("monthField instanceof On:" + (monthField.getExpression() instanceof On));
        logger.info("monthField instanceof And:" + (monthField.getExpression() instanceof And));
        logger.info("monthField instanceof QuestionMark:" + (monthField.getExpression() instanceof QuestionMark));
        CronField dayOfWeekField = cron.retrieve(CronFieldName.DAY_OF_WEEK);
        logger.info("dayOfWeekField instanceof Between:" + (dayOfWeekField.getExpression() instanceof Between));
        logger.info("dayOfWeekField instanceof Always:" + (dayOfWeekField.getExpression() instanceof Always));
        logger.info("dayOfWeekField instanceof Every:" + (dayOfWeekField.getExpression() instanceof Every));
        logger.info("dayOfWeekField instanceof On:" + (dayOfWeekField.getExpression() instanceof On));
        logger.info("dayOfWeekField instanceof And:" + (dayOfWeekField.getExpression() instanceof And));
        logger.info("dayOfWeekField instanceof QuestionMark:" + (dayOfWeekField.getExpression() instanceof QuestionMark));
        CycleEnum cycleEnum = CronUtils.getMaxCycle(minCrontab);
        if (cycleEnum != null) {
            logger.info(cycleEnum.name());
        } else {
            logger.info("can't get scheduleType");
        }
    }
    Assert.assertTrue(true);
}
Also used : CycleEnum(org.apache.dolphinscheduler.common.enums.CycleEnum) Cron(com.cronutils.model.Cron) CronField(com.cronutils.model.field.CronField) Test(org.junit.Test)

Aggregations

CronField (com.cronutils.model.field.CronField)34 IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)18 Test (org.junit.Test)16 On (com.cronutils.model.field.expression.On)15 SingleCron (com.cronutils.model.SingleCron)13 ArrayList (java.util.ArrayList)13 Before (org.junit.Before)7 Between (com.cronutils.model.field.expression.Between)6 SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)5 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)4 WeekDay (com.cronutils.mapper.WeekDay)3 Cron (com.cronutils.model.Cron)3 CronFieldName (com.cronutils.model.field.CronFieldName)3 Every (com.cronutils.model.field.expression.Every)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 CompositeCron (com.cronutils.model.CompositeCron)2 And (com.cronutils.model.field.expression.And)2 ValidationFieldExpressionVisitor (com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor)2 CronConstraint (com.cronutils.model.definition.CronConstraint)1 FieldConstraintsBuilder (com.cronutils.model.field.constraint.FieldConstraintsBuilder)1