本文整理汇总了Java中com.mockrunner.mock.jdbc.MockConnection类的典型用法代码示例。如果您正苦于以下问题:Java MockConnection类的具体用法?Java MockConnection怎么用?Java MockConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockConnection类属于com.mockrunner.mock.jdbc包,在下文中一共展示了MockConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:19,代码来源:PhoenixInterpreterTest.java
示例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);
}
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:19,代码来源:PostgreSqlInterpreterTest.java
示例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");
}
}
开发者ID:GitHubRGI,项目名称:swagd,代码行数:23,代码来源:JdbcUtilityTest.java
示例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");
}
开发者ID:GitHubRGI,项目名称:swagd,代码行数:23,代码来源:JdbcUtilityTest.java
示例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");
}
开发者ID:GitHubRGI,项目名称:swagd,代码行数:24,代码来源:JdbcUtilityTest.java
示例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");
}
开发者ID:GitHubRGI,项目名称:swagd,代码行数:24,代码来源:JdbcUtilityTest.java
示例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);
}
}
}
}
开发者ID:GitHubRGI,项目名称:swagd,代码行数:24,代码来源:JdbcUtilityTest.java
示例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");
}
开发者ID:GitHubRGI,项目名称:swagd,代码行数:21,代码来源:JdbcUtilityTest.java
示例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"));
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:SqlScriptMigrationTaskTest.java
示例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);
}
}
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:38,代码来源:MyBatisSpringTest.java
示例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());
}
}
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:10,代码来源:AbstractMyBatisSpringTest.java
示例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;
}
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:11,代码来源:AbstractMyBatisSpringTest.java
示例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);
}
}
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:36,代码来源:MapperFactoryBeanTest.java
示例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);
}
开发者ID:nortal,项目名称:petit,代码行数:10,代码来源:GeneratedKeysTest.java
示例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);
}
开发者ID:nortal,项目名称:petit,代码行数:10,代码来源:GeneratedKeysTest.java
示例16: prepareResultsetReturningString
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
private void prepareResultsetReturningString() {
MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
PreparedStatementResultSetHandler statementHandler = connection.getPreparedStatementResultSetHandler();
MockResultSet keysResult = statementHandler.createResultSet();
keysResult.addColumn("kood");
keysResult.addRow(new Object[] {"1234"});
statementHandler.prepareGeneratedKeys("insert", keysResult);
}
开发者ID:nortal,项目名称:petit,代码行数:10,代码来源:GeneratedKeysTest.java
示例17: prepareResultsetReturningMultipleKeys
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
private void prepareResultsetReturningMultipleKeys() {
MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
PreparedStatementResultSetHandler statementHandler = connection.getPreparedStatementResultSetHandler();
MockResultSet keysResult = statementHandler.createResultSet();
keysResult.addColumn("id");
keysResult.addRow(new Object[] {BigDecimal.valueOf(11L)});
keysResult.addRow(new Object[] {BigDecimal.valueOf(12L)});
keysResult.addRow(new Object[] {BigDecimal.valueOf(13L)});
statementHandler.prepareGeneratedKeys("insert", keysResult);
}
开发者ID:nortal,项目名称:petit,代码行数:12,代码来源:InsertStatementInterceptorTest.java
示例18: prepareResultSet
import com.mockrunner.mock.jdbc.MockConnection; //导入依赖的package包/类
private void prepareResultSet()
{
MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
PreparedStatementResultSetHandler statementHandler = connection.getPreparedStatementResultSetHandler();
MockResultSet result = statementHandler.createResultSet();
result.addColumn("id");
result.addColumn("description");
result.addColumn("optional");
result.addRow(new Object[] { 1L, "Bean description", "Optional result" });
statementHandler.prepareResultSet("select", result, new Object[] { 1L });
}
开发者ID:nortal,项目名称:petit,代码行数:12,代码来源:BeanMapperTest.java
示例19: 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);
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);
}
}
开发者ID:zyong2004,项目名称:mybatis-spring,代码行数:38,代码来源:MyBatisSpringTest.java
示例20: 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);
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);
}
}
开发者ID:zyong2004,项目名称:mybatis-spring,代码行数:36,代码来源:MapperFactoryBeanTest.java
注:本文中的com.mockrunner.mock.jdbc.MockConnection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论