Search in sources :

Example 6 with OneTimeCalendar

use of com.enonic.xp.scheduler.OneTimeCalendar in project xp by enonic.

the class CalendarServiceImplTest method oneTime.

@Test
public void oneTime() {
    final OneTimeCalendar calendar = calendarService.oneTime(Instant.parse("2014-09-25T10:00:00.00Z"));
    assertTrue(calendar.nextExecution().get().isNegative());
    assertEquals(Instant.parse("2014-09-25T10:00:00.00Z"), calendar.getValue());
}
Also used : OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) Test(org.junit.jupiter.api.Test)

Example 7 with OneTimeCalendar

use of com.enonic.xp.scheduler.OneTimeCalendar in project xp by enonic.

the class SchedulerResourceTest method list.

@Test
public void list() throws Exception {
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing");
    final CronCalendar cronCalendar = new CronCalendar() {

        @Override
        public String getCronValue() {
            return "* * * * *";
        }

        @Override
        public TimeZone getTimeZone() {
            return TimeZone.getTimeZone("GMT+3:00");
        }

        public Optional<Duration> nextExecution() {
            return Optional.of(Duration.ofSeconds(50));
        }

        @Override
        public ScheduleCalendarType getType() {
            return ScheduleCalendarType.CRON;
        }
    };
    final OneTimeCalendar oneTimeCalendar = new OneTimeCalendar() {

        @Override
        public Instant getValue() {
            return Instant.parse("2016-11-02T10:36:00Z");
        }

        @Override
        public Optional<Duration> nextExecution() {
            return Optional.of(Duration.ofSeconds(50));
        }

        @Override
        public ScheduleCalendarType getType() {
            return ScheduleCalendarType.ONE_TIME;
        }
    };
    final PropertyTree config = new PropertyTree();
    config.addString("string", "value");
    final ScheduledJob job1 = ScheduledJob.create().name(ScheduledJobName.from("test1")).descriptor(descriptor).calendar(cronCalendar).config(config).enabled(true).description("description").creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:modifier")).user(PrincipalKey.from("user:system:user")).lastRun(Instant.parse("2012-01-01T00:00:00.00Z")).lastTaskId(TaskId.from("task-id")).createdTime(Instant.parse("2010-01-01T00:00:00.00Z")).modifiedTime(Instant.parse("2011-02-01T00:00:00.00Z")).lastRun(Instant.parse("2012-01-01T00:00:00.00Z")).build();
    final ScheduledJob job2 = ScheduledJob.create().name(ScheduledJobName.from("test2")).descriptor(descriptor).calendar(oneTimeCalendar).creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:modifier")).createdTime(Instant.parse("2010-01-01T00:00:00.00Z")).modifiedTime(Instant.parse("2011-02-01T00:00:00.00Z")).build();
    Mockito.when(schedulerService.list()).thenReturn(List.of(job1, job2));
    final String result = request().path("scheduler/list").get().getAsString();
    assertJson("list_scheduled_jobs.json", result);
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) PropertyTree(com.enonic.xp.data.PropertyTree) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) DescriptorKey(com.enonic.xp.page.DescriptorKey) Duration(java.time.Duration) Test(org.junit.jupiter.api.Test)

Example 8 with OneTimeCalendar

use of com.enonic.xp.scheduler.OneTimeCalendar in project xp by enonic.

the class BaseScheduledJobHandlerTest method mockOneTimeCalendar.

protected void mockOneTimeCalendar() {
    Mockito.when(calendarService.oneTime(Mockito.isA(Instant.class))).thenAnswer(invocation -> {
        final OneTimeCalendar oneTime = Mockito.mock(OneTimeCalendar.class);
        Mockito.when(oneTime.getType()).thenReturn(ScheduleCalendarType.ONE_TIME);
        Mockito.when(oneTime.getValue()).thenReturn(invocation.getArgument(0));
        return oneTime;
    });
}
Also used : Instant(java.time.Instant) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar)

Aggregations

OneTimeCalendar (com.enonic.xp.scheduler.OneTimeCalendar)8 CronCalendar (com.enonic.xp.scheduler.CronCalendar)5 Test (org.junit.jupiter.api.Test)4 PropertySet (com.enonic.xp.data.PropertySet)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)3 Instant (java.time.Instant)3 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)2 ScheduleCalendar (com.enonic.xp.scheduler.ScheduleCalendar)2 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)2 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 AuditLogService (com.enonic.xp.audit.AuditLogService)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 CalendarServiceImpl (com.enonic.xp.impl.scheduler.CalendarServiceImpl)1 ScheduleAuditLogExecutorImpl (com.enonic.xp.impl.scheduler.ScheduleAuditLogExecutorImpl)1