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()));
}
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));
}
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()));
}
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);
}
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);
}
Aggregations