Search in sources :

Example 1 with TaskManager

use of com.synopsys.integration.alert.api.task.TaskManager in project hub-alert by blackducksoftware.

the class TaskManagerTest method testGetDifferenceToNextRunTime.

@Test
public void testGetDifferenceToNextRunTime() {
    ScheduledTask task = Mockito.mock(ScheduledTask.class);
    final String taskName = "a_task";
    Mockito.when(task.getTaskName()).thenReturn(taskName);
    Mockito.when(task.getMillisecondsToNextRun()).thenReturn(Optional.of(999L));
    TaskManager taskManager = new TaskManager();
    taskManager.registerTask(task);
    taskManager.getDifferenceToNextRun(taskName, TimeUnit.SECONDS);
    Mockito.verify(task).getMillisecondsToNextRun();
}
Also used : TaskManager(com.synopsys.integration.alert.api.task.TaskManager) ScheduledTask(com.synopsys.integration.alert.api.task.ScheduledTask) Test(org.junit.jupiter.api.Test)

Example 2 with TaskManager

use of com.synopsys.integration.alert.api.task.TaskManager in project hub-alert by blackducksoftware.

the class TaskManagerTest method testGetNextRunTimeForUnknownTask.

@Test
public void testGetNextRunTimeForUnknownTask() {
    ScheduledTask task = Mockito.mock(ScheduledTask.class);
    final String taskName = "a_task";
    Mockito.when(task.getTaskName()).thenReturn(taskName);
    TaskManager taskManager = new TaskManager();
    taskManager.registerTask(task);
    taskManager.getNextRunTime("unknown_task");
    Mockito.verify(task, Mockito.times(0)).getFormatedNextRunTime();
    taskManager.getNextRunTime(null);
    Mockito.verify(task, Mockito.times(0)).getFormatedNextRunTime();
}
Also used : TaskManager(com.synopsys.integration.alert.api.task.TaskManager) ScheduledTask(com.synopsys.integration.alert.api.task.ScheduledTask) Test(org.junit.jupiter.api.Test)

Example 3 with TaskManager

use of com.synopsys.integration.alert.api.task.TaskManager in project hub-alert by blackducksoftware.

the class TaskManagerTest method testUnschedule.

@Test
public void testUnschedule() {
    ScheduledTask task = Mockito.mock(ScheduledTask.class);
    final String taskName = "a_task";
    final String cronExpression = "cron_expression";
    Mockito.when(task.getTaskName()).thenReturn(taskName);
    TaskManager taskManager = new TaskManager();
    taskManager.registerTask(task);
    taskManager.scheduleCronTask(cronExpression, taskName);
    Mockito.verify(task).scheduleExecution(Mockito.anyString());
    assertFalse(taskManager.unScheduleTask("unknown_task"));
    assertTrue(taskManager.unScheduleTask(taskName));
}
Also used : TaskManager(com.synopsys.integration.alert.api.task.TaskManager) ScheduledTask(com.synopsys.integration.alert.api.task.ScheduledTask) Test(org.junit.jupiter.api.Test)

Example 4 with TaskManager

use of com.synopsys.integration.alert.api.task.TaskManager in project hub-alert by blackducksoftware.

the class TaskManagerTest method testGetDifferenceToNextRunTimeForUnknownTask.

@Test
public void testGetDifferenceToNextRunTimeForUnknownTask() {
    ScheduledTask task = Mockito.mock(ScheduledTask.class);
    final String taskName = "a_task";
    Mockito.when(task.getTaskName()).thenReturn(taskName);
    Mockito.when(task.getMillisecondsToNextRun()).thenReturn(Optional.of(999L));
    TaskManager taskManager = new TaskManager();
    taskManager.registerTask(task);
    taskManager.getDifferenceToNextRun("unknown_task", TimeUnit.SECONDS);
    Mockito.verify(task, Mockito.times(0)).getMillisecondsToNextRun();
    taskManager.getDifferenceToNextRun(null, TimeUnit.SECONDS);
    Mockito.verify(task, Mockito.times(0)).getMillisecondsToNextRun();
}
Also used : TaskManager(com.synopsys.integration.alert.api.task.TaskManager) ScheduledTask(com.synopsys.integration.alert.api.task.ScheduledTask) Test(org.junit.jupiter.api.Test)

Example 5 with TaskManager

use of com.synopsys.integration.alert.api.task.TaskManager in project hub-alert by blackducksoftware.

the class TaskManagerTest method testScheduleCron.

@Test
public void testScheduleCron() {
    ScheduledTask task = Mockito.mock(ScheduledTask.class);
    final String taskName = "a_task";
    final String cronExpression = "cron_expression";
    Mockito.when(task.getTaskName()).thenReturn(taskName);
    TaskManager taskManager = new TaskManager();
    taskManager.registerTask(task);
    taskManager.scheduleCronTask(cronExpression, taskName);
    Mockito.verify(task).scheduleExecution(Mockito.anyString());
}
Also used : TaskManager(com.synopsys.integration.alert.api.task.TaskManager) ScheduledTask(com.synopsys.integration.alert.api.task.ScheduledTask) Test(org.junit.jupiter.api.Test)

Aggregations

TaskManager (com.synopsys.integration.alert.api.task.TaskManager)18 Test (org.junit.jupiter.api.Test)17 ScheduledTask (com.synopsys.integration.alert.api.task.ScheduledTask)11 TaskScheduler (org.springframework.scheduling.TaskScheduler)6 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)5 StaticJobAccessor (com.synopsys.integration.alert.database.api.StaticJobAccessor)5 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)5 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)5 DateRange (com.synopsys.integration.alert.common.message.model.DateRange)4 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)2 TaskManagementDescriptorKey (com.synopsys.integration.alert.component.tasks.TaskManagementDescriptorKey)2 ArrayList (java.util.ArrayList)2 ProviderSchedulingManager (com.synopsys.integration.alert.api.provider.lifecycle.ProviderSchedulingManager)1 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)1 TaskMetaData (com.synopsys.integration.alert.api.task.TaskMetaData)1 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)1 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)1 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)1