Search in sources :

Example 16 with ScheduledJob

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());
}
Also used : SchedulerExecutorService(com.enonic.xp.impl.scheduler.SchedulerExecutorService) BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) SchedulerConstants(com.enonic.xp.scheduler.SchedulerConstants) UpdateLastRunCommand(com.enonic.xp.impl.scheduler.UpdateLastRunCommand) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ContextAccessor(com.enonic.xp.context.ContextAccessor) SchedulerServiceImpl(com.enonic.xp.impl.scheduler.SchedulerServiceImpl) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ContextBuilder(com.enonic.xp.context.ContextBuilder) User(com.enonic.xp.security.User) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TimeZone(java.util.TimeZone) Set(java.util.Set) SchedulerConfig(com.enonic.xp.impl.scheduler.SchedulerConfig) Instant(java.time.Instant) ScheduleAuditLogSupportImpl(com.enonic.xp.impl.scheduler.ScheduleAuditLogSupportImpl) TaskId(com.enonic.xp.task.TaskId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) CronCalendar(com.enonic.xp.scheduler.CronCalendar) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ScheduleCalendar(com.enonic.xp.scheduler.ScheduleCalendar) Mockito.mock(org.mockito.Mockito.mock) Strictness(org.mockito.quality.Strictness) ScheduleAuditLogExecutorImpl(com.enonic.xp.impl.scheduler.ScheduleAuditLogExecutorImpl) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) ModifyScheduledJobParams(com.enonic.xp.scheduler.ModifyScheduledJobParams) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ScheduleCalendarType(com.enonic.xp.scheduler.ScheduleCalendarType) AuditLogService(com.enonic.xp.audit.AuditLogService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CalendarServiceImpl(com.enonic.xp.impl.scheduler.CalendarServiceImpl) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ApplicationKey(com.enonic.xp.app.ApplicationKey) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) PrincipalKey(com.enonic.xp.security.PrincipalKey) DescriptorKey(com.enonic.xp.page.DescriptorKey) NodeAccessException(com.enonic.xp.node.NodeAccessException) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) TaskId(com.enonic.xp.task.TaskId) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) PropertyTree(com.enonic.xp.data.PropertyTree) Instant(java.time.Instant) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 17 with ScheduledJob

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());
}
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 18 with ScheduledJob

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());
}
Also used : Instant(java.time.Instant) PropertyTree(com.enonic.xp.data.PropertyTree) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) DescriptorKey(com.enonic.xp.page.DescriptorKey) ScheduleCalendar(com.enonic.xp.scheduler.ScheduleCalendar) PrincipalKey(com.enonic.xp.security.PrincipalKey) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) Test(org.junit.jupiter.api.Test)

Example 19 with ScheduledJob

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());
}
Also used : ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) ScheduleCalendar(com.enonic.xp.scheduler.ScheduleCalendar) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) Test(org.junit.jupiter.api.Test)

Example 20 with ScheduledJob

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;
}
Also used : ScheduledJob(com.enonic.xp.scheduler.ScheduledJob)

Aggregations

ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)23 PropertyTree (com.enonic.xp.data.PropertyTree)14 Test (org.junit.jupiter.api.Test)13 DescriptorKey (com.enonic.xp.page.DescriptorKey)11 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)10 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)10 PrincipalKey (com.enonic.xp.security.PrincipalKey)9 EditableScheduledJob (com.enonic.xp.scheduler.EditableScheduledJob)7 Instant (java.time.Instant)7 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)6 CronCalendar (com.enonic.xp.scheduler.CronCalendar)6 ModifyScheduledJobParams (com.enonic.xp.scheduler.ModifyScheduledJobParams)6 ScheduleCalendar (com.enonic.xp.scheduler.ScheduleCalendar)6 Context (com.enonic.xp.context.Context)5 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)5 AuditLogService (com.enonic.xp.audit.AuditLogService)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4 OneTimeCalendar (com.enonic.xp.scheduler.OneTimeCalendar)4 IdProviderKey (com.enonic.xp.security.IdProviderKey)4 User (com.enonic.xp.security.User)4