/*
 * Copyright (C) 2011.
 * All rights reserved.
 */
package ro.isdc.wro.config.factory;

import java.util.Properties;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ro.isdc.wro.WroRuntimeException;
import ro.isdc.wro.config.jmx.ConfigConstants;
import ro.isdc.wro.config.jmx.WroConfiguration;


/**
 * @author Alex Objelean
 */
public class TestPropertyWroConfigurationFactory {
  private static final Logger LOG = LoggerFactory.getLogger(TestPropertyWroConfigurationFactory.class);
  private PropertyWroConfigurationFactory factory;


  @Before
  public void setUp() {
    factory = new PropertyWroConfigurationFactory();
  }


  @Test
  public void testCreateDefaultConfig() {
    factory.setProperties(null);
    final WroConfiguration config = factory.create();
    LOG.debug("config: {}", config);
    Assert.assertNotNull(config);
    Assert.assertEquals(0, config.getModelUpdatePeriod());
    Assert.assertEquals(0, config.getCacheUpdatePeriod());
    Assert.assertEquals(true, config.isDebug());
    Assert.assertEquals(false, config.isDisableCache());
    Assert.assertEquals(true, config.isGzipEnabled());
    Assert.assertEquals(true, config.isIgnoreMissingResources());
    Assert.assertEquals(true, config.isJmxEnabled());
  }


  @Test
  public void testConfigWithProperties() {
    final Properties props = new Properties();
    props.setProperty(ConfigConstants.cacheUpdatePeriod.name(), "10");
    props.setProperty(ConfigConstants.modelUpdatePeriod.name(), "20");
    props.setProperty(ConfigConstants.disableCache.name(), "true");
    props.setProperty(ConfigConstants.gzipResources.name(), "false");
    factory.setProperties(props);
    final WroConfiguration config = factory.create();
    LOG.debug("config: {}", config);
    Assert.assertEquals(10, config.getCacheUpdatePeriod());
    Assert.assertEquals(20, config.getModelUpdatePeriod());
    Assert.assertEquals(true, config.isDisableCache());
    Assert.assertEquals(false, config.isGzipEnabled());
  }


  @Test(expected = WroRuntimeException.class)
  public void testConfigWithInvalidProperties() {
    final Properties props = new Properties();
    props.setProperty(ConfigConstants.cacheUpdatePeriod.name(), "INVALID_LONG");
    factory.setProperties(props);
    final WroConfiguration config = factory.create();
    LOG.debug("config: {}", config);
    Assert.assertEquals(0, config.getCacheUpdatePeriod());
  }
}

@@ -1324,34 +1324,520 @@
 mxEnabled());%0A  
+  Assert.assertEquals(false, config.isCacheGzippedContent());%0A    Assert.assertEquals(false, config.isParallelPreprocessing());%0A  %7D%0A%0A  @Test%0A  public void invalidBooleanFallbacksToFalse() %7B%0A    final Properties props = new Properties();%0A    props.setProperty(ConfigConstants.cacheGzippedContent.name(), %22INVALID_BOOLEAN%22);%0A    %0A    factory.setProperties(props);%0A    final WroConfiguration config = factory.create();%0A    %0A    Assert.assertEquals(false, config.isCacheGzippedContent());%0A  
 %7D
-%0A
 %0A%0A  @Test%0A  publ
@@ -2196,24 +2196,176 @@
 , %22false%22);%0A
+    props.setProperty(ConfigConstants.cacheGzippedContent.name(), %22true%22);%0A    props.setProperty(ConfigConstants.parallelPreprocessing.name(), %22true%22);%0A
     factory.
@@ -2705,24 +2705,152 @@
 Enabled());%0A
+    Assert.assertEquals(true, config.isCacheGzippedContent());%0A    Assert.assertEquals(true, config.isParallelPreprocessing());%0A
   %7D%0A%0A%0A  @Tes

add unit tests