WroManager implements WroConfigurationChangeListener { public final void process() throws IOException { final WroConfiguration config = Context.get().getConfig(); cacheSchedulerHelper.scheduleWithPeriod(config.getCacheUpdatePeriod()); modelSchedulerHelper.scheduleWithPeriod(config.getModelUpdatePeriod()); resourceBundleProcessor.serveProcessedBundle(); } private  WroManager(final Builder builder); final void process(); final String encodeVersionIntoGroupPath(final String groupName, final ResourceType resourceType,
      final boolean minimize); @Override final void onCachePeriodChanged(final long period); @Override final void onModelPeriodChanged(final long period); final void destroy(); final HashStrategy getHashStrategy(); final WroModelFactory getModelFactory(); final ProcessorsFactory getProcessorsFactory(); final CacheStrategy<CacheKey, CacheValue> getCacheStrategy(); final UriLocatorFactory getUriLocatorFactory(); final NamingStrategy getNamingStrategy(); final GroupExtractor getGroupExtractor(); CacheKeyFactory getCacheKeyFactory(); MetaDataFactory getMetaDataFactory(); ResourceWatcher getResourceWatcher(); final void registerCallback(final ObjectFactory<LifecycleCallback> callbackFactory); LifecycleCallbackRegistry getCallbackRegistry(); ResourceAuthorizationManager getResourceAuthorizationManager();  }
@Test public void testNoProcessorWroManagerFactory() throws IOException { final WroManagerFactory factory = new NoProcessorsWroManagerFactory().setModelFactory(getValidModelFactory()); final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Context.get().getResponse(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); Mockito.when(response.getOutputStream()).thenReturn(new DelegatingServletOutputStream(out)); Mockito.when(request.getRequestURI()).thenReturn("/app/g1.css"); Context.unset(); Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class))); factory.create().process(); WroTestUtils.compare(WroTestUtils.getInputStream("classpath:ro/isdc/wro/manager/noProcessorsResult.css"), new ByteArrayInputStream(out.toByteArray())); }
@Test public void processValidModel() throws IOException { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class, Mockito.RETURNS_DEEP_STUBS); Mockito.when(request.getRequestURI()).thenReturn("/app/g1.css"); Mockito.doAnswer(new Answer<Void>() { public Void answer(final InvocationOnMock invocation) throws Throwable { LOG.debug("Header: {}", Arrays.toString(invocation.getArguments())); final Object[] arguments = invocation.getArguments(); if (HttpHeader.ETAG.toString().equals(arguments[0])) { final String etagHeaderValue = (String) arguments[1]; Assert.assertTrue(etagHeaderValue.matches("\".*?\"")); } return null; } }).when(response).setHeader(Mockito.anyString(), Mockito.anyString()); Context.unset(); Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class))); managerFactory.create().process(); }
@Test public void testManagerWithSchedulerAndUpdatePeriodSet() throws Exception { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getRequestURI()).thenReturn("/app/g1.css"); final Context context = Context.webContext(request, Mockito.mock(HttpServletResponse.class, Mockito.RETURNS_DEEP_STUBS), Mockito.mock(FilterConfig.class)); final WroConfiguration config = new WroConfiguration(); config.setModelUpdatePeriod(1); config.setCacheUpdatePeriod(1); Context.unset(); Context.set(context, config); managerFactory.create().process(); Thread.sleep(1100); }
@Test public void testManagerWhenSchedulerIsStarted() throws Exception { newConfigWithUpdatePeriodValue(1); final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Context.get().getResponse(); Mockito.when(request.getRequestURI()).thenReturn("/app/g1.css"); Context.unset(); Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class))); managerFactory.create().process(); Thread.sleep(300); }
@Test public void testAggregatedComputedFolder() throws Exception { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Context.get().getResponse(); Mockito.when(request.getRequestURI()).thenReturn("/wro4j/wro/g1.css"); Context.unset(); Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class))); managerFactory.create().process(); Assert.assertEquals("/wro4j/wro/", Context.get().getAggregatedFolderPath()); }
@Test public void testAggregatedComputedFolder2() throws Exception { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Context.get().getResponse(); Mockito.when(request.getRequestURI()).thenReturn("/wro4j/wro/path/to/g1.css"); Context.unset(); Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class))); managerFactory.create().process(); Assert.assertEquals("/wro4j/wro/path/to/", Context.get().getAggregatedFolderPath()); }
@Test(expected = WroRuntimeException.class) public void shouldNotProcessGroupWithNoResources() throws Exception { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Context.get().getResponse(); Mockito.when(request.getRequestURI()).thenReturn("/noResources.css"); final WroConfiguration config = new WroConfiguration(); config.setIgnoreEmptyGroup(false); Context.unset(); Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class)), config); final WroModel model = new WroModel(); model.addGroup(new Group("noResources")); final WroManagerFactory managerFactory = new BaseWroManagerFactory().setModelFactory(WroUtil.factoryFor(model)); managerFactory.create().process(); }