/*
 * 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.core.yaml.sharding;

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

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

public class YamlKeyGeneratorConfigurationTest {
    
    @Test
    public void assertGetKeyGeneratorWithClassName() {
        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();
        keyGeneratorConfiguration.setClassName("io.shardingsphere.core.keygen.generator.SnowflakeKeyGenerator");
        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(SnowflakeKeyGenerator.class.getName()));
    }
    
    @Test
    public void assertGetKeyGeneratorWithSnowflakeType() {
        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();
        keyGeneratorConfiguration.setType("SNOWFLAKE");
        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(SnowflakeKeyGenerator.class.getName()));
    }
    
    @Test
    public void assertGetKeyGeneratorWithoutTypeAndClassName() {
        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();
        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(SnowflakeKeyGenerator.class.getName()));
    }
    
    @Test(expected = IllegalArgumentException.class)
    public void assertGetKeyGeneratorClassNameWithLeaf() {
        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();
        keyGeneratorConfiguration.setType("LEAF");
        keyGeneratorConfiguration.getKeyGenerator();
    }
    
    @Test
    public void assertGetKeyGeneratorClassNameWithUUID() {
        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();
        keyGeneratorConfiguration.setType("UUID");
        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(UUIDKeyGenerator.class.getName()));
    }
    
    @Test(expected = ShardingConfigurationException.class)
    public void assertGetKeyGeneratorClassNameWithException() {
        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();
        keyGeneratorConfiguration.setType("DEFAULT");
        keyGeneratorConfiguration.getKeyGenerator();
    }
    
    @Test
    public void assertGetKeyGeneratorVariables() {
        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();
        keyGeneratorConfiguration.setType("SNOWFLAKE");
        keyGeneratorConfiguration.setClassName("io.shardingsphere.core.keygen.generator.SnowflakeKeyGenerator");
        keyGeneratorConfiguration.setColumn("order_id");
        assertThat(keyGeneratorConfiguration.getType(), is("SNOWFLAKE"));
        assertThat(keyGeneratorConfiguration.getClassName(), is("io.shardingsphere.core.keygen.generator.SnowflakeKeyGenerator"));
        assertThat(keyGeneratorConfiguration.getColumn(), is("order_id"));
    }
}

@@ -689,188 +689,44 @@
 ere.
-core.exception.ShardingConfigurationException;%0Aimport io.shardingsphere.core.keygen.generator.SnowflakeKeyGenerator;%0Aimport io.shardingsphere.core.keygen.generator.UUIDKeyGenerator
+api.config.KeyGeneratorConfiguration
 ;%0Aim
@@ -740,20 +740,22 @@
 g.junit.
-Test
+Before
 ;%0A%0Aimpor
@@ -760,2380 +760,290 @@
 ort 
-static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0A%0Apublic class YamlKeyGeneratorConfigurationTest %7B%0A    %0A    @Test%0A    public void assertGetKeyGeneratorWithClassName() %7B%0A        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();%0A        keyGeneratorConfiguration.setClassName(%22io.shardingsphere.core.keygen.generator.SnowflakeKeyGenerator%22);%0A        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(SnowflakeKeyGenerator.class.getName()));%0A    %7D%0A    %0A    @Test%0A    public void assertGetKeyGeneratorWithSnowflakeType() %7B%0A        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();%0A        keyGeneratorConfiguration.setType(%22SNOWFLAKE%22);%0A        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(SnowflakeKeyGenerator.class.getName()));%0A    %7D%0A    %0A    @Test%0A    public void assertGetKeyGeneratorWithoutTypeAndClassName() %7B%0A        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();%0A        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(SnowflakeKeyGenerator.class.getName())
+java.util.Properties;%0A%0Apublic class YamlKeyGeneratorConfigurationTest %7B%0A    %0A    private KeyGeneratorConfiguration keyGeneratorConfiguration;%0A    %0A    @Before%0A    public void setUp() %7B%0A        Properties props = new Properties(
 );%0A    
-%7D%0A
     
-%0A    @Test(expected = IllegalArgumentException.class)%0A    public void assertGetKeyGeneratorClassNameWithLeaf() %7B%0A        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();%0A        keyGeneratorConfiguration.setType(%22LEAF%22);%0A        keyGeneratorConfiguration.getKeyGenerator();%0A    %7D%0A    %0A    @Test%0A    public void assertGetKeyGeneratorClassNameWithUUID() %7B%0A        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();%0A        keyGeneratorConfiguration.setType(%22UUID%22);%0A        assertThat(keyGeneratorConfiguration.getKeyGenerator().getClass().getName(), is(UUIDKeyGenerator.class.getName()));%0A    %7D%0A    %0A    @Test(expected = ShardingConfigurationException.class)%0A    public void assertGetKeyGeneratorClassNameWithException() %7B%0A        YamlKeyGeneratorConfiguration keyGeneratorConfiguration = new YamlKeyGeneratorConfiguration();%0A        keyGeneratorConfiguration.setType(%22DEFAULT%22);%0A        keyGeneratorConfiguration.getKeyGenerator();%0A    %7D%0A    %0A    @Test%0A    public void assertGetKeyGeneratorVariables() %7B%0A        YamlKeyGeneratorConfiguration
+props.setProperty(%22key1%22, %22value1%22);%0A       
  key
@@ -1071,20 +1071,16 @@
 n = new 
-Yaml
 KeyGener
@@ -1101,514 +1101,39 @@
 ion(
-);%0A        keyGeneratorConfiguration.setType(%22SNOWFLAKE%22);%0A        keyGeneratorConfiguration.setClassName(%22io.shardingsphere.core.keygen.generator.SnowflakeKeyGenerator%22);%0A        keyGeneratorConfiguration.setColumn(%22order_id%22);%0A        assertThat(keyGeneratorConfiguration.getType(), is(%22SNOWFLAKE%22));%0A        assertThat(keyGeneratorConfiguration.getClassName(), is(%22io.shardingsphere.core.keygen.generator.SnowflakeKeyGenerator%22));%0A        assertThat(keyGeneratorConfiguration.getColumn(), is(%22order_id%22)
+%22order_id%22, %22UUID%22, null, props
 );%0A 
@@ -1137,10 +1137,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

add setUp()