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

import com.google.common.base.Function;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import io.shardingsphere.jdbc.orchestration.api.yaml.YamlOrchestrationShardingDataSourceFactory;
import io.shardingsphere.jdbc.orchestration.internal.OrchestrationShardingDataSource;
import io.shardingsphere.jdbc.orchestration.yaml.AbstractYamlDataSourceTest;
import lombok.RequiredArgsConstructor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Collection;

@RunWith(Parameterized.class)
@RequiredArgsConstructor
public class YamlOrchestrationShardingIntegrateTest extends AbstractYamlDataSourceTest {
    
    private final String filePath;
    
    private final boolean hasDataSource;
    
    @Parameterized.Parameters(name = "{index}:{0}-{1}")
    public static Collection init() {
        return Arrays.asList(new Object[][]{
                {"/yaml/integrate/sharding/configWithDataSourceWithoutProps.yaml", true},
//                {"/yaml/integrate/sharding/configWithoutDataSourceWithoutProps.yaml", false},
//                {"/yaml/integrate/sharding/configWithDataSourceWithProps.yaml", true},
//                {"/yaml/integrate/sharding/configWithoutDataSourceWithProps.yaml", false},
        });
    }
    
    @Test
    public void assertWithDataSource() throws SQLException, URISyntaxException, IOException {
        File yamlFile = new File(YamlOrchestrationShardingIntegrateTest.class.getResource(filePath).toURI());
        DataSource dataSource;
        if (hasDataSource) {
            dataSource = YamlOrchestrationShardingDataSourceFactory.createDataSource(yamlFile);
        } else {
            dataSource = YamlOrchestrationShardingDataSourceFactory.createDataSource(Maps.asMap(Sets.newHashSet("db0", "db1"), new Function<String, DataSource>() {
                @Override
                public DataSource apply(final String key) {
                    return createDataSource(key);
                }
            }), yamlFile);
        }
        try (Connection conn = dataSource.getConnection();
             Statement stm = conn.createStatement()) {
//            stm.execute(String.format("INSERT INTO t_order(user_id,status) values(%d, %s)", 10, "'insert'"));
            stm.executeQuery("SELECT * FROM t_order");
//            stm.executeQuery("SELECT * FROM t_order_item");
//            stm.executeQuery("SELECT * FROM config");
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ((OrchestrationShardingDataSource) dataSource).close();
    }
}

@@ -1898,34 +1898,32 @@
 s.yaml%22, true%7D,%0A
-//
                 
@@ -1996,26 +1996,24 @@
 l%22, false%7D,%0A
-//
             
@@ -2087,18 +2087,16 @@
  true%7D,%0A
-//
         
@@ -3057,18 +3057,16 @@
 nt()) %7B%0A
-//
         
@@ -3218,26 +3218,24 @@
  t_order%22);%0A
-//
             
@@ -3282,18 +3282,16 @@
 item%22);%0A
-//
         
@@ -3340,113 +3340,8 @@
 %22);%0A
-            Thread.sleep(1);%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A
     

use all test