/*
 * 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.driver.jdbc.unsupported;

import org.apache.shardingsphere.driver.jdbc.base.AbstractShardingSphereDataSourceForShardingTest;
import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ArrayList;
import java.util.List;

public final class UnsupportedOperationParameterMetaTest extends AbstractShardingSphereDataSourceForShardingTest {
    
    private static final String SQL = "SELECT user_id AS usr_id FROM t_order WHERE status = 'init'";
    
    private final List<ShardingSphereConnection> shardingSphereConnections = new ArrayList<>();
    
    private final List<ParameterMetaData> parameterMetaData = new ArrayList<>();
    
    @Before
    public void init() throws SQLException {
        ShardingSphereConnection connection = getShardingSphereDataSource().getConnection();
        shardingSphereConnections.add(connection);
        PreparedStatement preparedStatement = connection.prepareStatement(SQL);
        parameterMetaData.add(preparedStatement.getParameterMetaData());
    }
    
    @After
    public void close() throws SQLException {
        for (ShardingSphereConnection each : shardingSphereConnections) {
            each.close();
        }
    }
    
    @Test(expected = SQLFeatureNotSupportedException.class)
    public void assertIsNullable() throws SQLException {
        for (ParameterMetaData each : parameterMetaData) {
            each.getParameterClassName(1);
        }
    }
    
    @Test(expected = SQLFeatureNotSupportedException.class)
    public void assertIsSigned() throws SQLException {
        for (ParameterMetaData each : parameterMetaData) {
            each.isSigned(1);
        }
    }
    
    @Test(expected = SQLFeatureNotSupportedException.class)
    public void assertGetPrecision() throws SQLException {
        for (ParameterMetaData each : parameterMetaData) {
            each.getPrecision(1);
        }
    }
    
    @Test(expected = SQLFeatureNotSupportedException.class)
    public void assertGetScale() throws SQLException {
        for (ParameterMetaData each : parameterMetaData) {
            each.getScale(1);
        }
    }
    
    @Test(expected = SQLFeatureNotSupportedException.class)
    public void assertGetParameterType() throws SQLException {
        for (ParameterMetaData each : parameterMetaData) {
            each.getParameterType(1);
        }
    }
    
    @Test(expected = SQLFeatureNotSupportedException.class)
    public void assertGetParameterTypeName() throws SQLException {
        for (ParameterMetaData each : parameterMetaData) {
            each.getParameterTypeName(1);
        }
    }
    
    @Test(expected = SQLFeatureNotSupportedException.class)
    public void assertGetParameterClassName() throws SQLException {
        for (ParameterMetaData each : parameterMetaData) {
            each.getParameterClassName(1);
        }
    }
    
    @Test(expected = SQLFeatureNotSupportedException.class)
    public void assertGetParameterMode() throws SQLException {
        for (ParameterMetaData each : parameterMetaData) {
            each.getParameterMode(1);
        }
    }
}

@@ -905,291 +905,167 @@
 dbc.
-base.AbstractShardingSphereDataSourceForShardingTest;%0Aimport org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.sql.ParameterMetaData;%0Aimport java.sql.PreparedStatement;
+core.statement.metadata.ShardingSphereParameterMetaData;%0Aimport org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;%0Aimport org.junit.Test;%0A
 %0Aimp
@@ -1144,57 +1144,47 @@
 on;%0A
+%0A
 import 
-java.util.ArrayList;%0Aimport java.util.List
+static org.mockito.Mockito.mock
 ;%0A%0Ap
@@ -1243,901 +1243,161 @@
 est 
-extends AbstractShardingSphereDataSourceForShardingTest %7B%0A    %0A    private static final String SQL = %22SELECT user_id AS usr_id FROM t_order WHERE status = 'init'%22;%0A    %0A    private final List%3CShardingSphereConnection%3E shardingSphereConnections = new ArrayList%3C%3E();%0A    %0A    private final List%3CParameterMetaData%3E parameterMetaData = new ArrayList%3C%3E();%0A    %0A    @Before%0A    public void init() throws SQLException %7B%0A        ShardingSphereConnection connection = getShardingSphereDataSource().getConnection();%0A        shardingSphereConnections.add(connection);%0A        PreparedStatement preparedStatement = connection.prepareStatement(SQL);%0A        parameterMetaData.add(preparedStatement.getParameterMetaData());%0A    %7D%0A    %0A    @After%0A    public void close() throws SQLException %7B%0A        for (ShardingSphereConnection each : shardingSphereConnections) %7B%0A            each.close();%0A        %7D%0A    %7D
+%7B%0A    %0A    private final ShardingSphereParameterMetaData shardingSphereParameterMetaData = new ShardingSphereParameterMetaData(mock(SQLStatement.class));
 %0A   
@@ -1527,75 +1527,39 @@
     
-for (ParameterMetaData each : parameterMetaData) %7B%0A            each
+shardingSphereParameterMetaData
 .get
@@ -1577,34 +1577,24 @@
 assName(1);%0A
-        %7D%0A
     %7D%0A    %0A 
@@ -1719,75 +1719,39 @@
     
-for (ParameterMetaData each : parameterMetaData) %7B%0A            each
+shardingSphereParameterMetaData
 .isS
@@ -1756,34 +1756,24 @@
 sSigned(1);%0A
-        %7D%0A
     %7D%0A    %0A 
@@ -1902,75 +1902,39 @@
     
-for (ParameterMetaData each : parameterMetaData) %7B%0A            each
+shardingSphereParameterMetaData
 .get
@@ -1943,34 +1943,24 @@
 ecision(1);%0A
-        %7D%0A
     %7D%0A    %0A 
@@ -2085,75 +2085,39 @@
     
-for (ParameterMetaData each : parameterMetaData) %7B%0A            each
+shardingSphereParameterMetaData
 .get
@@ -2122,34 +2122,24 @@
 etScale(1);%0A
-        %7D%0A
     %7D%0A    %0A 
@@ -2272,75 +2272,39 @@
     
-for (ParameterMetaData each : parameterMetaData) %7B%0A            each
+shardingSphereParameterMetaData
 .get
@@ -2317,34 +2317,24 @@
 terType(1);%0A
-        %7D%0A
     %7D%0A    %0A 
@@ -2471,75 +2471,39 @@
     
-for (ParameterMetaData each : parameterMetaData) %7B%0A            each
+shardingSphereParameterMetaData
 .get
@@ -2520,34 +2520,24 @@
 ypeName(1);%0A
-        %7D%0A
     %7D%0A    %0A 
@@ -2675,75 +2675,39 @@
     
-for (ParameterMetaData each : parameterMetaData) %7B%0A            each
+shardingSphereParameterMetaData
 .get
@@ -2725,34 +2725,24 @@
 assName(1);%0A
-        %7D%0A
     %7D%0A    %0A 
@@ -2875,75 +2875,39 @@
     
-for (ParameterMetaData each : parameterMetaData) %7B%0A            each
+shardingSphereParameterMetaData
 .get
@@ -2928,18 +2928,8 @@
 1);%0A
-        %7D%0A
     

Simplify UnsupportedOperationParameterMetaTest (#9162)