WroFilter implements Filter { public final void init(final FilterConfig config) throws ServletException { this.filterConfig = config; this.wroConfiguration = createConfiguration(); this.wroManagerFactory = createWroManagerFactory(); this.injector = createInjector(); headersConfigurer = newResponseHeadersConfigurer(); requestHandlers = createRequestHandlers(); registerChangeListeners(); registerMBean(); doInit(config); LOG.info("wro4j version: {}", WroUtil.getImplementationVersion()); LOG.info("wro4j configuration: {}", wroConfiguration); }  static boolean isPassedThroughyWroFilter(final HttpServletRequest request); final void init(final FilterConfig config); final void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain); void setWroManagerFactory(final WroManagerFactory wroManagerFactory); final WroManagerFactory getWroManagerFactory(); void setRequestHandlerFactory(final RequestHandlerFactory requestHandlerFactory); void setWroConfigurationFactory(final ObjectFactory<WroConfiguration> wroConfigurationFactory); final WroConfiguration getConfiguration(); final void setConfiguration(final WroConfiguration config); void setEnable(final boolean enable); void destroy(); static final String ATTRIBUTE_PASSED_THROUGH_FILTER; }
@Test(expected = WroRuntimeException.class) public void testFilterInitParamsAreWrong() throws Exception { when(mockFilterConfig.getInitParameter(ConfigConstants.cacheUpdatePeriod.name())).thenReturn("InvalidNumber"); when(mockFilterConfig.getInitParameter(ConfigConstants.modelUpdatePeriod.name())).thenReturn("100"); victim.init(mockFilterConfig); }
@Test(expected = WroRuntimeException.class) public void cannotAcceptInvalidAppFactoryClassNameIsSet() throws Exception { victim = new WroFilter(); when(mockFilterConfig.getInitParameter(ConfigConstants.managerFactoryClassName.name())).thenReturn("Invalid value"); victim.init(mockFilterConfig); }
@Test public void testValidAppFactoryClassNameIsSet() throws Exception { when(mockFilterConfig.getInitParameter(ConfigConstants.managerFactoryClassName.name())).thenReturn( BaseWroManagerFactory.class.getName()); victim.init(mockFilterConfig); }
@Test public void testJmxDisabled() throws Exception { when(mockFilterConfig.getInitParameter(ConfigConstants.jmxEnabled.name())).thenReturn("false"); victim.init(mockFilterConfig); }
@Test public void testValidHeaderParamIsSet() throws Exception { when(mockFilterConfig.getInitParameter(ConfigConstants.header.name())).thenReturn("ETag: 998989"); victim.init(mockFilterConfig); }
@Test public void testValidHeaderParamsAreSet() throws Exception { when(mockFilterConfig.getInitParameter(ConfigConstants.header.name())).thenReturn( "ETag: 998989 | Expires: Thu, 15 Apr 2010 20:00:00 GMT"); victim.init(mockFilterConfig); }
@Test(expected = WroRuntimeException.class) public void testInvalidHeaderParamIsSet() throws Exception { when(mockFilterConfig.getInitParameter(ConfigConstants.header.name())).thenReturn("ETag 998989 expires 1"); victim.init(mockFilterConfig); }
@Test public void modelShouldBeReloadedWhenReloadIsTriggered() throws Exception { final WroManagerFactory wroManagerFactory = new BaseWroManagerFactory().setModelFactory(new WroModelFactory() { private boolean wasCreated = false; public WroModel create() { if (!wasCreated) { wasCreated = true; return new WroModel(); } return new WroModel().addGroup(new Group("g1")); } public void destroy() { } }); final WroFilter filter = new WroFilter() { @Override protected WroManagerFactory newWroManagerFactory() { return wroManagerFactory; } @Override protected ObjectFactory<WroConfiguration> newWroConfigurationFactory(final FilterConfig filterConfig) { return new ObjectFactory<WroConfiguration>() { public WroConfiguration create() { return Context.get().getConfig(); } }; } }; filter.init(mockFilterConfig); final WroModelFactory modelFactory = wroManagerFactory.create().getModelFactory(); assertTrue(modelFactory.create().getGroups().isEmpty()); Context.get().getConfig().reloadModel(); assertEquals(1, modelFactory.create().getGroups().size()); }
@Test(expected = IllegalStateException.class) public void shouldFailWhenConfigurationFactoryFails() throws Exception { victim = new WroFilter() { @Override protected ObjectFactory<WroConfiguration> newWroConfigurationFactory(final FilterConfig filterConfig) { throw new IllegalStateException("BOOM!"); } }; victim.init(mockFilterConfig); }