use of com.enonic.xp.task.ProgressReporter in project xp by enonic.
the class ImportListenerImplTest method test.
@Test
void test() {
final ProgressReporter progressReporter = mock(ProgressReporter.class);
final ImportListenerImpl listener = new ImportListenerImpl(progressReporter);
listener.nodeResolved(Integer.MAX_VALUE);
listener.nodeImported(1);
listener.nodeImported(2);
final InOrder inOrder = inOrder(progressReporter);
inOrder.verify(progressReporter).progress(1, Integer.MAX_VALUE);
inOrder.verify(progressReporter).progress(3, Integer.MAX_VALUE);
inOrder.verifyNoMoreInteractions();
}
use of com.enonic.xp.task.ProgressReporter in project xp by enonic.
the class VacuumTaskHandlerTest method vacuum.
@Test
public void vacuum() 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", "vacuum")).run(taskId, progressReporter);
Mockito.verify(vacuumService, Mockito.times(1)).vacuum(paramsCaptor.capture());
assertEquals("PT2S", paramsCaptor.getValue().getAgeThreshold().toString());
assertEquals(2, paramsCaptor.getValue().getTaskNames().size());
assertTrue(paramsCaptor.getValue().getTaskNames().containsAll(Set.of("a", "b")));
assertNotNull(paramsCaptor.getValue().getVacuumListener());
}
use of com.enonic.xp.task.ProgressReporter in project xp by enonic.
the class VacuumTaskHandler method execute.
public void execute() {
final ProgressReporter progressReporter = TaskProgressReporterContext.current();
final VacuumResult result = vacuumService.vacuum(VacuumParameters.create().ageThreshold(ageThreshold != null ? Duration.parse(ageThreshold) : null).taskNames(tasks == null || tasks.isEmpty() ? DEFAULT_VACUUM_TASKS : tasks).vacuumListener(new VacuumListenerImpl(progressReporter)).build());
try {
progressReporter.info(MAPPER.writeValueAsString(MAPPER.createObjectNode().putPOJO("taskResults", result.getResults())));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
use of com.enonic.xp.task.ProgressReporter 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());
}
use of com.enonic.xp.task.ProgressReporter in project xp by enonic.
the class ExportListenerImplTest method test.
@Test
void test() {
final ProgressReporter progressReporter = mock(ProgressReporter.class);
final ExportListenerImpl listener = new ExportListenerImpl(progressReporter);
listener.nodeResolved(Integer.MAX_VALUE);
listener.nodeExported(1);
listener.nodeExported(2);
final InOrder inOrder = inOrder(progressReporter);
inOrder.verify(progressReporter).progress(1, Integer.MAX_VALUE);
inOrder.verify(progressReporter).progress(3, Integer.MAX_VALUE);
inOrder.verifyNoMoreInteractions();
}
Aggregations