/*
 * 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.api;

import io.shardingsphere.core.api.algorithm.sharding.ListShardingValue;
import io.shardingsphere.core.hint.HintManagerHolder;
import org.junit.Test;

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

public final class HintManagerTest {
    
    @Test
    public void assertAddDatabaseShardingValueForEquals() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.addDatabaseShardingValue("logicTable", 1);
            assertTrue(HintManagerHolder.getDatabaseShardingValue("logicTable").isPresent());
            assertThat(hintManager.getDatabaseShardingValue("logicTable").getColumnName(), is(HintManagerHolder.DB_COLUMN_NAME));
            assertThat(((ListShardingValue<? extends Comparable>) hintManager.getDatabaseShardingValue("logicTable")).getValues().iterator().next(), is((Comparable) 1));
        }
    }
    
    @Test
    public void assertAddDatabaseShardingValueForIn() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.addDatabaseShardingValue("logicTable", 1, 3, 5);
            assertTrue(HintManagerHolder.getDatabaseShardingValue("logicTable").isPresent());
            assertThat(hintManager.getDatabaseShardingValue("logicTable").getColumnName(), is(HintManagerHolder.DB_COLUMN_NAME));
            assertThat(((ListShardingValue) hintManager.getDatabaseShardingValue("logicTable")).getValues().size(), is(3));
        }
    }
    
    @SuppressWarnings("unchecked")
    @Test
    public void assertAddTableShardingValueForEquals() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.addTableShardingValue("logicTable", 1);
            assertTrue(HintManagerHolder.getTableShardingValue("logicTable").isPresent());
            assertThat(hintManager.getTableShardingValue("logicTable").getColumnName(), is(HintManagerHolder.DB_COLUMN_NAME));
            assertThat(((ListShardingValue<? extends Comparable>) hintManager.getTableShardingValue("logicTable")).getValues().iterator().next(), is((Comparable) 1));
        }
    }
    
    @Test
    public void assertAddTableShardingValueForIn() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.addTableShardingValue("logicTable", 1, 3, 5);
            assertTrue(HintManagerHolder.getTableShardingValue("logicTable").isPresent());
            assertThat(hintManager.getTableShardingValue("logicTable").getColumnName(), is(HintManagerHolder.DB_COLUMN_NAME));
            assertThat(((ListShardingValue) hintManager.getTableShardingValue("logicTable")).getValues().size(), is(3));
        }
    }
    
    @Test
    public void assertAddDatabaseShardingOnly() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setDatabaseShardingValue("1");
            assertTrue(HintManagerHolder.isDatabaseShardingOnly());
            assertThat((String) ((ListShardingValue) 
                    hintManager.getDatabaseShardingValue(HintManagerHolder.DB_TABLE_NAME)).getValues().iterator().next(), is("1"));
        }
    }
}

@@ -1287,33 +1287,33 @@
      assertThat(
-h
+H
 intManager.getDa
@@ -1298,32 +1298,38 @@
 That(HintManager
+Holder
 .getDatabaseShar
@@ -1344,32 +1344,38 @@
 e(%22logicTable%22).
+get().
 getColumnName(),
@@ -1472,33 +1472,33 @@
 ds Comparable%3E) 
-h
+H
 intManager.getDa
@@ -1483,32 +1483,38 @@
 le%3E) HintManager
+Holder
 .getDatabaseShar
@@ -1528,32 +1528,38 @@
 ue(%22logicTable%22)
+.get()
 ).getValues().it
@@ -1933,33 +1933,33 @@
      assertThat(
-h
+H
 intManager.getDa
@@ -1944,32 +1944,38 @@
 That(HintManager
+Holder
 .getDatabaseShar
@@ -1990,32 +1990,38 @@
 e(%22logicTable%22).
+get().
 getColumnName(),
@@ -2096,33 +2096,33 @@
 tShardingValue) 
-h
+H
 intManager.getDa
@@ -2107,32 +2107,38 @@
 lue) HintManager
+Holder
 .getDatabaseShar
@@ -2152,32 +2152,38 @@
 ue(%22logicTable%22)
+.get()
 ).getValues().si
@@ -2557,33 +2557,33 @@
      assertThat(
-h
+H
 intManager.getTa
@@ -2568,32 +2568,38 @@
 That(HintManager
+Holder
 .getTableShardin
@@ -2611,32 +2611,38 @@
 e(%22logicTable%22).
+get().
 getColumnName(),
@@ -2747,17 +2747,17 @@
 rable%3E) 
-h
+H
 intManag
@@ -2750,32 +2750,38 @@
 le%3E) HintManager
+Holder
 .getTableShardin
@@ -2792,32 +2792,38 @@
 ue(%22logicTable%22)
+.get()
 ).getValues().it
@@ -3196,17 +3196,17 @@
 ertThat(
-h
+H
 intManag
@@ -3199,32 +3199,38 @@
 That(HintManager
+Holder
 .getTableShardin
@@ -3250,16 +3250,22 @@
 Table%22).
+get().
 getColum
@@ -3356,17 +3356,17 @@
 gValue) 
-h
+H
 intManag
@@ -3363,24 +3363,30 @@
  HintManager
+Holder
 .getTableSha
@@ -3409,16 +3409,22 @@
 cTable%22)
+.get()
 ).getVal
@@ -3769,17 +3769,16 @@
 ngValue)
- 
 %0A       
@@ -3782,33 +3782,33 @@
                 
-h
+H
 intManager.getDa
@@ -3797,24 +3797,30 @@
  HintManager
+Holder
 .getDatabase
@@ -3865,16 +3865,22 @@
 LE_NAME)
+.get()
 ).getVal

modify cases