use of org.ligoj.app.model.TaskSampleSubscription in project ligoj-api by ligoj.
the class LongTaskRunnerTest method newTaskSample.
private TaskSampleSubscription newTaskSample() {
final TaskSampleSubscription taskSample = new TaskSampleSubscription();
taskSample.setAuthor(DEFAULT_USER);
taskSample.setData("custom");
taskSample.setStart(new Date());
taskSample.setEnd(new Date());
taskSample.setLocked(em.find(Subscription.class, subscription));
return taskSample;
}
use of org.ligoj.app.model.TaskSampleSubscription in project ligoj-api by ligoj.
the class LongTaskRunnerTest method startTask.
@Test
public void startTask() {
resource.startTask(subscription, task -> task.setData("init"));
final TaskSampleSubscription task = resource.getTask(subscription);
assertTask(task, "init");
Assertions.assertFalse(task.isFailed());
Assertions.assertNull(task.getEnd());
}
use of org.ligoj.app.model.TaskSampleSubscription in project ligoj-api by ligoj.
the class LongTaskRunnerTest method startTaskNotRunning.
@Test
public void startTaskNotRunning() {
repository.saveAndFlush(newTaskSample());
resource.startTask(subscription, task -> task.setData("init"));
final TaskSampleSubscription task = resource.getTask(subscription);
assertTask(task, "init");
Assertions.assertNull(task.getEnd());
Assertions.assertFalse(task.isFailed());
}
use of org.ligoj.app.model.TaskSampleSubscription in project ligoj-api by ligoj.
the class SubscriptionResourceTest method deleteTasksSubscription.
@Test
public void deleteTasksSubscription() throws Exception {
final TaskSampleSubscriptionResource sampleResource = registerSingleton("taskSampleResource", applicationContext.getAutowireCapableBeanFactory().createBean(TaskSampleSubscriptionResource.class));
try {
final TaskSampleSubscription entity = new TaskSampleSubscription();
entity.setLocked(repository.findOne(subscription));
entity.setStart(new Date());
entity.setAuthor(DEFAULT_USER);
taskSampleRepository.saveAndFlush(entity);
Assertions.assertNotNull(taskSampleRepository.findNotFinishedByLocked(subscription));
entity.setEnd(new Date());
taskSampleRepository.saveAndFlush(entity);
Assertions.assertNull(taskSampleRepository.findNotFinishedByLocked(subscription));
em.flush();
em.clear();
Assertions.assertEquals(1, taskSampleRepository.count());
resource.deleteTasks(sampleResource, subscription);
Assertions.assertNull(taskSampleRepository.findNotFinishedByLocked(subscription));
Assertions.assertEquals(0, taskSampleRepository.count());
} finally {
destroySingleton("taskSampleResource");
}
}
use of org.ligoj.app.model.TaskSampleSubscription in project ligoj-api by ligoj.
the class LongTaskRunnerTest method startTaskRunning.
/**
* There is already a running task on this subscription.
*/
@Test
public void startTaskRunning() {
final TaskSampleSubscription newTaskSample = newTaskSample();
newTaskSample.setEnd(null);
repository.saveAndFlush(newTaskSample);
Assertions.assertThrows(BusinessException.class, () -> {
resource.startTask(subscription, task -> task.setData("init"));
});
}
Aggregations