Search in sources :

Example 66 with DescriptorKey

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

the class EditableScheduledJobTest method testNotChanged.

@Test
public void testNotChanged() {
    final PrincipalKey user = PrincipalKey.ofUser(IdProviderKey.createDefault(), "user");
    final PrincipalKey creator = PrincipalKey.ofUser(IdProviderKey.createDefault(), "creator");
    final PrincipalKey modifier = PrincipalKey.ofUser(IdProviderKey.createDefault(), "modifier");
    final Instant createdTime = Instant.parse("2021-02-25T10:44:33.170079900Z");
    final Instant modifiedTime = Instant.parse("2021-03-25T10:44:33.170079900Z");
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.BASE, "descriptor");
    final PropertyTree config = new PropertyTree();
    config.addString("property", "value");
    final String description = "description";
    final ScheduledJob source = ScheduledJob.create().name(ScheduledJobName.from("name")).config(config).user(user).descriptor(descriptor).description(description).calendar(mock(ScheduleCalendar.class)).enabled(true).creator(creator).modifier(modifier).createdTime(createdTime).modifiedTime(modifiedTime).build();
    final ScheduledJob target = new EditableScheduledJob(source).build();
    assertEquals(source.getName(), target.getName());
    assertEquals(source.getConfig(), target.getConfig());
    assertEquals(source.getUser(), target.getUser());
    assertEquals(source.getDescriptor(), target.getDescriptor());
    assertEquals(source.getDescription(), target.getDescription());
    assertEquals(source.isEnabled(), target.isEnabled());
    assertEquals(source.getCreator(), target.getCreator());
    assertEquals(source.getCreatedTime(), target.getCreatedTime());
}
Also used : Instant(java.time.Instant) PropertyTree(com.enonic.xp.data.PropertyTree) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) DescriptorKey(com.enonic.xp.page.DescriptorKey) ScheduleCalendar(com.enonic.xp.scheduler.ScheduleCalendar) PrincipalKey(com.enonic.xp.security.PrincipalKey) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob) Test(org.junit.jupiter.api.Test)

Example 67 with DescriptorKey

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

the class TaskServiceImplTest method submitTask_DescriptorKey_offload_to_clustered_wait_success.

@Test
void submitTask_DescriptorKey_offload_to_clustered_wait_success() {
    final DescriptorKey descriptorKey = DescriptorKey.from("module:my-admin-tool");
    final TaskManager clusteredTaskManager = mock(TaskManager.class);
    when(taskConfig.distributable_acceptInbound()).thenReturn(false);
    taskService.activate(taskConfig);
    CompletableFuture.runAsync(() -> taskService.setClusteredTaskManager(clusteredTaskManager), CompletableFuture.delayedExecutor(1, TimeUnit.SECONDS));
    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 68 with DescriptorKey

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

the class TaskDescriptorLoaderTest method testLoad.

@Test
public void testLoad() {
    final DescriptorKey descriptorKey = DescriptorKey.from("myapp1:task1");
    final ResourceKey resourceKey = this.loader.toResource(descriptorKey);
    assertEquals("myapp1:/tasks/task1/task1.xml", resourceKey.toString());
    final Resource resource = this.resourceService.getResource(resourceKey);
    final TaskDescriptor descriptor = this.loader.load(descriptorKey, resource);
    assertEquals("MyTask", descriptor.getDescription());
    FormItem formItem = descriptor.getConfig().getFormItem("param1");
    assertEquals(" something ", formItem.toInput().getDefaultValue().getRootValue());
}
Also used : TaskDescriptor(com.enonic.xp.task.TaskDescriptor) FormItem(com.enonic.xp.form.FormItem) Resource(com.enonic.xp.resource.Resource) DescriptorKey(com.enonic.xp.page.DescriptorKey) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 69 with DescriptorKey

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

the class TaskServiceImplTest method submitTask_DescriptorKey_offload_to_local.

@Test
void submitTask_DescriptorKey_offload_to_local() {
    final DescriptorKey descriptorKey = DescriptorKey.from("module:my-admin-tool");
    final TaskId taskId = taskService.submitTask(SubmitTaskParams.create().descriptorKey(descriptorKey).build());
    verify(taskManager).submitTask(describedTaskCaptor.capture());
    describedTaskCaptor.getValue();
    final DescribedTask argument = describedTaskCaptor.getValue();
    assertEquals(taskId, argument.getTaskId());
}
Also used : 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 70 with DescriptorKey

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

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