com.cronutils.descriptor.CronDescriptor Java Examples

The following examples show how to use com.cronutils.descriptor.CronDescriptor. 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: AbstractMirror.java    From centraldogma with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    final ToStringHelper helper = MoreObjects.toStringHelper("")
                                             .add("schedule", CronDescriptor.instance().describe(schedule))
                                             .add("direction", direction)
                                             .add("localProj", localRepo.parent().name())
                                             .add("localRepo", localRepo.name())
                                             .add("localPath", localPath)
                                             .add("remoteRepo", remoteRepoUri)
                                             .add("remotePath", remotePath);
    if (remoteBranch != null) {
        helper.add("remoteBranch", remoteBranch);
    }

    helper.add("credential", credential);

    return helper.toString();
}
 
Example #3
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 #4
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 #5
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 #6
Source File: Issue343Test.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
public void workaround() {
	CronParser pareser = new CronParser( workingSpringCronDefinition() );
	
	String actualDescription = CronDescriptor.instance(Locale.ENGLISH)
			.describe(pareser.parse(expressionToTest.getExpression()));
	
	Assert.assertThat(actualDescription, IsEqual.equalTo(expressionToTest.getExpectedDescription()));
}
 
Example #7
Source File: Issue343Test.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
public void test() {
	CronParser pareser = new CronParser( CronDefinitionBuilder.instanceDefinitionFor(CronType.SPRING) );
	
	String actualDescription = CronDescriptor.instance(Locale.ENGLISH)
			.describe(pareser.parse(expressionToTest.getExpression()));
	
	Assert.assertThat(actualDescription, IsEqual.equalTo(expressionToTest.getExpectedDescription()));
}
 
Example #8
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 #9
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 #10
Source File: CronParserQuartzIntegrationTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #60: Parser exception when parsing cron.
 */
@Test
public void testDescribeExpression() {
    final String expression = "0 * * ? * 1,5";
    final Cron c = parser.parse(expression);
    CronDescriptor.instance(Locale.GERMAN).describe(c);
}
 
Example #11
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 #12
Source File: Issue338Test.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void testEverySecondInFrench() {
	CronParser cronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
	String cronString = "* * * * * ? *";
	Cron cron = cronParser.parse(cronString);
	String description = CronDescriptor.instance(Locale.FRANCE).describe(cron);
	Assert.assertEquals("chaque seconde", description);
}
 
Example #13
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 #14
Source File: Issue421Test.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testWrongEveryXMonthsDescription() {
    ZonedDateTime now = ZonedDateTime.now();

    String description = CronDescriptor.instance(Locale.US).describe(getEveryMonth(now, 3).instance());
    System.out.println(description);
    Assert.assertTrue(description.contains("every 3 months"));

    description = CronDescriptor.instance(Locale.US).describe(getEveryMonth(now, 6).instance());
    System.out.println(description);
    Assert.assertTrue(description.contains("every 6 months"));
}
 
Example #15
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 #16
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 #17
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));
}
 
Example #18
Source File: MaintenanceWindowLayout.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
public CronTranslationListener() {
    cronDescriptor = CronDescriptor.instance(getClientsLocale());
}