1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.service.cache;
35
36 import java.util.List;
37
38 import org.springframework.mock.web.MockHttpServletRequest;
39
40 import fr.paris.lutece.portal.business.page.Page;
41 import fr.paris.lutece.portal.service.page.PageEvent;
42 import fr.paris.lutece.test.LuteceTestCase;
43
44 public class PathCacheServiceDisabledTest extends LuteceTestCase
45 {
46 IPathCacheService service;
47 boolean bEnabled;
48
49 @Override
50 protected void setUp( ) throws Exception
51 {
52 super.setUp( );
53 service = null;
54 List<CacheableService> serviceList = CacheService.getCacheableServicesList( );
55 for ( CacheableService aService : serviceList )
56 {
57 if ( aService instanceof IPathCacheService )
58 {
59 service = (IPathCacheService) aService;
60 bEnabled = aService.isCacheEnable( );
61 aService.enableCache( false );
62 break;
63 }
64 }
65 assertNotNull( service );
66 }
67
68 @Override
69 protected void tearDown( ) throws Exception
70 {
71 List<CacheableService> serviceList = CacheService.getCacheableServicesList( );
72 for ( CacheableService aService : serviceList )
73 {
74 if ( aService == service )
75 {
76 aService.enableCache( bEnabled );
77 break;
78 }
79 }
80 service = null;
81 super.tearDown( );
82 }
83
84 public void testGetKey( )
85 {
86 assertNull( service.getKey( "junit", 0, new MockHttpServletRequest( ) ) );
87 assertNull( service.getKey( "junit", 0, "junit", new MockHttpServletRequest( ) ) );
88 }
89
90 public void testPutAndGetFromCache( )
91 {
92 service.putInCache( null, "junit" );
93 String key = service.getKey( "junit", 0, null );
94 service.putInCache( key, "junit" );
95 assertNull( service.getFromCache( key ) );
96 assertNull( service.getFromCache( null ) );
97 assertNull( service.getFromCache( "NotInCache" ) );
98 }
99
100 public void testProcessPageEvent( )
101 {
102 String key = service.getKey( "junit", 0, null );
103 for ( int nEventType : new int [ ] {
104 PageEvent.PAGE_CONTENT_MODIFIED, PageEvent.PAGE_CREATED, PageEvent.PAGE_DELETED, PageEvent.PAGE_MOVED, PageEvent.PAGE_STATE_CHANGED
105 } )
106 {
107 service.putInCache( key, "junit" );
108 PageEvent event = new PageEvent( new Page( ), nEventType );
109 ( (PathCacheService) service ).processPageEvent( event );
110 assertNull( service.getFromCache( key ) );
111 }
112 }
113
114 }