本文整理汇总了Java中com.mockrunner.mock.jdbc.MockConnection类的典型用法代码示例。如果您正苦于以下问题:Java MockConnection类的具体用法?Java MockConnection怎么用?Java MockConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockConnection类属于com.mockrunner.mock.jdbc包,在下文中一共展示了MockConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeTest
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
@Before
public void beforeTest() {
MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
StatementResultSetHandler statementHandler = connection.getStatementResultSetHandler();
result = statementHandler.createResultSet();
statementHandler.prepareGlobalResultSet(result);
Properties properties = new Properties();
properties.put(PHOENIX_JDBC_DRIVER_NAME, DEFAULT_JDBC_DRIVER_NAME);
properties.put(PHOENIX_JDBC_URL, DEFAULT_JDBC_URL);
properties.put(PHOENIX_JDBC_USER, DEFAULT_JDBC_USER);
properties.put(PHOENIX_JDBC_PASSWORD, DEFAULT_JDBC_PASSWORD);
properties.put(PHOENIX_MAX_RESULT, DEFAULT_MAX_RESULT);
phoenixInterpreter = spy(new PhoenixInterpreter(properties));
when(phoenixInterpreter.getJdbcConnection()).thenReturn(connection);
}
示例2: beforeTest
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
@Before
public void beforeTest() {
MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
StatementResultSetHandler statementHandler = connection.getStatementResultSetHandler();
result = statementHandler.createResultSet();
statementHandler.prepareGlobalResultSet(result);
Properties properties = new Properties();
properties.put(POSTGRESQL_SERVER_DRIVER_NAME, DEFAULT_JDBC_DRIVER_NAME);
properties.put(POSTGRESQL_SERVER_URL, DEFAULT_JDBC_URL);
properties.put(POSTGRESQL_SERVER_USER, DEFAULT_JDBC_USER_NAME);
properties.put(POSTGRESQL_SERVER_PASSWORD, DEFAULT_JDBC_USER_PASSWORD);
properties.put(POSTGRESQL_SERVER_MAX_RESULT, DEFAULT_MAX_RESULT);
psqlInterpreter = spy(new PostgreSqlInterpreter(properties));
when(psqlInterpreter.getJdbcConnection()).thenReturn(connection);
}
示例3: map2ResultSetFunctionNullTest
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
/**
* Tests if an IllegalArgumentException is thrown
* when the ResultSetFunction is null
*/
@Test(expected = IllegalArgumentException.class)
public void map2ResultSetFunctionNullTest() throws SQLException
{
try(final Connection connection = new MockConnection())
{
try(final Statement statement = connection.createStatement())
{
try(final ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM sqlite_master;"))
{
JdbcUtility.map(resultSet,
null,
HashSet<String>::new);
}
}
fail("map should have thrown an IllegalArgumentException for a null resultSetFunction");
}
}
示例4: map2NullCollectionFactoryTest
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
/**
* Tests if an IllegalArgumentException is thrown
* when the CollectionFactory is null
*/
@Test(expected = IllegalArgumentException.class)
public void map2NullCollectionFactoryTest() throws SQLException
{
try(final Connection connection = new MockConnection())
{
try(final Statement statement = connection.createStatement())
{
try(final ResultSet results = statement.executeQuery("SELECT COUNT(*) FROM sqlite_master;"))
{
JdbcUtility.map(results,
resultSet -> "",
null);
}
}
}
fail("map should have thrown an IllegalArgumentException for a null collectionFactory");
}
示例5: mapFilterResultSetTest
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
/**
* Tests if an IllegalArgumentException is thrown
* when ResultSetFunction is null
*/
@Test(expected = IllegalArgumentException.class)
public void mapFilterResultSetTest() throws SQLException
{
try(final Connection connection = new MockConnection())
{
try(final Statement statement = connection.createStatement())
{
try(final ResultSet results = statement.executeQuery("SELECT COUNT(*) FROM sqlite_master;"))
{
JdbcUtility.mapFilter(results,
null,
pyramidName -> true,
HashSet<String>::new);
}
}
}
fail("mapFilter should have thrown an IllegalArgumentException for a null funciton");
}
示例6: mapFilterNullpredicateTest
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
/**
* Tests if an IllegalArgumentException is thrown
* when JdbcPredicate is null
*/
@Test(expected = IllegalArgumentException.class)
public void mapFilterNullpredicateTest() throws SQLException
{
try(final Connection connection = new MockConnection())
{
try(final Statement statement = connection.createStatement())
{
try(ResultSet results = statement.executeQuery("SELECT COUNT(*) FROM sqlite_master;"))
{
JdbcUtility.mapFilter(results,
resultSet -> "",
null,
HashSet<String>::new);
}
}
}
fail("mapFilter should have thrown an IllegalArgumentException for a null predicate");
}
示例7: mapFilterFunctionTest
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
/**
* Tests if an the function returns a collection after
* executing with a proper string
*/
@Test(expected = IllegalArgumentException.class)
public void mapFilterFunctionTest() throws SQLException
{
try(final Connection connection = new MockConnection())
{
try(final Statement statement = connection.createStatement())
{
try(final ResultSet results = statement.executeQuery("SELECT COUNT(*) FROM sqlite_master;"))
{
final Collection<String> collection = JdbcUtility.mapFilter(results,
resultSet -> "",
pyramidName -> true,
HashSet<String>::new);
assertNotNull("mapFilter should have a set", collection);
}
}
}
}
示例8: getObjectsEndLessThanStartTest
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
/**
* Tests if an IllegalArgumentException is thrown
* when startColumnIndex is greater than EndColumnIndex
*/
@Test(expected = IllegalArgumentException.class)
public void getObjectsEndLessThanStartTest() throws SQLException
{
try(final Connection connection = new MockConnection())
{
try(final Statement statement = connection.createStatement())
{
try(final ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM sqlite_master;"))
{
JdbcUtility.getObjects(resultSet, 3, 1);
}
}
}
fail("getObjects should have thrown an IllegalArgumentException where endColumn is greater than startIndex");
}
示例9: setUp
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
protected void setUp() throws Exception
{
super.setUp();
MockConnection conn = getJDBCMockObjectFactory().getMockConnection();
context = new DataSourceMigrationContext();
context.setDataSource(new ConnectionWrapperDataSource(conn));
context.setSystemName("milestone");
context.setDatabaseType(new DatabaseType("postgres"));
}
示例10: testNonSpringTxFactoryNonSpringDSWithTx
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
@Test
public void testNonSpringTxFactoryNonSpringDSWithTx() throws java.sql.SQLException {
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
MockDataSource mockDataSource = new MockDataSource();
mockDataSource.setupConnection(createMockConnection());
Environment nonSpring = new Environment("non-spring", new JdbcTransactionFactory(), mockDataSource,null);
sqlSessionFactory.getConfiguration().setEnvironment(nonSpring);
TransactionStatus status = null;
try {
status = txManager.getTransaction(new DefaultTransactionDefinition());
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.commit();
session.close();
txManager.commit(status);
// txManager still uses original connection
assertCommit();
assertSingleConnection();
// SqlSession uses its own connection
// that connection will not have commited since no SQL was executed by the session
MockConnection mockConnection = (MockConnection) mockDataSource.getConnection();
assertEquals("should call commit on Connection", 0, mockConnection.getNumberCommits());
assertEquals("should not call rollback on Connection", 0, mockConnection.getNumberRollbacks());
assertCommitSession();
} finally {
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
sqlSessionFactory.getConfiguration().setEnvironment(original);
}
}
示例11: assertConnectionClosed
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
protected void assertConnectionClosed(MockConnection connection) {
try {
if ((connection != null) && !connection.isClosed()) {
fail("Connection is not closed");
}
} catch (SQLException sqle) {
fail("cannot call Connection.isClosed() " + sqle.getMessage());
}
}
示例12: createMockConnection
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
protected MockConnection createMockConnection() {
// this query must be the same as the query in TestMapper.xml
MockResultSet rs = new MockResultSet("SELECT 1");
rs.addRow(new Object[] { 1 });
MockConnection con = new MockConnection();
con.getPreparedStatementResultSetHandler().prepareResultSet("SELECT 1", rs);
return con;
}
示例13: testNonSpringWithTx
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
@Test
public void testNonSpringWithTx() throws Exception {
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
MockDataSource mockDataSource = new MockDataSource();
mockDataSource.setupConnection(createMockConnection());
Environment nonSpring = new Environment("non-spring", new JdbcTransactionFactory(), mockDataSource,null);
sqlSessionFactory.getConfiguration().setEnvironment(nonSpring);
SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
TransactionStatus status = null;
try {
status = txManager.getTransaction(new DefaultTransactionDefinition());
find(sqlSessionTemplate);
txManager.commit(status);
// txManager still uses original connection
assertCommit();
assertSingleConnection();
// SqlSessionTemplate uses its own connection
MockConnection mockConnection = (MockConnection) mockDataSource.getConnection();
assertEquals("should call commit on Connection", 1, mockConnection.getNumberCommits());
assertEquals("should not call rollback on Connection", 0, mockConnection.getNumberRollbacks());
assertCommitSession();
} finally {
sqlSessionFactory.getConfiguration().setEnvironment(original);
}
}
示例14: prepareResultsetReturningLong
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
private void prepareResultsetReturningLong() {
MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
PreparedStatementResultSetHandler statementHandler = connection.getPreparedStatementResultSetHandler();
MockResultSet keysResult = statementHandler.createResultSet();
keysResult.addColumn("id");
keysResult.addRow(new Object[] {Long.valueOf(11L)});
statementHandler.prepareGeneratedKeys("insert", keysResult);
}
示例15: prepareResultsetReturningBigDecimal
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
private void prepareResultsetReturningBigDecimal() {
MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
PreparedStatementResultSetHandler statementHandler = connection.getPreparedStatementResultSetHandler();
MockResultSet keysResult = statementHandler.createResultSet();
keysResult.addColumn("id");
keysResult.addRow(new Object[] {BigDecimal.valueOf(11L)});
statementHandler.prepareGeneratedKeys("insert", keysResult);
}