本文整理汇总了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));
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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));
}
示例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();
}
示例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;
}