Search in sources :

Example 1 with ScheduledJobName

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

the class BaseScheduledJobHandlerTest method mockJob.

private void mockJob() {
    jobs = new HashMap<>();
    Mockito.when(schedulerService.create(Mockito.isA(CreateScheduledJobParams.class))).thenAnswer(invocation -> {
        final CreateScheduledJobParams params = invocation.getArgument(0);
        final ScheduledJob job = ScheduledJob.create().name(params.getName()).descriptor(params.getDescriptor()).description(params.getDescription()).calendar(params.getCalendar()).config(params.getConfig()).enabled(params.isEnabled()).user(params.getUser()).creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:creator")).createdTime(Instant.parse("2016-11-02T10:36:00Z")).modifiedTime(Instant.parse("2016-11-02T10:36:00Z")).build();
        jobs.put(job.getName(), job);
        return job;
    });
    Mockito.when(schedulerService.modify(Mockito.isA(ModifyScheduledJobParams.class))).thenAnswer(invocation -> {
        final ModifyScheduledJobParams params = invocation.getArgument(0);
        final EditableScheduledJob editableJob = new EditableScheduledJob(jobs.get(params.getName()));
        params.getEditor().edit(editableJob);
        ScheduledJob modifiedJob = editableJob.build();
        modifiedJob = ScheduledJob.create().name(modifiedJob.getName()).description(modifiedJob.getDescription()).calendar(modifiedJob.getCalendar()).enabled(modifiedJob.isEnabled()).descriptor(modifiedJob.getDescriptor()).config(modifiedJob.getConfig()).user(modifiedJob.getUser()).creator(modifiedJob.getCreator()).createdTime(modifiedJob.getCreatedTime()).modifiedTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).modifier(PrincipalKey.from("user:system:modifier")).build();
        jobs.put(params.getName(), modifiedJob);
        return modifiedJob;
    });
    Mockito.when(schedulerService.delete(Mockito.isA(ScheduledJobName.class))).thenAnswer(invocation -> {
        final ScheduledJobName name = invocation.getArgument(0);
        final ScheduledJob job = jobs.remove(name);
        return job != null;
    });
    Mockito.when(schedulerService.get(Mockito.isA(ScheduledJobName.class))).thenAnswer(invocation -> jobs.get(invocation.getArgument(0)));
    Mockito.when(schedulerService.list()).thenAnswer(invocation -> new ArrayList<>(jobs.values()));
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) ModifyScheduledJobParams(com.enonic.xp.scheduler.ModifyScheduledJobParams) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob)

Example 2 with ScheduledJobName

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

the class SchedulerServiceImplTest method getNotCreated.

@Test
void getNotCreated() {
    final ScheduledJobName name = ScheduledJobName.from("test");
    assertNull(schedulerService.get(name));
}
Also used : ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 3 with ScheduledJobName

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

the class SchedulerServiceImplTest method createOneTimeJob.

@Test
void createOneTimeJob() throws Exception {
    final ScheduledJobName name = ScheduledJobName.from("test");
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing");
    final ScheduleCalendar calendar = calendarService.oneTime(Instant.parse("2021-02-25T10:44:33.170079900Z"));
    final PropertyTree config = new PropertyTree();
    config.addString("string", "value");
    final PrincipalKey user = PrincipalKey.from("user:system:user");
    final CreateScheduledJobParams params = CreateScheduledJobParams.create().name(name).descriptor(descriptor).calendar(calendar).config(config).description("description").enabled(true).user(user).build();
    final Instant now = Instant.now();
    Thread.sleep(100);
    final ScheduledJob scheduledJob = adminContext().callWith(() -> schedulerService.create(params));
    assertEquals("2021-02-25T10:44:33.170079900Z", ((OneTimeCalendar) scheduledJob.getCalendar()).getValue().toString());
    assertEquals(ScheduleCalendarType.ONE_TIME, scheduledJob.getCalendar().getType());
    assertEquals("user:system:repo-test-user", scheduledJob.getCreator().toString());
    assertEquals("user:system:repo-test-user", scheduledJob.getModifier().toString());
    assertTrue(now.isBefore(scheduledJob.getModifiedTime()));
    assertTrue(now.isBefore(scheduledJob.getCreatedTime()));
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) PropertyTree(com.enonic.xp.data.PropertyTree) Instant(java.time.Instant) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) DescriptorKey(com.enonic.xp.page.DescriptorKey) ScheduleCalendar(com.enonic.xp.scheduler.ScheduleCalendar) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 4 with ScheduledJobName

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

the class SchedulerServiceImplTest method deleteNotCreated.

@Test
void deleteNotCreated() {
    final ScheduledJobName name = ScheduledJobName.from("test");
    final boolean deleted = schedulerService.delete(name);
    assertFalse(deleted);
}
Also used : ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 5 with ScheduledJobName

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

the class SchedulerServiceImplTest method delete.

@Test
void delete() {
    final ScheduledJobName name = ScheduledJobName.from("test");
    adminContext().callWith(() -> schedulerService.create(CreateScheduledJobParams.create().name(name).descriptor(DescriptorKey.from(ApplicationKey.from("com.enonic.app.test"), "task1")).calendar(calendarService.cron("* * * * *", TimeZone.getTimeZone("GMT+5:30"))).config(new PropertyTree()).build()));
    final boolean deleted = adminContext().callWith(() -> schedulerService.delete(name));
    assertTrue(deleted);
}
Also used : 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)

Aggregations

ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)20 Test (org.junit.jupiter.api.Test)18 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)17 PropertyTree (com.enonic.xp.data.PropertyTree)15 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)11 CronCalendar (com.enonic.xp.scheduler.CronCalendar)10 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)10 DescriptorKey (com.enonic.xp.page.DescriptorKey)9 ScheduleCalendar (com.enonic.xp.scheduler.ScheduleCalendar)7 PrincipalKey (com.enonic.xp.security.PrincipalKey)7 Instant (java.time.Instant)6 Context (com.enonic.xp.context.Context)5 ModifyScheduledJobParams (com.enonic.xp.scheduler.ModifyScheduledJobParams)5 OneTimeCalendar (com.enonic.xp.scheduler.OneTimeCalendar)5 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)5 Set (java.util.Set)5 TimeZone (java.util.TimeZone)5 ApplicationKey (com.enonic.xp.app.ApplicationKey)4 AuditLogService (com.enonic.xp.audit.AuditLogService)4 ContextAccessor (com.enonic.xp.context.ContextAccessor)4