/*
 * Copyright 2013 Rackspace
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.rackspacecloud.blueflood.cache;

import com.rackspacecloud.blueflood.rollup.Granularity;
import com.rackspacecloud.blueflood.service.Configuration;
import com.rackspacecloud.blueflood.service.TtlConfig;
import com.rackspacecloud.blueflood.types.RollupType;
import com.rackspacecloud.blueflood.utils.TimeValue;
import org.junit.Assert;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

public class ConfigTtlProviderTest {

    @Test
    public void testConfigTtl() throws Exception {
        final ConfigTtlProvider ttlProvider = ConfigTtlProvider.getInstance();
        final Configuration config = Configuration.getInstance();

        Assert.assertTrue(new TimeValue(config.getIntegerProperty(TtlConfig.RAW_METRICS_TTL), TimeUnit.DAYS).equals(
                ttlProvider.getTTL("acFoo", Granularity.FULL, RollupType.BF_BASIC)));

        // Ask for an invalid combination of granularity and rollup type
        Assert.assertNull(ttlProvider.getTTL("acBar", Granularity.FULL, RollupType.BF_HISTOGRAMS));
    }

    @Test
    public void testConfigTtlForStrings() throws Exception {
        final ConfigTtlProvider ttlProvider = ConfigTtlProvider.getInstance();
        final Configuration config = Configuration.getInstance();

        Assert.assertTrue(new TimeValue(config.getIntegerProperty(TtlConfig.STRING_METRICS_TTL), TimeUnit.DAYS).equals(
                ttlProvider.getTTLForStrings("acFoo")));
    }
}

@@ -659,16 +659,80 @@
 cache;%0A%0A
+import com.rackspacecloud.blueflood.exceptions.ConfigException;%0A
 import c
@@ -1610,16 +1610,34 @@
 up type%0A
+        try %7B%0A    
         
@@ -1724,24 +1724,192 @@
 STOGRAMS));%0A
+        %7D catch (ConfigException ex) %7B%0A            // pass%0A        %7D catch (Exception ex) %7B%0A            Assert.fail(%22Should have thrown a ConfigException.%22);%0A        %7D%0A
     %7D%0A%0A    @

Fix broken test