Search in sources :

Example 11 with CronCalendar

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

the class SchedulerServiceImplTest method createWithoutAccess.

@Test
void createWithoutAccess() {
    final ScheduledJobName name = ScheduledJobName.from("test");
    final CronCalendar calendar = calendarService.cron("* * * * *", TimeZone.getDefault());
    final CreateScheduledJobParams params = CreateScheduledJobParams.create().name(name).calendar(calendar).descriptor(DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing")).config(new PropertyTree()).build();
    assertThrows(NodeAccessException.class, () -> schedulerService.create(params));
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) CronCalendar(com.enonic.xp.scheduler.CronCalendar) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 12 with CronCalendar

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

the class SchedulerServiceImplTest method createWithoutUser.

@Test
void createWithoutUser() {
    final ScheduledJobName name = ScheduledJobName.from("test");
    final CronCalendar calendar = calendarService.cron("* * * * *", TimeZone.getDefault());
    final CreateScheduledJobParams params = CreateScheduledJobParams.create().name(name).calendar(calendar).descriptor(DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing")).config(new PropertyTree()).build();
    Context context = ContextAccessor.current();
    final AuthenticationInfo authenticationInfo = AuthenticationInfo.copyOf(AuthenticationInfo.unAuthenticated()).user(null).principals(context.getAuthInfo().getPrincipals()).principals(RoleKeys.ADMIN).build();
    context = ContextBuilder.from(context).authInfo(authenticationInfo).build();
    final ScheduledJob scheduledJob = context.callWith(() -> schedulerService.create(params));
    assertEquals(User.ANONYMOUS.getKey(), scheduledJob.getCreator());
    assertEquals(User.ANONYMOUS.getKey(), scheduledJob.getModifier());
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) Context(com.enonic.xp.context.Context) CronCalendar(com.enonic.xp.scheduler.CronCalendar) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) PropertyTree(com.enonic.xp.data.PropertyTree) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 13 with CronCalendar

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

the class CalendarServiceImplTest method cron.

@Test
public void cron() {
    final CronCalendar calendar = calendarService.cron("* * * * *", TimeZone.getTimeZone("GMT+5:30"));
    assertTrue(calendar.nextExecution().get().get(ChronoUnit.SECONDS) <= 60);
    assertEquals(TimeZone.getTimeZone("GMT+5:30"), calendar.getTimeZone());
    assertEquals("* * * * *", calendar.getCronValue());
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) Test(org.junit.jupiter.api.Test)

Example 14 with CronCalendar

use of com.enonic.xp.scheduler.CronCalendar 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)

Aggregations

CronCalendar (com.enonic.xp.scheduler.CronCalendar)14 PropertyTree (com.enonic.xp.data.PropertyTree)9 Test (org.junit.jupiter.api.Test)9 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)7 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)6 DescriptorKey (com.enonic.xp.page.DescriptorKey)5 PropertySet (com.enonic.xp.data.PropertySet)4 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)4 OneTimeCalendar (com.enonic.xp.scheduler.OneTimeCalendar)4 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)4 Context (com.enonic.xp.context.Context)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 Node (com.enonic.xp.node.Node)1 PrincipalKey (com.enonic.xp.security.PrincipalKey)1 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 TimeZone (java.util.TimeZone)1