Skip to content

Commit

Permalink
Simplify UnsupportedOperationStatementTest (apache#9159)
Browse files Browse the repository at this point in the history
* Simplify UnsupportedOperationStatementTest

* Simplify UnsupportedOperationPreparedStatementTest
  • Loading branch information
terrymanu authored Jan 25, 2021
1 parent cdcc73b commit 7f9d4e6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,113 +17,79 @@

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.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.junit.Before;
import org.junit.Test;

import java.io.StringReader;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ArrayList;
import java.util.List;

public final class UnsupportedOperationPreparedStatementTest 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<>();
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public final class UnsupportedOperationPreparedStatementTest {

private final List<PreparedStatement> statements = new ArrayList<>();
private ShardingSpherePreparedStatement shardingSpherePreparedStatement;

@Before
public void init() throws SQLException {
ShardingSphereConnection connection = getShardingSphereDataSource().getConnection();
shardingSphereConnections.add(connection);
PreparedStatement preparedStatement = connection.prepareStatement(SQL);
statements.add(preparedStatement);
}

@After
public void close() throws SQLException {
for (PreparedStatement each : statements) {
each.close();
}
for (ShardingSphereConnection each : shardingSphereConnections) {
each.close();
}
public void setUp() throws SQLException {
ShardingSphereConnection connection = mock(ShardingSphereConnection.class, RETURNS_DEEP_STUBS);
when(connection.getMetaDataContexts().getDefaultMetaData().getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
shardingSpherePreparedStatement = new ShardingSpherePreparedStatement(connection, "SELECT 1");
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertGetMetaData() throws SQLException {
for (PreparedStatement each : statements) {
each.getMetaData();
}
shardingSpherePreparedStatement.getMetaData();
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetNString() throws SQLException {
for (PreparedStatement each : statements) {
each.setNString(1, "");
}
shardingSpherePreparedStatement.setNString(1, "");
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetNClob() throws SQLException {
for (PreparedStatement each : statements) {
each.setNClob(1, (NClob) null);
}
shardingSpherePreparedStatement.setNClob(1, (NClob) null);
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetNClobForReader() throws SQLException {
for (PreparedStatement each : statements) {
each.setNClob(1, new StringReader(""));
}
shardingSpherePreparedStatement.setNClob(1, new StringReader(""));
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetNClobForReaderAndLength() throws SQLException {
for (PreparedStatement each : statements) {
each.setNClob(1, new StringReader(""), 1);
}
shardingSpherePreparedStatement.setNClob(1, new StringReader(""), 1);
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetNCharacterStream() throws SQLException {
for (PreparedStatement each : statements) {
each.setNCharacterStream(1, new StringReader(""));
}
shardingSpherePreparedStatement.setNCharacterStream(1, new StringReader(""));
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetNCharacterStreamWithLength() throws SQLException {
for (PreparedStatement each : statements) {
each.setNCharacterStream(1, new StringReader(""), 1);
}
shardingSpherePreparedStatement.setNCharacterStream(1, new StringReader(""), 1);
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetArray() throws SQLException {
for (PreparedStatement each : statements) {
each.setArray(1, null);
}
shardingSpherePreparedStatement.setArray(1, null);
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetRowId() throws SQLException {
for (PreparedStatement each : statements) {
each.setRowId(1, null);
}
shardingSpherePreparedStatement.setRowId(1, null);
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetRef() throws SQLException {
for (PreparedStatement each : statements) {
each.setRef(1, null);
}
shardingSpherePreparedStatement.setRef(1, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,80 +17,47 @@

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.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement;
import org.junit.Test;

import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public final class UnsupportedOperationStatementTest extends AbstractShardingSphereDataSourceForShardingTest {

private final List<ShardingSphereConnection> shardingSphereConnections = new ArrayList<>();

private final List<Statement> statements = new ArrayList<>();
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

public final class UnsupportedOperationStatementTest {

@Before
public void init() {
ShardingSphereConnection connection = getShardingSphereDataSource().getConnection();
shardingSphereConnections.add(connection);
statements.add(connection.createStatement());
}
private final ShardingSphereStatement shardingSphereStatement = new ShardingSphereStatement(mock(ShardingSphereConnection.class, RETURNS_DEEP_STUBS));

@After
public void close() throws SQLException {
for (Statement each : statements) {
each.close();
}
for (ShardingSphereConnection each : shardingSphereConnections) {
each.close();
}
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertAddBatch() throws SQLException {
for (Statement each : statements) {
each.addBatch("");
}
shardingSphereStatement.addBatch("");
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertClearBatch() throws SQLException {
for (Statement each : statements) {
each.clearBatch();
}
shardingSphereStatement.clearBatch();
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertExecuteBatch() throws SQLException {
for (Statement each : statements) {
each.executeBatch();
}
shardingSphereStatement.executeBatch();
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertCloseOnCompletion() throws SQLException {
for (Statement each : statements) {
each.closeOnCompletion();
}
shardingSphereStatement.closeOnCompletion();
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertIsCloseOnCompletion() throws SQLException {
for (Statement each : statements) {
each.isCloseOnCompletion();
}
shardingSphereStatement.isCloseOnCompletion();
}

@Test(expected = SQLFeatureNotSupportedException.class)
public void assertSetCursorName() throws SQLException {
for (Statement each : statements) {
each.setCursorName("cursorName");
}
shardingSphereStatement.setCursorName("cursorName");
}
}

0 comments on commit 7f9d4e6

Please sign in to comment.