PentahoSystemReadyListener implements ServletContextListener { @Override public void contextInitialized( ServletContextEvent servletContextEvent ) { IPluginManager pluginManager = PentahoSystem.get( IPluginManager.class ); IPentahoSession session = PentahoSessionHolder.getSession(); IPluginProvider pluginProvider = PentahoSystem.get( IPluginProvider.class, "IPluginProvider", session ); try { List<IPlatformPlugin> providedPlugins = pluginProvider.getPlugins( session ); for ( IPlatformPlugin plugin : providedPlugins ) { try { if ( !StringUtils.isEmpty( plugin.getLifecycleListenerClassname() ) ) { ClassLoader loader = pluginManager.getClassLoader( plugin.getId() ); Object listener = loader.loadClass( plugin.getLifecycleListenerClassname() ).newInstance(); if ( IPlatformReadyListener.class.isAssignableFrom( listener.getClass() ) ) { ( (IPlatformReadyListener) listener ).ready(); } } } catch ( Exception e ) { Logger.warn( PentahoSystemReadyListener.class.getName(), e.getMessage(), e ); } } } catch ( PlatformPluginRegistrationException e ) { Logger.warn( PentahoSystemReadyListener.class.getName(), e.getMessage(), e ); } }  @Override void contextInitialized( ServletContextEvent servletContextEvent ); @Override void contextDestroyed( ServletContextEvent servletContextEvent );  }
@Test public void testContextInitialized() throws Exception { when( pluginProvider.getPlugins( any( IPentahoSession.class ) ) ).thenReturn( pluginList ); when( pluginA.getLifecycleListenerClassname() ).thenReturn( TestReadyListener.class.getName() ); when( pluginA.getId() ).thenReturn( "PluginA" ); when( pluginB.getLifecycleListenerClassname() ).thenReturn( "" ); when( pluginManager.getClassLoader( "PluginA" ) ).thenReturn( classLoader ); Class clazz = TestReadyListener.class; when( classLoader.loadClass( TestReadyListener.class.getName() ) ).thenReturn( clazz ); systemReadyListener.contextInitialized( contextEvent ); assertTrue( TestReadyListener.readyCalled ); }