Search in sources :

Example 1 with TaskSampleSubscription

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;
}
Also used : TaskSampleSubscription(org.ligoj.app.model.TaskSampleSubscription) Subscription(org.ligoj.app.model.Subscription) TaskSampleSubscription(org.ligoj.app.model.TaskSampleSubscription) Date(java.util.Date)

Example 2 with TaskSampleSubscription

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());
}
Also used : TaskSampleSubscription(org.ligoj.app.model.TaskSampleSubscription) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest) Test(org.junit.jupiter.api.Test)

Example 3 with TaskSampleSubscription

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());
}
Also used : TaskSampleSubscription(org.ligoj.app.model.TaskSampleSubscription) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest) Test(org.junit.jupiter.api.Test)

Example 4 with TaskSampleSubscription

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");
    }
}
Also used : TaskSampleSubscription(org.ligoj.app.model.TaskSampleSubscription) Date(java.util.Date) Test(org.junit.jupiter.api.Test) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest)

Example 5 with TaskSampleSubscription

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"));
    });
}
Also used : TaskSampleSubscription(org.ligoj.app.model.TaskSampleSubscription) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest) Test(org.junit.jupiter.api.Test)

Aggregations

TaskSampleSubscription (org.ligoj.app.model.TaskSampleSubscription)11 Test (org.junit.jupiter.api.Test)10 AbstractOrgTest (org.ligoj.app.resource.AbstractOrgTest)10 Date (java.util.Date)2 Subscription (org.ligoj.app.model.Subscription)1 TaskSampleSubscriptionResource (org.ligoj.app.resource.subscription.TaskSampleSubscriptionResource)1