Search in sources :

Example 26 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class NamedTaskFactoryImplTest method createExisting.

@Test
void createExisting() {
    final DescriptorKey descriptorKey = DescriptorKey.from("myapplication:mytask");
    final TaskDescriptor descriptor = TaskDescriptor.create().key(descriptorKey).build();
    when(taskDescriptorService.getTask(descriptorKey)).thenReturn(descriptor);
    final RunnableTask runnableTask = namedTaskScriptFactory.create(descriptor, new PropertyTree());
    assertNotNull(runnableTask);
    runnableTask.run(TaskId.from("123"), null);
}
Also used : TaskDescriptor(com.enonic.xp.task.TaskDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) RunnableTask(com.enonic.xp.task.RunnableTask) Test(org.junit.jupiter.api.Test)

Example 27 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class DistributableTaskTest method fields.

@Test
void fields() {
    final DescriptorKey descriptorKey = DescriptorKey.from("app:a");
    final TaskDescriptor descriptor = TaskDescriptor.create().key(descriptorKey).description("task description").config(Form.create().build()).build();
    final PropertyTree config = new PropertyTree();
    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);
    assertAll(() -> assertEquals("app:a", describedTask.getName()), () -> assertNotNull(describedTask.getTaskId()), () -> assertNotNull(describedTask.getTaskContext()), () -> assertEquals("task description", describedTask.getDescription()), () -> assertEquals(descriptorKey.getApplicationKey(), describedTask.getApplicationKey()));
}
Also used : TaskDescriptor(com.enonic.xp.task.TaskDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) Test(org.junit.jupiter.api.Test)

Example 28 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class TaskDescriptorServiceImplTest method getTask.

@Test
void getTask() {
    final DescriptorKey key = DescriptorKey.from("app:a");
    final TaskDescriptor desc = TaskDescriptor.create().key(key).build();
    when(this.descriptorService.get(TaskDescriptor.class, key)).thenReturn(desc);
    final TaskDescriptor result = this.service.getTask(key);
    assertNotNull(result);
}
Also used : TaskDescriptor(com.enonic.xp.task.TaskDescriptor) DescriptorKey(com.enonic.xp.page.DescriptorKey) Test(org.junit.jupiter.api.Test)

Example 29 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class TaskServiceImplTest method submitTask_DescriptorKey_offload_to_clustered.

@Test
void submitTask_DescriptorKey_offload_to_clustered() {
    final DescriptorKey descriptorKey = DescriptorKey.from("module:my-admin-tool");
    final TaskManager clusteredTaskManager = mock(TaskManager.class);
    taskService.setClusteredTaskManager(clusteredTaskManager);
    final TaskId taskId = taskService.submitTask(SubmitTaskParams.create().descriptorKey(descriptorKey).build());
    verify(clusteredTaskManager).submitTask(describedTaskCaptor.capture());
    describedTaskCaptor.getValue();
    final DescribedTask argument = describedTaskCaptor.getValue();
    assertEquals(taskId, argument.getTaskId());
}
Also used : TaskManager(com.enonic.xp.impl.task.distributed.TaskManager) TaskId(com.enonic.xp.task.TaskId) DescriptorKey(com.enonic.xp.page.DescriptorKey) DescribedTask(com.enonic.xp.impl.task.distributed.DescribedTask) Test(org.junit.jupiter.api.Test)

Example 30 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey 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)

Aggregations

DescriptorKey (com.enonic.xp.page.DescriptorKey)73 Test (org.junit.jupiter.api.Test)45 PropertyTree (com.enonic.xp.data.PropertyTree)25 PrincipalKey (com.enonic.xp.security.PrincipalKey)11 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)10 TaskId (com.enonic.xp.task.TaskId)10 Page (com.enonic.xp.page.Page)7 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)7 TaskDescriptor (com.enonic.xp.task.TaskDescriptor)7 Instant (java.time.Instant)7 PropertySet (com.enonic.xp.data.PropertySet)6 ServiceDescriptor (com.enonic.xp.service.ServiceDescriptor)6 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)5 CronCalendar (com.enonic.xp.scheduler.CronCalendar)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ApplicationKey (com.enonic.xp.app.ApplicationKey)4 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)4 DescribedTask (com.enonic.xp.impl.task.distributed.DescribedTask)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 PortalResponse (com.enonic.xp.portal.PortalResponse)4