/*
 * Copyright 1999-2015 dangdang.com.
 * <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.shardingjdbc.core.routing.router;


import io.shardingjdbc.core.api.HintManager;
import io.shardingjdbc.core.api.config.ShardingRuleConfiguration;
import io.shardingjdbc.core.api.config.TableRuleConfiguration;
import io.shardingjdbc.core.api.config.strategy.HintShardingStrategyConfiguration;
import io.shardingjdbc.core.fixture.OrderDatabaseHintShardingAlgorithm;
import io.shardingjdbc.core.hint.HintManagerHolder;
import io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement;
import io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement;
import io.shardingjdbc.core.rule.ShardingRule;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

public final class DatabaseHintSQLRouterTest {

    private DatabaseHintSQLRouter databaseHintSQLRouter;

    private ShardingRule shardingRule;

    private boolean showSQL;

    @Before
    public void setRouteRuleContext() {
        ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
        TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
        tableRuleConfig.setLogicTable("LOGIC_TABLE");
        tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
        shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
        shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new HintShardingStrategyConfiguration(new OrderDatabaseHintShardingAlgorithm()));
        shardingRule = new ShardingRule(shardingRuleConfig, Arrays.asList("ds0", "ds1"));
        showSQL=true;
        databaseHintSQLRouter = new DatabaseHintSQLRouter(shardingRule, showSQL);
    }

    @Test
    public void assertParse() {
        assertThat(databaseHintSQLRouter.parse("select t from table t", false), instanceOf(SelectStatement.class));
    }

    @Test
    public void assertRoute() {
        HintManager hintManager = HintManager.getInstance();
        hintManager.addDatabaseShardingValue(HintManagerHolder.DB_TABLE_NAME, HintManagerHolder.DB_COLUMN_NAME, 1);
        assertNotNull(databaseHintSQLRouter.route("select t from table t", Collections.emptyList(), new DQLStatement()));
    }
}
@@ -1580,78 +1580,8 @@
 r;%0A%0A
-    private ShardingRule shardingRule;%0A%0A    private boolean showSQL;%0A%0A
     
@@ -2141,32 +2141,45 @@
 hm()));%0A        
+ShardingRule 
 shardingRule = n
@@ -2248,30 +2248,8 @@
 ));%0A
-        showSQL=true;%0A
     
@@ -2320,15 +2320,12 @@
 le, 
-showSQL
+true
 );%0A 

add test case