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

import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.metadata.datasource.dialect.H2DataSourceMetaData;
import io.shardingsphere.core.metadata.datasource.dialect.MySQLDataSourceMetaData;
import io.shardingsphere.core.metadata.datasource.dialect.OracleDataSourceMetaData;
import io.shardingsphere.core.metadata.datasource.dialect.PostgreSQLDataSourceMetaData;
import io.shardingsphere.core.metadata.datasource.dialect.SQLServerDataSourceMetaData;
import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class DataSourceMetaDataFactoryTest {
    
    @Test
    public void assertAllNewInstanceForH2() {
        assertTrue(DataSourceMetaDataFactory.newInstance(DatabaseType.H2, "jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL") instanceof H2DataSourceMetaData);
    }
    
    @Test
    public void assertAllNewInstanceForMySQL() {
        assertTrue(DataSourceMetaDataFactory.newInstance(DatabaseType.MySQL, "jdbc:mysql://127.0.0.1:3306/db_0") instanceof MySQLDataSourceMetaData);
    }
    
    @Test
    public void assertAllNewInstanceForOracle() {
        assertTrue(DataSourceMetaDataFactory.newInstance(DatabaseType.Oracle, "jdbc:oracle:thin:@//127.0.0.1:3306/ds_0") instanceof OracleDataSourceMetaData);
    }
    
    @Test
    public void assertAllNewInstanceForPostgreSQL() {
        assertTrue(DataSourceMetaDataFactory.newInstance(DatabaseType.PostgreSQL, "jdbc:postgresql://127.0.0.1:3306/ds_0") instanceof PostgreSQLDataSourceMetaData);
    }
    
    @Test
    public void assertAllNewInstanceForSQLServer() {
        assertTrue(DataSourceMetaDataFactory.newInstance(DatabaseType.SQLServer, "jdbc:microsoft:sqlserver://127.0.0.1:3306;DatabaseName=ds_0") instanceof SQLServerDataSourceMetaData);
    }
}

@@ -1165,16 +1165,68 @@
 .Test;%0A%0A
+import static org.hamcrest.CoreMatchers.instanceOf;%0A
 import s
@@ -1255,19 +1255,19 @@
 .assertT
-rue
+hat
 ;%0A%0Apubli
@@ -1374,35 +1374,35 @@
 %0A        assertT
-rue
+hat
 (DataSourceMetaD
@@ -1513,16 +1513,17 @@
 =MySQL%22)
+,
  instanc
@@ -1523,19 +1523,19 @@
 instance
-of 
+Of(
 H2DataSo
@@ -1538,32 +1538,39 @@
 taSourceMetaData
+.class)
 );%0A    %7D%0A    %0A  
@@ -1633,35 +1633,35 @@
 %0A        assertT
-rue
+hat
 (DataSourceMetaD
@@ -1734,24 +1734,25 @@
 :3306/db_0%22)
+,
  instanceof 
@@ -1748,19 +1748,19 @@
 instance
-of 
+Of(
 MySQLDat
@@ -1766,32 +1766,39 @@
 taSourceMetaData
+.class)
 );%0A    %7D%0A    %0A  
@@ -1862,35 +1862,35 @@
 %0A        assertT
-rue
+hat
 (DataSourceMetaD
@@ -1967,32 +1967,33 @@
 .0.1:3306/ds_0%22)
+,
  instanceof Orac
@@ -1985,19 +1985,19 @@
 instance
-of 
+Of(
 OracleDa
@@ -2004,32 +2004,39 @@
 taSourceMetaData
+.class)
 );%0A    %7D%0A    %0A  
@@ -2104,35 +2104,35 @@
 %0A        assertT
-rue
+hat
 (DataSourceMetaD
@@ -2215,24 +2215,25 @@
 :3306/ds_0%22)
+,
  instanceof 
@@ -2229,19 +2229,19 @@
 instance
-of 
+Of(
 PostgreS
@@ -2252,32 +2252,39 @@
 taSourceMetaData
+.class)
 );%0A    %7D%0A    %0A  
@@ -2363,11 +2363,11 @@
 ertT
-rue
+hat
 (Dat
@@ -2487,16 +2487,17 @@
 e=ds_0%22)
+,
  instanc
@@ -2497,19 +2497,19 @@
 instance
-of 
+Of(
 SQLServe
@@ -2527,16 +2527,23 @@
 MetaData
+.class)
 );%0A    %7D

use instanceOf()