Search in sources :

Example 1 with NamedTask

use of com.enonic.xp.impl.task.script.NamedTask in project xp by enonic.

the class TaskServiceImpl method submitTask.

@Override
public TaskId submitTask(final DescriptorKey key, final PropertyTree config) {
    final NamedTask namedTask = namedTaskFactory.createLegacy(key, config);
    final DescribedTaskImpl task = new DescribedTaskImpl(namedTask, buildContext());
    return submitLocal(task);
}
Also used : NamedTask(com.enonic.xp.impl.task.script.NamedTask)

Example 2 with NamedTask

use of com.enonic.xp.impl.task.script.NamedTask in project xp by enonic.

the class TaskServiceImplTest method submitTask_DescriptorKey.

@Test
void submitTask_DescriptorKey() {
    final DescriptorKey descriptorKey = DescriptorKey.from("module:my-admin-tool");
    final PropertyTree config = new PropertyTree();
    final NamedTask namedTask = mock(NamedTask.class);
    when(namedTaskFactory.createLegacy(descriptorKey, config)).thenReturn(namedTask);
    when(namedTask.getTaskDescriptor()).thenReturn(TaskDescriptor.create().key(descriptorKey).description("task description").build());
    final TaskId taskId = taskService.submitTask(descriptorKey, config);
    verify(taskManager).submitTask(describedTaskCaptor.capture());
    describedTaskCaptor.getValue();
    final DescribedTask argument = describedTaskCaptor.getValue();
    assertEquals(taskId, argument.getTaskId());
}
Also used : TaskId(com.enonic.xp.task.TaskId) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) NamedTask(com.enonic.xp.impl.task.script.NamedTask) DescribedTask(com.enonic.xp.impl.task.distributed.DescribedTask) Test(org.junit.jupiter.api.Test)

Example 3 with NamedTask

use of com.enonic.xp.impl.task.script.NamedTask in project xp by enonic.

the class DistributableTaskTest method run.

@Test
void run() {
    final NamedTask namedTask = mock(NamedTask.class);
    final DescriptorKey descriptorKey = DescriptorKey.from("app:a");
    final TaskDescriptor descriptor = TaskDescriptor.create().key(descriptorKey).description("task description").build();
    final PropertyTree config = new PropertyTree();
    when(namedTaskFactory.create(descriptor, config)).thenReturn(namedTask);
    when(taskDescriptorService.getTask(descriptorKey)).thenReturn(descriptor);
    when(propertyTreeMarshallerService.marshal(eq(config.toMap()), eq(descriptor.getConfig()), Mockito.anyBoolean())).thenReturn(config);
    final DistributableTask describedTask = new DistributableTask(descriptorKey, config, TEST_TASK_CONTEXT);
    describedTask.run(mock(ProgressReporter.class));
    verify(namedTask).run(any(TaskId.class), any(ProgressReporter.class));
}
Also used : TaskDescriptor(com.enonic.xp.task.TaskDescriptor) TaskId(com.enonic.xp.task.TaskId) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) ProgressReporter(com.enonic.xp.task.ProgressReporter) NamedTask(com.enonic.xp.impl.task.script.NamedTask) Test(org.junit.jupiter.api.Test)

Aggregations

NamedTask (com.enonic.xp.impl.task.script.NamedTask)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 DescriptorKey (com.enonic.xp.page.DescriptorKey)2 TaskId (com.enonic.xp.task.TaskId)2 Test (org.junit.jupiter.api.Test)2 DescribedTask (com.enonic.xp.impl.task.distributed.DescribedTask)1 ProgressReporter (com.enonic.xp.task.ProgressReporter)1 TaskDescriptor (com.enonic.xp.task.TaskDescriptor)1