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.web.includes;
35
36 import java.util.HashSet;
37 import java.util.Locale;
38 import java.util.Set;
39
40 import fr.paris.lutece.portal.service.plugin.Plugin;
41 import fr.paris.lutece.portal.service.plugin.PluginEvent;
42 import fr.paris.lutece.portal.service.plugin.PluginService;
43 import fr.paris.lutece.portal.service.spring.SpringContextService;
44 import fr.paris.lutece.test.LuteceTestCase;
45
46 public class LinksIncludeCacheServiceTest extends LuteceTestCase
47 {
48 private LinksIncludeCacheService service;
49 private boolean bOrigCacheStatus;
50
51 @Override
52 protected void setUp( ) throws Exception
53 {
54 super.setUp( );
55 service = SpringContextService.getBean( LinksIncludeCacheService.SERVICE_NAME );
56 bOrigCacheStatus = service.isCacheEnable( );
57 service.enableCache( true );
58 }
59
60 @Override
61 protected void tearDown( ) throws Exception
62 {
63 service.enableCache( bOrigCacheStatus );
64 super.tearDown( );
65 }
66
67 public void testGetCacheKey( )
68 {
69 Set<String> keys = new HashSet<>( );
70 for ( int nMode : new int [ ] {
71 0, 1
72 } )
73 {
74 for ( String strPage : new String [ ] {
75 null, "test", "test2"
76 } )
77 {
78 for ( Locale locale : new Locale [ ] {
79 null, Locale.FRANCE, Locale.FRENCH
80 } )
81 {
82 String key = service.getCacheKey( nMode, strPage, locale );
83 assertTrue( "key " + key + " was already generated", keys.add( key ) );
84 }
85 }
86 }
87 }
88
89 public void testProcessPluginEvent( )
90 {
91 service.putInCache( "key", "value" );
92 assertEquals( "value", service.getFromCache( "key" ) );
93 service.processPluginEvent( null );
94 assertNull( service.getFromCache( "key" ) );
95 for ( Plugin plugin : new Plugin [ ] {
96 null, PluginService.getCore( )
97 } )
98 {
99 for ( int eventType : new int [ ] {
100 PluginEvent.PLUGIN_INSTALLED, PluginEvent.PLUGIN_POOL_CHANGED, PluginEvent.PLUGIN_UNINSTALLED
101 } )
102 {
103 service.putInCache( "key", "value" );
104 assertEquals( "value", service.getFromCache( "key" ) );
105 PluginEvent event = new PluginEvent( plugin, eventType );
106 service.processPluginEvent( event );
107 assertNull( service.getFromCache( "key" ) );
108 }
109 }
110 }
111
112 }