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