Search in sources :

Example 1 with VacuumService

use of com.enonic.xp.vacuum.VacuumService 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());
}
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)

Example 2 with VacuumService

use of com.enonic.xp.vacuum.VacuumService 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

ProgressReporter (com.enonic.xp.task.ProgressReporter)2 TaskId (com.enonic.xp.task.TaskId)2 TaskProgressReporterContext (com.enonic.xp.task.TaskProgressReporterContext)2 ScriptTestSupport (com.enonic.xp.testing.ScriptTestSupport)2 VacuumParameters (com.enonic.xp.vacuum.VacuumParameters)2 VacuumResult (com.enonic.xp.vacuum.VacuumResult)2 VacuumService (com.enonic.xp.vacuum.VacuumService)2 Set (java.util.Set)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)2 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 Test (org.junit.jupiter.api.Test)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 ArgumentMatchers.isA (org.mockito.ArgumentMatchers.isA)2 Captor (org.mockito.Captor)2 Mock (org.mockito.Mock)2 Mockito (org.mockito.Mockito)2 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)2