use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class WebModuleUtil method stopTasks.
/**
* Stops all tasks started by given module
* @param mod
*/
private static void stopTasks(Module mod) {
SchedulerService schedulerService = Context.getSchedulerService();
String modulePackageName = mod.getPackageName();
for (TaskDefinition task : schedulerService.getRegisteredTasks()) {
String taskClass = task.getTaskClass();
if (isModulePackageNameInTaskClass(modulePackageName, taskClass)) {
try {
schedulerService.shutdownTask(task);
} catch (SchedulerException e) {
log.error("Couldn't stop task:" + task + " for module: " + mod);
}
}
}
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class SchedulerFormValidatorTest method validate_shouldFailValidationIfClassCannotBeInstantiated.
/**
* @see SchedulerFormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfClassCannotBeInstantiated() {
TaskDefinition def = new TaskDefinition();
def.setName("Chores");
def.setRepeatInterval(3600000L);
def.setTaskClass("org.openmrs.BaseOpenmrsData");
Errors errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("taskClass"));
Assert.assertEquals("Scheduler.taskForm.instantiationException", errors.getFieldError("taskClass").getCode());
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class SchedulerFormValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.
/**
* @see SchedulerFormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
TaskDefinition def = new TaskDefinition();
def.setName("Chores");
def.setRepeatInterval(3600000L);
def.setTaskClass("org.openmrs.scheduler.tasks.HelloWorldTask");
Errors errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class SchedulerFormValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.
/**
* @see SchedulerFormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {
TaskDefinition def = new TaskDefinition();
def.setName(null);
def.setRepeatInterval(3600000L);
def.setTaskClass("org.openmrs.scheduler.tasks.HelloWorldTask");
Errors errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
def.setName("");
errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
def.setName(" ");
errors = new BindException(def, "def");
new SchedulerFormValidator().validate(def, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class SchedulerFormValidatorTest method validate_shouldFailValidationIfClassNotFound.
/**
* @see SchedulerFormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfClassNotFound() {
TaskDefinition def = new TaskDefinition();
def.setName("Chores");
def.setRepeatInterval(3600000L);
def.setTaskClass("org.openmrs.ScaryRobot");
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());
}
Aggregations