use of com.enonic.xp.scheduler.CreateScheduledJobParams 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.CreateScheduledJobParams in project xp by enonic.
the class SchedulerServiceActivatorTest method initWithExistJob.
@Test
void initWithExistJob() {
final CreateScheduledJobParams jobParams = CreateScheduledJobParams.create().name(ScheduledJobName.from("name")).descriptor(DescriptorKey.from("appKey:descriptorName")).calendar(calendarService.cron("* * * * *", TimeZone.getDefault())).config(new PropertyTree()).build();
when(schedulerConfig.jobs()).thenReturn(Set.of(jobParams));
when(nodeService.create(isA(CreateNodeParams.class))).thenThrow(new NodeAlreadyExistAtPathException(NodePath.create(NodePath.ROOT, jobParams.getName().getValue()).build(), RepositoryId.from("repo"), Branch.from("branch")));
activator.activate(bundleContext);
verify(nodeService, times(1)).create(isA(CreateNodeParams.class));
}
use of com.enonic.xp.scheduler.CreateScheduledJobParams in project xp by enonic.
the class SchedulerServiceActivatorTest method initWithInvalidJob.
@Test
void initWithInvalidJob() {
final CreateScheduledJobParams jobParams = CreateScheduledJobParams.create().name(ScheduledJobName.from("name")).descriptor(DescriptorKey.from("appKey:descriptorName")).calendar(calendarService.cron("* * * * *", TimeZone.getDefault())).config(new PropertyTree()).build();
when(schedulerConfig.jobs()).thenReturn(Set.of(jobParams));
when(nodeService.create(isA(CreateNodeParams.class))).thenThrow(new RuntimeException());
assertThrows(RuntimeException.class, () -> activator.activate(bundleContext));
}
use of com.enonic.xp.scheduler.CreateScheduledJobParams in project xp by enonic.
the class SchedulerServiceActivatorTest method initWithAlreadyScheduledRescheduleTask.
@Test
void initWithAlreadyScheduledRescheduleTask() {
final CreateScheduledJobParams jobParams = CreateScheduledJobParams.create().name(ScheduledJobName.from("name")).descriptor(DescriptorKey.from("appKey:descriptorName")).calendar(calendarService.cron("* * * * *", TimeZone.getDefault())).config(new PropertyTree()).build();
mockNode(jobParams);
when(schedulerConfig.jobs()).thenReturn(Set.of(jobParams));
when(schedulerExecutorService.getAllFutures()).thenReturn(Set.of(RescheduleTask.NAME));
final ScheduledFuture<?> scheduledFuture = mock(ScheduledFuture.class);
when(scheduledFuture.isDone()).thenReturn(false);
final Optional<? extends ScheduledFuture<?>> optional = Optional.of(scheduledFuture);
doReturn(optional).when(schedulerExecutorService).get(RescheduleTask.NAME);
activator.activate(bundleContext);
verify(schedulerExecutorService, never()).scheduleAtFixedRate(isA(SchedulableTask.class), anyLong(), anyLong(), isA(TimeUnit.class));
}
use of com.enonic.xp.scheduler.CreateScheduledJobParams in project xp by enonic.
the class SchedulerConfigImplTest method cronJob.
@Test
void cronJob() {
Map<String, String> properties = new HashMap<>();
properties.put("init-job.landing1.enabled", "true");
properties.put("init-job.landing1.description", "landing1 description");
properties.put("init-job.landing1.descriptor", "com.enonic.app.features:landing");
properties.put("init-job.landing1.user", "user:system:user");
properties.put("init-job.landing1.config", "{\"a\":\"valueA\"}");
properties.put("init-job.landing1.cron", "* * * * *");
properties.put("init-job.landing1.timezone", "GMT+5:30");
schedulerConfig = new SchedulerConfigImpl(properties, propertyTreeMarshallerService, calendarService);
final Set<CreateScheduledJobParams> jobs = schedulerConfig.jobs();
assertEquals(2, jobs.size());
final CreateScheduledJobParams job = jobs.stream().filter(params -> params.getName().getValue().equals("landing1")).findAny().orElseThrow(RuntimeException::new);
assertTrue(job.isEnabled());
assertEquals(PrincipalKey.from("user:system:user"), job.getUser());
assertEquals(DescriptorKey.from("com.enonic.app.features:landing"), job.getDescriptor());
assertEquals("landing1 description", job.getDescription());
assertEquals("valueA", job.getConfig().getString("a"));
assertEquals(ScheduleCalendarType.CRON, job.getCalendar().getType());
assertEquals("* * * * *", ((CronCalendar) job.getCalendar()).getCronValue());
assertEquals(TimeZone.getTimeZone("GMT+5:30"), ((CronCalendar) job.getCalendar()).getTimeZone());
}
Aggregations