use of com.enonic.xp.scheduler.ScheduledJob in project xp by enonic.
the class SchedulerServiceImplTest method modifyClearLastRun.
@Test
void modifyClearLastRun() throws Exception {
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 TaskId lastTaskId = TaskId.from("task-id");
final Instant lastRun = Instant.parse("2021-02-25T10:44:33.170079900Z");
adminContext().runWith(() -> UpdateLastRunCommand.create().name(name).lastTaskId(lastTaskId).lastRun(lastRun).nodeService(nodeService).build().execute());
final ScheduledJob runJob = adminContext().callWith(() -> schedulerService.get(name));
assertEquals(lastRun, runJob.getLastRun());
assertEquals(lastTaskId, runJob.getLastTaskId());
final ScheduledJob modifiedJob = adminContext().callWith(() -> schedulerService.modify(ModifyScheduledJobParams.create().name(name).editor(edit -> {
edit.enabled = true;
}).build()));
assertNull(modifiedJob.getLastRun());
assertNull(modifiedJob.getLastTaskId());
}
use of com.enonic.xp.scheduler.ScheduledJob 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());
}
use of com.enonic.xp.scheduler.ScheduledJob in project xp by enonic.
the class EditableScheduledJobTest method testNotChanged.
@Test
public void testNotChanged() {
final PrincipalKey user = PrincipalKey.ofUser(IdProviderKey.createDefault(), "user");
final PrincipalKey creator = PrincipalKey.ofUser(IdProviderKey.createDefault(), "creator");
final PrincipalKey modifier = PrincipalKey.ofUser(IdProviderKey.createDefault(), "modifier");
final Instant createdTime = Instant.parse("2021-02-25T10:44:33.170079900Z");
final Instant modifiedTime = Instant.parse("2021-03-25T10:44:33.170079900Z");
final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.BASE, "descriptor");
final PropertyTree config = new PropertyTree();
config.addString("property", "value");
final String description = "description";
final ScheduledJob source = ScheduledJob.create().name(ScheduledJobName.from("name")).config(config).user(user).descriptor(descriptor).description(description).calendar(mock(ScheduleCalendar.class)).enabled(true).creator(creator).modifier(modifier).createdTime(createdTime).modifiedTime(modifiedTime).build();
final ScheduledJob target = new EditableScheduledJob(source).build();
assertEquals(source.getName(), target.getName());
assertEquals(source.getConfig(), target.getConfig());
assertEquals(source.getUser(), target.getUser());
assertEquals(source.getDescriptor(), target.getDescriptor());
assertEquals(source.getDescription(), target.getDescription());
assertEquals(source.isEnabled(), target.isEnabled());
assertEquals(source.getCreator(), target.getCreator());
assertEquals(source.getCreatedTime(), target.getCreatedTime());
}
use of com.enonic.xp.scheduler.ScheduledJob in project xp by enonic.
the class EditableScheduledJobTest method testEmpty.
@Test
public void testEmpty() {
final ScheduledJobName name = ScheduledJobName.from("scheduledJobName");
final ScheduledJob source = ScheduledJob.create().name(name).calendar(mock(ScheduleCalendar.class)).descriptor(DescriptorKey.from("app:key")).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();
final ScheduledJob target = new EditableScheduledJob(source).build();
assertEquals(name, target.getName());
assertEquals(0, target.getConfig().getTotalSize());
assertNull(target.getUser());
assertNull(target.getDescription());
assertNotNull(target.getDescriptor());
assertNotNull(target.getCalendar());
assertNotNull(target.getConfig());
assertFalse(source.isEnabled());
}
use of com.enonic.xp.scheduler.ScheduledJob in project xp by enonic.
the class SchedulerServiceImpl method modify.
@Override
public ScheduledJob modify(final ModifyScheduledJobParams params) {
UnscheduleJobCommand.create().schedulerExecutorService(schedulerExecutorService).name(params.getName()).build().execute();
final ScheduledJob job = ModifyScheduledJobCommand.create().nodeService(nodeService).params(params).build().execute();
auditLogSupport.modify(params, job);
return job;
}
Aggregations