use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class SchedulerFormValidatorTest method validate_shouldFailValidationIfRepeatIntervalIsNullOrEmptyOrWhitespace.
/**
* @see SchedulerFormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfRepeatIntervalIsNullOrEmptyOrWhitespace() {
TaskDefinition def = new TaskDefinition();
def.setName("Chores");
def.setTaskClass("org.openmrs.scheduler.tasks.HelloWorldTask");
Errors errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("repeatInterval"));
def.setTaskClass(" ");
errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("repeatInterval"));
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class SchedulerFormValidatorTest method validate_shouldFailValidationIfClassIsNotInstanceOfTask.
/**
* @see SchedulerFormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfClassIsNotInstanceOfTask() {
TaskDefinition def = new TaskDefinition();
def.setName("Chores");
def.setRepeatInterval(3600000L);
def.setTaskClass("org.openmrs.Obs");
Errors errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("taskClass"));
Assert.assertEquals("Scheduler.taskForm.classDoesNotImplementTask", errors.getFieldError("taskClass").getCode());
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class SchedulerFormValidatorTest method validate_shouldFailValidationIfClassIsNotAccessible.
/**
* @see SchedulerFormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfClassIsNotAccessible() {
TaskDefinition def = new TaskDefinition();
def.setName("Chores");
def.setRepeatInterval(3600000L);
// TODO: Find a way to trigger an IllegalAccessException
def.setTaskClass("???");
Errors errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("taskClass"));
Assert.assertEquals("Scheduler.taskForm.classNotFoundException", errors.getFieldError("taskClass").getCode());
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class SchedulerFormValidatorTest method validate_shouldFailValidationIfTaskClassIsEmptyOrWhitespace.
/**
* @see SchedulerFormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfTaskClassIsEmptyOrWhitespace() {
TaskDefinition def = new TaskDefinition();
def.setName("Chores");
def.setRepeatInterval(3600000L);
def.setTaskClass("");
Errors errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("taskClass"));
def.setTaskClass(" ");
errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("taskClass"));
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class TimerSchedulerServiceImplTest method scheduleTask_shouldHandleZeroRepeatInterval.
/**
* Tests whether the TimerScheduler schedules tasks even if the repeatInterval is zero.
*
* @throws SchedulerException
* @see TimerSchedulerServiceImpl#scheduleTask(TaskDefinition)
*/
@Test
public void scheduleTask_shouldHandleZeroRepeatInterval() throws SchedulerException {
// Represents the start time of the task (right now)
Calendar startTime = Calendar.getInstance();
// Define repeatInterval as zero
Long repeatInterval = 0L;
String taskName = "TestTask";
String className = "org.openmrs.scheduler.tasks.TestTask";
Boolean startOnStartup = false;
// Create the new task
TaskDefinition taskDefinition = new TaskDefinition();
taskDefinition.setName(taskName);
taskDefinition.setTaskClass(className);
taskDefinition.setStartTime(startTime.getTime());
taskDefinition.setRepeatInterval(repeatInterval);
taskDefinition.setStartOnStartup(startOnStartup);
Task clientTask = null;
clientTask = Context.getSchedulerService().scheduleTask(taskDefinition);
// without this commit there seems to be a table lock left on the SCHEDULER_TASK_CONFIG table, see TRUNK-4212
Context.flushSession();
// Assert that the clientTask is not null, i.e. the sheduleTask was able to successfully schedule in case of zero repeatInterval.
assertNotNull("The clientTask variable is null, so either the TimerSchedulerServiceImpl.scheduleTask method hasn't finished or didn't get run", clientTask);
}
Aggregations