Search in sources :

Example 11 with TaskId

use of com.enonic.xp.task.TaskId in project xp by enonic.

the class ContentResourceTest method reprocess_task_skip_children.

@Test
public void reprocess_task_skip_children() throws Exception {
    Content content = createContent("content-id", ContentPath.from("/path/to/content"));
    Content reprocessedContent = Content.create(content).displayName("new name").build();
    TaskId taskId = TaskId.from("task-id");
    Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    Mockito.when(this.contentService.reprocess(content.getId())).thenReturn(reprocessedContent);
    Mockito.when(this.taskService.submitTask(Mockito.any(RunnableTask.class), Mockito.anyString())).thenReturn(taskId);
    final String result = request().path("content/reprocessTask").entity(readFromFile("reprocess_params_skip_children.json"), MediaType.APPLICATION_JSON_TYPE).post().getAsString();
    assertEquals("{\"taskId\":\"task-id\"}", result);
}
Also used : TaskId(com.enonic.xp.task.TaskId) Content(com.enonic.xp.content.Content) RunnableTask(com.enonic.xp.task.RunnableTask) Test(org.junit.jupiter.api.Test)

Example 12 with TaskId

use of com.enonic.xp.task.TaskId in project xp by enonic.

the class TaskResource method getTask.

@GET
@Path("/{taskId}")
public TaskInfoJson getTask(@PathParam("taskId") final String taskIdString) {
    final TaskId taskId = TaskId.from(taskIdString);
    final TaskInfo taskInfo = taskService.getTaskInfo(taskId);
    if (taskInfo == null) {
        throw new WebApplicationException(String.format("Task [%s] was not found", taskIdString), Response.Status.NOT_FOUND);
    }
    return new TaskInfoJson(taskInfo);
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) TaskInfoJson(com.enonic.xp.task.TaskInfoJson) TaskId(com.enonic.xp.task.TaskId) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with TaskId

use of com.enonic.xp.task.TaskId in project xp by enonic.

the class CleanUpAuditLogCommand method execute.

public TaskResultJson execute() {
    PropertyTree config = new PropertyTree();
    if (params.getAgeThreshold() != null) {
        config.addString("ageThreshold", params.getAgeThreshold());
    }
    final TaskId taskId = taskService.submitTask(SubmitTaskParams.create().descriptorKey(DescriptorKey.from("com.enonic.xp.app.system:audit-log-cleanup")).data(config).build());
    return new TaskResultJson(taskId);
}
Also used : TaskId(com.enonic.xp.task.TaskId) PropertyTree(com.enonic.xp.data.PropertyTree) TaskResultJson(com.enonic.xp.task.TaskResultJson)

Example 14 with TaskId

use of com.enonic.xp.task.TaskId in project xp by enonic.

the class TaskResourceTest method getTask.

@Test
public void getTask() throws Exception {
    final TaskId taskId = TaskId.from("123");
    final TaskInfo taskInfo = TaskInfo.create().id(taskId).description("My task").state(TaskState.RUNNING).application(ApplicationKey.from("com.enonic.myapp")).user(PrincipalKey.from("user:store:me")).startTime(Instant.parse("2017-10-01T09:00:00Z")).progress(TaskProgress.create().current(2).total(10).info("Processing items").build()).build();
    Mockito.when(this.taskService.getTaskInfo(taskId)).thenReturn(taskInfo);
    String response = request().path("task/123").get().getAsString();
    assertJson("get_task_result.json", response);
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) TaskId(com.enonic.xp.task.TaskId) Test(org.junit.jupiter.api.Test)

Example 15 with TaskId

use of com.enonic.xp.task.TaskId in project xp by enonic.

the class VacuumTaskHandlerTest method vacuumDefaultParams.

@Test
public void vacuumDefaultParams() throws Exception {
    final TaskId taskId = TaskId.from("task");
    Mockito.when(vacuumService.vacuum(isA(VacuumParameters.class))).thenReturn(VacuumResult.create().build());
    TaskProgressReporterContext.withContext((id, progressReporter) -> runFunction("/test/VacuumTaskHandlerTest.js", "vacuumDefault")).run(taskId, progressReporter);
    Mockito.verify(vacuumService, Mockito.times(1)).vacuum(paramsCaptor.capture());
    assertNull(paramsCaptor.getValue().getAgeThreshold());
    assertEquals(2, paramsCaptor.getValue().getTaskNames().size());
    assertTrue(paramsCaptor.getValue().getTaskNames().containsAll(Set.of("SegmentVacuumTask", "VersionTableVacuumTask")));
    assertNotNull(paramsCaptor.getValue().getVacuumListener());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) VacuumResult(com.enonic.xp.vacuum.VacuumResult) Mock(org.mockito.Mock) VacuumParameters(com.enonic.xp.vacuum.VacuumParameters) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Set(java.util.Set) TaskProgressReporterContext(com.enonic.xp.task.TaskProgressReporterContext) VacuumService(com.enonic.xp.vacuum.VacuumService) Captor(org.mockito.Captor) TaskId(com.enonic.xp.task.TaskId) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ScriptTestSupport(com.enonic.xp.testing.ScriptTestSupport) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ProgressReporter(com.enonic.xp.task.ProgressReporter) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) TaskId(com.enonic.xp.task.TaskId) VacuumParameters(com.enonic.xp.vacuum.VacuumParameters) Test(org.junit.jupiter.api.Test)

Aggregations

TaskId (com.enonic.xp.task.TaskId)26 Test (org.junit.jupiter.api.Test)19 DescriptorKey (com.enonic.xp.page.DescriptorKey)7 TaskInfo (com.enonic.xp.task.TaskInfo)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 DescribedTask (com.enonic.xp.impl.task.distributed.DescribedTask)5 TasksReporterCallable (com.enonic.xp.impl.task.distributed.TasksReporterCallable)4 TaskManager (com.enonic.xp.impl.task.distributed.TaskManager)3 User (com.enonic.xp.security.User)3 RunnableTask (com.enonic.xp.task.RunnableTask)3 SubmitTaskParams (com.enonic.xp.task.SubmitTaskParams)3 Member (com.hazelcast.core.Member)3 Instant (java.time.Instant)3 Set (java.util.Set)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 Context (com.enonic.xp.context.Context)2