/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.shardingsphere.core.rewrite;

import org.apache.shardingsphere.api.config.encryptor.EncryptRuleConfiguration;
import org.apache.shardingsphere.api.config.encryptor.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.api.config.encryptor.EncryptorConfiguration;
import org.apache.shardingsphere.core.metadata.table.ColumnMetaData;
import org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetaData;
import org.junit.Before;

import java.util.Arrays;
import java.util.Properties;

public final class EncryptSQLRewriteEngineTest {
    
    @Before
    public void setUp() {
        
    }
    
    private EncryptRuleConfiguration createEncryptRuleConfiguration() {
        EncryptorConfiguration encryptorConfig = new EncryptorConfiguration("test", "col1, col2", new Properties());
        EncryptTableRuleConfiguration encryptTableRuleConfig = new EncryptTableRuleConfiguration();
        encryptTableRuleConfig.setTable("t_encrypt");
        encryptTableRuleConfig.setEncryptorConfig(encryptorConfig);
        EncryptorConfiguration encryptorQueryConfig = new EncryptorConfiguration("assistedTest", "col1, col2", "query1, query2", new Properties());
        EncryptTableRuleConfiguration encryptQueryTableRuleConfig = new EncryptTableRuleConfiguration();
        encryptQueryTableRuleConfig.setTable("t_query_encrypt");
        encryptQueryTableRuleConfig.setEncryptorConfig(encryptorQueryConfig);
        EncryptRuleConfiguration result = new EncryptRuleConfiguration();
        result.getTableRuleConfigs().add(encryptTableRuleConfig);
        result.getTableRuleConfigs().add(encryptQueryTableRuleConfig);
        return result;
    }
    
    private ShardingTableMetaData createShardingTableMetaData() {
        ColumnMetaData columnMetaData1 = new ColumnMetaData("col1", "VARCHAR(10)", false);
        ColumnMetaData columnMetaData2 = new ColumnMetaData("col2", "VARCHAR(10)", false);
        ColumnMetaData queryColumnnMetaData1 = new ColumnMetaData("col1", "VARCHAR(10)", false);
        ColumnMetaData queryColumnMetaData2 = new ColumnMetaData("col2", "VARCHAR(10)", false);
        TableMetaData encryptTableMetaData = new TableMetaData(Arrays.asList(columnMetaData1, columnMetaData2));
        
        ShardingTableMetaData result = new ShardingTableMetaData();
    }
}

@@ -1352,16 +1352,70 @@
 Arrays;%0A
+import java.util.LinkedHashMap;%0Aimport java.util.Map;%0A
 import j
@@ -2882,17 +2882,16 @@
 ryColumn
-n
 MetaData
@@ -2906,35 +2906,37 @@
 ColumnMetaData(%22
-col
+query
 1%22, %22VARCHAR(10)
@@ -3004,35 +3004,37 @@
 ColumnMetaData(%22
-col
+query
 2%22, %22VARCHAR(10)
@@ -3161,24 +3161,170 @@
 ));%0A        
+TableMetaData queryTableMetaData = new TableMetaData(Arrays.asList(columnMetaData1, columnMetaData2, queryColumnMetaData1, queryColumnMetaData2));
 %0A        Sha
@@ -3320,24 +3320,28 @@
         
-Shard
+Map%3CStr
 ing
+, 
 TableMet
@@ -3345,25 +3345,178 @@
 MetaData
- result =
+%3E tables = new LinkedHashMap%3C%3E();%0A        tables.put(%22t_encrypt%22, encryptTableMetaData);%0A        tables.put(%22t_query_encrypt%22, queryTableMetaData);%0A        return
  new Sha
@@ -3534,16 +3534,22 @@
 etaData(
+tables
 );%0A    %7D

modify createShardingTableMetaData()