use of com.synopsys.integration.alert.api.task.TaskMetaData in project hub-alert by blackducksoftware.
the class ProviderTask method createTaskMetaData.
@Override
public TaskMetaData createTaskMetaData() {
String fullyQualifiedName = ScheduledTask.computeFullyQualifiedName(getClass());
String nextRunTime = getFormatedNextRunTime().orElse("");
String providerName = providerKey.getDisplayName();
String configName = providerProperties.getConfigName();
TaskMetaDataProperty providerProperty = new TaskMetaDataProperty("provider", "Provider", providerName);
TaskMetaDataProperty configurationProperty = new TaskMetaDataProperty("configurationName", "Configuration Name", configName);
List<TaskMetaDataProperty> properties = List.of(providerProperty, configurationProperty);
return new TaskMetaData(getTaskName(), getClass().getSimpleName(), fullyQualifiedName, nextRunTime, properties);
}
use of com.synopsys.integration.alert.api.task.TaskMetaData in project hub-alert by blackducksoftware.
the class TaskActionTest method testReadTasks.
@Test
public void testReadTasks() {
Long expectedDelay = 1000L;
TaskScheduler scheduler = Mockito.mock(TaskScheduler.class);
ScheduledFuture scheduledFuture = Mockito.mock(ScheduledFuture.class);
Mockito.when(scheduledFuture.isDone()).thenReturn(Boolean.FALSE);
Mockito.when(scheduledFuture.getDelay(Mockito.eq(TimeUnit.MILLISECONDS))).thenReturn(expectedDelay);
Mockito.when(scheduler.scheduleAtFixedRate(Mockito.any(), Mockito.anyLong())).thenReturn(scheduledFuture);
ScheduledTask task = new ScheduledTask(scheduler) {
@Override
public void runTask() {
}
@Override
public String scheduleCronExpression() {
return ScheduledTask.EVERY_MINUTE_CRON_EXPRESSION;
}
};
TaskManagementDescriptorKey descriptorKey = new TaskManagementDescriptorKey();
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasReadPermission(Mockito.eq(ConfigContextEnum.GLOBAL), Mockito.eq(descriptorKey))).thenReturn(Boolean.TRUE);
TaskManager taskManager = new TaskManager();
taskManager.registerTask(task);
taskManager.scheduleExecutionAtFixedRate(expectedDelay, task.getTaskName());
TaskActions actions = new TaskActions(descriptorKey, authorizationManager, taskManager);
ActionResponse<MultiTaskMetaDataModel> response = actions.getTasks();
assertTrue(response.isSuccessful());
assertTrue(response.hasContent());
MultiTaskMetaDataModel tasksModel = response.getContent().orElse(new MultiTaskMetaDataModel(List.of()));
TaskMetaData model = tasksModel.getTasks().stream().findFirst().orElse(null);
assertNotNull(model);
assertNotNull(task.getTaskName());
assertEquals(task.getFormatedNextRunTime().orElse(""), model.getNextRunTime());
}
Aggregations