package ro.isdc.wro.http;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ro.isdc.wro.config.Context;
import ro.isdc.wro.config.jmx.ConfigConstants;
import ro.isdc.wro.extensions.processor.js.CoffeeScriptProcessor;
import ro.isdc.wro.manager.WroManager;
import ro.isdc.wro.manager.factory.WroManagerFactory;
import ro.isdc.wro.model.resource.processor.ResourcePostProcessor;
import ro.isdc.wro.model.resource.processor.factory.ConfigurableProcessorsFactory;
import ro.isdc.wro.model.resource.processor.factory.ProcessorsFactory;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collection;
import java.util.Properties;

import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.when;

/**
 * @author Simon van der Sluis
 * @created Created on May 14, 2012
 */
public class TestConfigurableWroFilterWithExtensions
{

    private static final Logger LOG = LoggerFactory.getLogger(TestConfigurableWroFilterWithExtensions.class);
    @Mock
    private HttpServletRequest mockRequest;
    @Mock
    private HttpServletResponse mockResponse;
    @Mock
    private FilterChain mockFilterChain;
    @Mock
    private FilterConfig mockFilterConfig;
    @Mock
    private ServletContext mockServletContext;
    @Mock
    private ServletOutputStream mockServletOutputStream;

    @Before
    public void setUp() throws Exception {
      MockitoAnnotations.initMocks(this);
      when(mockRequest.getRequestURI()).thenReturn("/some.js");
      when(mockResponse.getOutputStream()).thenReturn(mockServletOutputStream);
      when(mockFilterConfig.getServletContext()).thenReturn(mockServletContext);
      Context.set(Context.webContext(mockRequest, mockResponse, mockFilterConfig));
    }

  @Test
  public void extensionProcessorsShouldBeAvailable() throws Exception {
    ConfigurableWroFilter filter = new ConfigurableWroFilter();
    final Properties properties = new Properties();
    properties.setProperty(ConfigurableProcessorsFactory.PARAM_POST_PROCESSORS, CoffeeScriptProcessor.ALIAS);
    filter.setProperties(properties);
    filter.init(mockFilterConfig);

    WroManagerFactory factory = filter.newWroManagerFactory();
    WroManager wroManager = factory.create();

    ProcessorsFactory processorsFactory = wroManager.getProcessorsFactory();
    Collection<ResourcePostProcessor> postProcessors = processorsFactory.getPostProcessors();

    assertEquals(1, postProcessors.size());
  }

}

@@ -1048,12 +1048,206 @@
 n;%0A%0A
+%0A
 /**%0A
+ * Proves that the code responsible for populating configurableWroManagerFactory with extensions processors does its job%0A * correctly (using reflection) when extension module is available.%0A * %0A
  * @
@@ -1369,132 +1369,19 @@
 ions
-%0A%7B%0A%0A    private static final Logger LOG = LoggerFactory.getLogger(TestConfigurableWroFilterWithExtensions.class);%0A  
+ %7B%0A
   @Mock%0A
     
@@ -1368,34 +1368,32 @@
 sions %7B%0A  @Mock%0A
-  
   private HttpSe
@@ -1418,18 +1418,16 @@
 equest;%0A
-  
   @Mock%0A
@@ -1420,34 +1420,32 @@
 uest;%0A  @Mock%0A  
- 
- 
 private HttpServ
@@ -1470,26 +1470,24 @@
 sponse;%0A
-  
   @Mock%0A
     priv
@@ -1482,61 +1482,8 @@
 ock%0A
-    private FilterChain mockFilterChain;%0A    @Mock%0A  
   pr
@@ -1517,34 +1517,30 @@
 erConfig;%0A  
- 
- 
 @Mock%0A
-  
   private Se
@@ -1572,18 +1572,16 @@
 ontext;%0A
-  
   @Mock%0A
@@ -1582,18 +1582,16 @@
 @Mock%0A  
- 
- 
 private 
@@ -1635,19 +1635,19 @@
 Stream;%0A
-%0A
   
+%0A
   @Befor
@@ -1648,18 +1648,16 @@
 @Before%0A
-  
   public
@@ -1669,16 +1669,22 @@
  setUp()
+%0A     
  throws 
@@ -1695,18 +1695,16 @@
 ption %7B%0A
-  
     Mock
@@ -1735,26 +1735,24 @@
 (this);%0A    
-  
 when(mockReq
@@ -1797,18 +1797,16 @@
 e.js%22);%0A
-  
     when
@@ -1875,18 +1875,16 @@
 tream);%0A
-  
     when
@@ -1958,18 +1958,16 @@
 t);%0A    
-  
 Context.
@@ -2038,20 +2038,20 @@
 ig));%0A  
-  
 %7D%0A
+  
 %0A  @Test
@@ -2103,16 +2103,22 @@
 ilable()
+%0A     
  throws 
@@ -2428,16 +2428,20 @@
 onfig);%0A
+    
 %0A    Wro
@@ -2538,24 +2538,28 @@
 y.create();%0A
+    
 %0A    Process
@@ -2718,16 +2718,20 @@
 sors();%0A
+    
 %0A    ass
@@ -2771,11 +2771,13 @@
 ));%0A  %7D%0A
+  
 %0A%7D%0A

update javadoc