PentahoWebContextFilter implements Filter { Integer getRequireWaitTime() { Integer waitTime = null; if ( cache != null ) { waitTime = (Integer) cache.getFromGlobalCache( PentahoSystem.WAIT_SECONDS ); } if ( waitTime == null ) { try { waitTime = Integer.valueOf( PentahoSystem.getSystemSetting( PentahoSystem.WAIT_SECONDS, "30" ) ); } catch ( NumberFormatException e ) { waitTime = 30; } if ( cache != null ) { cache.putInGlobalCache( PentahoSystem.WAIT_SECONDS, waitTime ); } } return waitTime; }  @Override void init( FilterConfig filterConfig ); @Override void destroy(); @Override void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ); String getSsoEnabled(); void setSsoEnabled( String ssoEnabled ); static final String WEB_CONTEXT_JS; static final String PARAM_SSO_ENABLED; }
@Test public void testWebContextCachedWaitSecondVariable() throws Exception { ICacheManager cacheManager = Mockito.mock( ICacheManager.class ); when( cacheManager.getFromGlobalCache( PentahoSystem.WAIT_SECONDS ) ).thenReturn( null ).thenReturn( 30 ); PentahoWebContextFilter filter = new PentahoWebContextFilter(); PentahoWebContextFilter.cache = cacheManager; filter.getRequireWaitTime(); filter.getRequireWaitTime(); verify( cacheManager, times( 2 ) ).getFromGlobalCache( eq( PentahoSystem.WAIT_SECONDS ) ); verify( cacheManager, times( 1 ) ).putInGlobalCache( eq( PentahoSystem.WAIT_SECONDS ), anyObject() ); }
@Test public void testDoGetDefinesRequireCfg() throws ServletException, IOException { Integer waitTime = 1337; doReturn( waitTime ).when( this.pentahoWebContextFilter ).getRequireWaitTime(); String response = executeWebContextFilter(); String expected = "var requireCfg = {" + "\n waitSeconds: " + waitTime + "," + "\n paths: {}," + "\n shim: {}," + "\n map: {\"*\": {}}," + "\n bundles: {}," + "\n config: {\"pentaho/modules\": {}}," + "\n packages: []" + "\n};"; assertTrue( response.contains( expected ) ); }