Java Code Examples for com.cronutils.descriptor.CronDescriptor#instance()

The following examples show how to use com.cronutils.descriptor.CronDescriptor#instance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuartzServiceImpl.java    From spring-batch-quartz-admin with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param jobName
 * @return String
 */
public String getScheduledJobDescription(String jobName) {
    String message = Constants.JOB_IS_NOT_SCHEDULED;
    JobKey jobKey = new JobKey(jobName, Constants.QUARTZ_GROUP);
    try {
        JobDetail jobDetail = schedulerFactory.getScheduler().getJobDetail(jobKey);
        if (null != jobDetail) {
            List<? extends Trigger> triggersOfJob = schedulerFactory.getScheduler().getTriggersOfJob(jobKey);
            if (null != triggersOfJob && !triggersOfJob.isEmpty()) {
                CronTrigger trigger = (CronTrigger) triggersOfJob.get(0);
                String cronExpression = trigger.getCronExpression();
                CronDescriptor descriptor = CronDescriptor.instance(Locale.US);
                CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(QUARTZ));
                message = descriptor.describe(parser.parse(cronExpression));
            }

        }
    } catch (SchedulerException e) {
        BatchAdminLogger.getLogger().error(e.getMessage(), e);
    }
    return message;
}
 
Example 2
Source File: Issue423Test.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
@Test
    public void issue423() {
        final CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
        final Cron cron = parser.parse("0 0 0-07,17-0 ? * SAT");
        final CronDescriptor cd = CronDescriptor.instance(Locale.UK);
        assertTrue(cd.describe(cron).length() > 0);
        // at time of test creation, the descriptor is
        // "every hour between 0 and 7 and every hour between 17 and 0 at Saturday day"

        final ExecutionTime et = ExecutionTime.forCron(cron);
        // At this point, an an exception WAS logged. But, not anymore!

        Arrays.asList(
            new TestPair(shortZDT( 0,  0), shortZDT( 1, 0)),
            new TestPair(shortZDT( 0, 30), shortZDT( 1, 0)),
            new TestPair(shortZDT( 6,  0), shortZDT( 7, 0)),
            new TestPair(shortZDT( 7,  0), shortZDT(17, 0)),
            new TestPair(shortZDT(16,  0), shortZDT(17, 0)), // Should be 17:00, but skips to the next Saturday
            new TestPair(shortZDT(17,  0), shortZDT(18, 0)), // Should be 18:00, but skips to the next Saturday
            new TestPair(shortZDT(18,  0), shortZDT(19, 0))  // Should be 19:00, but skips to the next Saturday
        ).forEach(tp -> {
//            System.err.println("Expected: " + tp.expected + "; Actual: " + et.nextExecution(tp.test).get().toString());
            assertEquals(
                "All these should be on the same Saturday",
                tp.expected,
                et.nextExecution(tp.test).get()
            );
        });
    }
 
Example 3
Source File: CronParserQuartzIntegrationTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #39: reported issue about exception being raised on parse.
 */
@Test
public void testDescribeExpressionWithQuestionMarkAndWeekdays() {
    final Cron quartzCron = parser.parse("0 0 0 ? * MON,TUE *");
    final CronDescriptor descriptor = CronDescriptor.instance(Locale.ENGLISH);
    descriptor.describe(quartzCron);
}
 
Example 4
Source File: Issue227Test.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void testProperDescriptorOutput() {
    final Cron cron = parser.parse("0 5-35/30 * * * ?");
    final CronDescriptor descriptor = CronDescriptor.instance(Locale.US);
    final String description = descriptor.describe(cron);

    assertEquals("every 30 minutes between 5 and 35", description);
}
 
Example 5
Source File: Issue227Test.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void testProperDescriptorOutputWithSeconds() {
    final Cron cron = parser.parse("5-35/30 * * * * ?");
    final CronDescriptor descriptor = CronDescriptor.instance(Locale.US);
    final String description = descriptor.describe(cron);

    assertEquals("every 30 seconds between 5 and 35", description);
}
 
Example 6
Source File: CronDescriptorTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    descriptor = CronDescriptor.instance(Locale.UK);
    nullFieldConstraints =
            FieldConstraintsBuilder.instance()
                    .addHashSupport()
                    .addLSupport()
                    .addWSupport()
                    .createConstraintsInstance();
}
 
Example 7
Source File: ExecutionTimeQuartzIntegrationTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #114: Describe day of week is incorrect.
 */
@Test
public void descriptionForExpressionTellsWrongDoW() {
    final CronDescriptor descriptor = CronDescriptor.instance();
    final Cron quartzCron = parser.parse("0 0 8 ? * SUN *");
    assertEquals("at 08:00 at Sunday day", descriptor.describe(quartzCron));
}
 
Example 8
Source File: CronTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
public void testIssue308(){
    CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
    CronParser parser = new CronParser(cronDefinition);
    Cron quartzCron = parser.parse("0 0 11 L-2 * ?");
    CronDescriptor descriptor = CronDescriptor.instance(Locale.ENGLISH);
    String description = descriptor.describe(quartzCron);

    // not sure what the exact string 'should' be ..
    assertEquals( "at 11:00 two days before the last day of month", description);
}
 
Example 9
Source File: MaintenanceWindowLayout.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
public CronTranslationListener() {
    cronDescriptor = CronDescriptor.instance(getClientsLocale());
}
 
Example 10
Source File: CronDescriptorQuartzIntegrationTest.java    From cron-utils with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    descriptor = CronDescriptor.instance(Locale.UK);
    parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
}
 
Example 11
Source File: CronDescriptorCron4jIntegrationZhTest.java    From cron-utils with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    descriptor = CronDescriptor.instance(Locale.CHINESE);
    parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.CRON4J));
}
 
Example 12
Source File: CronDescriptorCron4jIntegrationTest.java    From cron-utils with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    descriptor = CronDescriptor.instance(Locale.UK);
    parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.CRON4J));
}