1 package net.avcompris.examples.users3.core.tests;
2
3 import static net.avcompris.commons3.core.tests.CoreTestUtils.grantAll;
4 import static net.avcompris.examples.shared3.core.tests.MyCoreTestUtils.defaultUser;
5 import static org.junit.jupiter.api.Assertions.assertEquals;
6 import static org.junit.jupiter.api.Assertions.assertNotEquals;
7
8 import org.junit.jupiter.api.BeforeEach;
9 import org.junit.jupiter.api.Test;
10
11 import net.avcompris.commons3.core.CorrelationService;
12 import net.avcompris.commons3.core.tests.AbstractServiceTest;
13 import net.avcompris.commons3.dao.CorrelationDao;
14 import net.avcompris.commons3.utils.Clock;
15 import net.avcompris.commons3.utils.LogFactory;
16 import net.avcompris.examples.shared3.core.impl.CorrelationServiceImpl;
17
18 public abstract class AbstractCorrelationServicePurgeTest extends AbstractServiceTest<CorrelationDao> {
19
20 protected CorrelationService correlationService;
21 protected Clock dummyClock;
22
23 @BeforeEach
24 public final void setUpBeans() throws Exception {
25
26 dummyClock = new DummyClock(60);
27
28 final CorrelationDao correlationDao = getBeans(dummyClock);
29
30 correlationService = new CorrelationServiceImpl(grantAll(), dummyClock, correlationDao);
31
32 LogFactory.resetCorrelationId();
33 }
34
35 @Test
36 public final void test_purge() throws Exception {
37
38 final String correlationId = correlationService.getCorrelationId(null, null);
39
40 assertEquals(correlationId, correlationService.getCorrelationId(correlationId, null));
41 assertEquals(correlationId, correlationService.getCorrelationId(null, correlationId));
42 assertEquals(correlationId, correlationService.getCorrelationId(correlationId, correlationId));
43
44 dummyClock.now();
45
46 correlationService.purgeOlderThanSec(correlationId, defaultUser(), 200);
47
48
49
50 assertEquals(correlationId, correlationService.getCorrelationId(correlationId, null));
51
52 dummyClock.now();
53
54 correlationService.purgeOlderThanSec(correlationId, defaultUser(), 200);
55
56
57
58 assertNotEquals(correlationId, correlationService.getCorrelationId(correlationId, null));
59 }
60 }