当前位置: 首页>>代码示例>>Java>>正文


Java Cron.validate方法代码示例

本文整理汇总了Java中com.cronutils.model.Cron.validate方法的典型用法代码示例。如果您正苦于以下问题:Java Cron.validate方法的具体用法?Java Cron.validate怎么用?Java Cron.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.cronutils.model.Cron的用法示例。


在下文中一共展示了Cron.validate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMustMatchCronEvenIfNanoSecondsVaries

import com.cronutils.model.Cron; //导入方法依赖的package包/类
@Test
public void testMustMatchCronEvenIfNanoSecondsVaries() {
    final CronDefinition cronDefinition =
            CronDefinitionBuilder.instanceDefinitionFor(QUARTZ);

    final CronParser parser = new CronParser(cronDefinition);
    final Cron quartzCron = parser.parse("00 00 10 * * ?");

    quartzCron.validate();

    // NOTE: Off by 3 nano seconds
    final ZonedDateTime zdt = ZonedDateTime.of(1999, 07, 18, 10, 00, 00, 03, ZoneId.systemDefault());

    // Must be true
    assertTrue("Nano seconds must not affect matching of Cron Expressions", ExecutionTime.forCron(quartzCron).isMatch(zdt));
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:17,代码来源:Issue200Test.java

示例2: supportQuartzCronExpressionIncrementsOnYears

import com.cronutils.model.Cron; //导入方法依赖的package包/类
/**
 * Issue #154: Quartz Cron Year Pattern is not fully supported - i.e. increments on years are not supported
 * https://github.com/jmrozanec/cron-utils/issues/154
 * Duplicate of #148
 */
@Test
public void supportQuartzCronExpressionIncrementsOnYears() {
    final String[] sampleCronExpressions = {
            "0 0 0 1 * ? 2017/2",
            "0 0 0 1 * ? 2017/3",
            "0 0 0 1 * ? 2017/10",
            "0 0 0 1 * ? 2017-2047/2",
    };

    final CronParser quartzCronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
    for (final String cronExpression : sampleCronExpressions) {
        final Cron quartzCron = quartzCronParser.parse(cronExpression);
        quartzCron.validate();
    }
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:21,代码来源:CronParserQuartzIntegrationTest.java

示例3: parseQuartzCron

import com.cronutils.model.Cron; //导入方法依赖的package包/类
private static String parseQuartzCron(final String cron) {

        final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.CRON4J);
        //create a parser based on provided definition
        final com.cronutils.parser.CronParser parser = new com.cronutils.parser.CronParser(cronDefinition);
        final Cron cron4jCron = parser.parse(cron);
        cron4jCron.validate();

        // Migrate types
        final CronMapper cronMapper = CronMapper.fromCron4jToQuartz();
        final Cron quartzCron = cronMapper.map(cron4jCron);

        return quartzCron.asString();
    }
 
开发者ID:ftsakiris,项目名称:async-engine,代码行数:15,代码来源:ScheduledTaskService.java

示例4: cronValidation

import com.cronutils.model.Cron; //导入方法依赖的package包/类
private static void cronValidation(final String[] args) throws ParseException {
    final Options options = new Options();
    options.addOption("v", "validate", false, "Action of validation (default)");
    options.addOption("f", "format", true,
            "Cron expression format to validate. Possible values are: CRON4J, QUARTZ, UNIX");
    options.addOption("e", "expression", true, "Cron expression to validate. Example: '* 1 * * *'");
    options.addOption("h", HELP, false, "Help");

    final String header = "Cron expressions validation by cron-utils\n\n";
    final String footer = "\nPlease report issues at https://github.com/jmrozanec/cron-utils/issues";

    final CommandLineParser parser = new DefaultParser();
    final CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption(HELP) || cmd.getOptions().length == 0) {
        showHelp(options, header, footer);
        return;
    }
    if (!cmd.hasOption("validate")) {
        showHelp(options, header, footer);
        return;
    }
    if (cmd.hasOption('v')) {
        final String format = cmd.getOptionValue("f");
        final String expression = cmd.getOptionValue("e");

        final CronType cronType = CronType.valueOf(format);
        final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(cronType);
        final CronParser cronParser = new CronParser(cronDefinition);
        final Cron quartzCron = cronParser.parse(expression);
        quartzCron.validate();
    }
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:33,代码来源:CronUtilsCLI.java

示例5: testMatchExact

import com.cronutils.model.Cron; //导入方法依赖的package包/类
@Test
public void testMatchExact() {
    final CronDefinition cronDefinition =
            CronDefinitionBuilder.instanceDefinitionFor(QUARTZ);

    final CronParser parser = new CronParser(cronDefinition);
    final Cron quartzCron = parser.parse("00 00 10 * * ?");

    quartzCron.validate();

    final ZonedDateTime zdt = ZonedDateTime.of(1999, 07, 18, 10, 00, 00, 00, ZoneId.systemDefault());

    assertTrue("Nano seconds must not affect matching of Cron Expressions", ExecutionTime.forCron(quartzCron).isMatch(zdt));
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:15,代码来源:Issue200Test.java

示例6: testCronDefinitionShouldNotAcceptQuestionmark

import com.cronutils.model.Cron; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testCronDefinitionShouldNotAcceptQuestionmark() {
    final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    final CronParser parser = new CronParser(cronDefinition);
    final Cron quartzCron = parser.parse("* * * * ?");
    quartzCron.validate();
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:8,代码来源:CronDefinitionBuilderTest.java

示例7: validateInternal

import com.cronutils.model.Cron; //导入方法依赖的package包/类
private List<ErrorReport> validateInternal( JobConfiguration jobConfiguration )
{
    List<ErrorReport> errorReports = new ArrayList<>();
    if ( !jobConfiguration.isConfigurable() )
    {
        errorReports
            .add( new ErrorReport( JobConfiguration.class, ErrorCode.E7003, jobConfiguration.getJobType() ) );
    }

    if ( !jobConfiguration.isContinuousExecution() )
    {
        if ( jobConfiguration.getCronExpression() == null )
        {
            errorReports.add( new ErrorReport( JobConfiguration.class, ErrorCode.E7004 ) );
            return errorReports;
        }

        // Validate the cron expression
        CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor( QUARTZ );
        CronParser parser = new CronParser( cronDefinition );
        Cron quartzCron;
        try
        {
            quartzCron = parser.parse( jobConfiguration.getCronExpression() );
            quartzCron.validate();
        }
        catch ( IllegalArgumentException e )
        {
            errorReports.add( new ErrorReport( JobConfiguration.class, ErrorCode.E7005, e ) );
            return errorReports;
        }
    }

    // Validate cron expression with relation to all other jobs
    errorReports.addAll( validateCronForJobType( jobConfiguration ) );

    // Validate parameters
    ErrorReport parameterValidation =
        jobConfiguration.getJobParameters() != null ? jobConfiguration.getJobParameters().validate() : null;
    if ( parameterValidation != null )
    {
        errorReports.add( parameterValidation );
    }

    Job job = schedulingManager.getJob( jobConfiguration.getJobType() );
    ErrorReport jobValidation = job.validate();
    if ( jobValidation != null )
    {
        errorReports.add( jobValidation );
    }

    return errorReports;
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:54,代码来源:JobConfigurationObjectBundleHook.java


注:本文中的com.cronutils.model.Cron.validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。