Search in sources :

Example 1 with EditableScheduledJob

use of com.enonic.xp.scheduler.EditableScheduledJob 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 EditableScheduledJob

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

the class EditableScheduledJobTest method testChanged.

@Test
public void testChanged() {
    final ScheduledJob source = ScheduledJob.create().name(ScheduledJobName.from("name")).descriptor(DescriptorKey.from("app:key")).calendar(mock(ScheduleCalendar.class)).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 PrincipalKey user = PrincipalKey.ofUser(IdProviderKey.createDefault(), "user");
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.BASE, "descriptor");
    final PropertyTree config = new PropertyTree();
    config.addString("property", "value");
    final String description = "description";
    final EditableScheduledJob editable = new EditableScheduledJob(source);
    editable.config = config;
    editable.user = user;
    editable.descriptor = descriptor;
    editable.description = description;
    editable.calendar = mock(ScheduleCalendar.class);
    editable.enabled = true;
    final ScheduledJob target = editable.build();
    assertEquals(source.getName(), target.getName());
    assertEquals(config, target.getConfig());
    assertEquals(user, target.getUser());
    assertEquals(descriptor, target.getDescriptor());
    assertEquals(description, target.getDescription());
    assertTrue(target.isEnabled());
}
Also used : ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) PropertyTree(com.enonic.xp.data.PropertyTree) 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 3 with EditableScheduledJob

use of com.enonic.xp.scheduler.EditableScheduledJob 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 4 with EditableScheduledJob

use of com.enonic.xp.scheduler.EditableScheduledJob 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)

Aggregations

EditableScheduledJob (com.enonic.xp.scheduler.EditableScheduledJob)4 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)4 ScheduleCalendar (com.enonic.xp.scheduler.ScheduleCalendar)3 Test (org.junit.jupiter.api.Test)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 DescriptorKey (com.enonic.xp.page.DescriptorKey)2 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)2 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)1 ModifyScheduledJobParams (com.enonic.xp.scheduler.ModifyScheduledJobParams)1 Instant (java.time.Instant)1