/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * 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.
 * </p>
 */

package io.shardingsphere.api.config;

import io.shardingsphere.core.exception.ShardingConfigurationException;
import io.shardingsphere.core.keygen.generator.SnowflakeKeyGenerator;
import io.shardingsphere.core.keygen.generator.UUIDKeyGenerator;
import io.shardingsphere.core.yaml.sharding.YamlKeyGeneratorConfiguration;
import org.junit.Test;

import java.util.Properties;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class KeyGeneratorConfigurationTest {
    
    @Test
    public void assertGetKeyGeneratorWithAllProperties() {
        KeyGeneratorConfiguration keyGeneratorConfiguration = new KeyGeneratorConfiguration("order_id", "SNOWFLAKE", new Properties());
        assertThat(keyGeneratorConfiguration.getColumn(), is("order_id"));
        assertThat(keyGeneratorConfiguration.getType(), is("SNOWFLAKE"));
        assertThat(keyGeneratorConfiguration.getProps().entrySet().size(), is(0));
    }
    
    @Test
    public void assertGetKeyGeneratorWithSnowflakeType() {
        KeyGeneratorConfiguration keyGeneratorConfiguration = new KeyGeneratorConfiguration("order_id", "SNOWFLAKE", new Properties());
        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(SnowflakeKeyGenerator.class.getName()));
    }
        
    @Test
    public void assertGetKeyGeneratorClassNameWithUUID() {
        KeyGeneratorConfiguration keyGeneratorConfiguration = new KeyGeneratorConfiguration();
        keyGeneratorConfiguration.setType("UUID");
        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(UUIDKeyGenerator.class.getName()));
    }
    
    @Test(expected = ShardingConfigurationException.class)
    public void assertGetKeyGeneratorClassNameWithException() {
        KeyGeneratorConfiguration keyGeneratorConfiguration = new KeyGeneratorConfiguration();
        keyGeneratorConfiguration.setType("DEFAULT");
        keyGeneratorConfiguration.getKeyGenerator();
    }
    
    @Test
    public void assertGetKeyGeneratorVariables() {
        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();
        keyGeneratorConfiguration.setType("SNOWFLAKE");
        keyGeneratorConfiguration.setColumn("order_id");
        assertThat(keyGeneratorConfiguration.getType(), is("SNOWFLAKE"));
        assertThat(keyGeneratorConfiguration.getColumn(), is("order_id"));
    }
}

@@ -863,83 +863,8 @@
 or;%0A
-import io.shardingsphere.core.yaml.sharding.YamlKeyGeneratorConfiguration;%0A
 impo
@@ -999,16 +999,59 @@
 ertThat;
+%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Apublic
@@ -2646,20 +2646,16 @@
         
-Yaml
 KeyGener
@@ -2708,12 +2708,8 @@
 new 
-Yaml
 KeyG
@@ -2745,258 +2745,69 @@
     
-keyGeneratorConfiguration.setType(%22SNOWFLAKE%22);%0A        keyGeneratorConfiguration.setColumn(%22order_id%22);%0A        assertThat(keyGeneratorConfiguration.getType(), is(%22SNOWFLAKE%22));%0A        assertThat(keyGeneratorConfiguration.getColumn(), is(%22order_id%22
+assertTrue(null == keyGeneratorConfiguration.getKeyGenerator(
 ));%0A

modify KeyGeneratorConfigurationTest.java