Package com.mockrunner.mock.jdbc

Examples of com.mockrunner.mock.jdbc.MockConnection


        batchQuery.setUsingOptimisticLocking(true);
        batchQuery.add(qualifierSnapshot);

        DeleteBatchQueryBuilder batchQueryBuilder = new DeleteBatchQueryBuilder(adapter);

        MockConnection mockConnection = new MockConnection();
        PreparedStatementResultSetHandler preparedStatementResultSetHandler = mockConnection
                .getPreparedStatementResultSetHandler();
        preparedStatementResultSetHandler.setExactMatch(false);
        preparedStatementResultSetHandler.setCaseSensitive(false);
        preparedStatementResultSetHandler.prepareUpdateCount("DELETE", 1);

        boolean generatesKeys = false;

        BatchAction action = new BatchAction(batchQuery, adapter, resolver);
        action.runAsIndividualQueries(
                mockConnection,
                batchQueryBuilder,
                new MockOperationObserver(),
                generatesKeys);
        assertEquals(0, mockConnection.getNumberCommits());
        assertEquals(0, mockConnection.getNumberRollbacks());
    }
View Full Code Here


        batchQuery.setUsingOptimisticLocking(true);
        batchQuery.add(qualifierSnapshot);

        DeleteBatchQueryBuilder batchQueryBuilder = new DeleteBatchQueryBuilder(adapter);

        MockConnection mockConnection = new MockConnection();
        PreparedStatementResultSetHandler preparedStatementResultSetHandler = mockConnection
                .getPreparedStatementResultSetHandler();
        preparedStatementResultSetHandler.setExactMatch(false);
        preparedStatementResultSetHandler.setCaseSensitive(false);
        preparedStatementResultSetHandler.prepareUpdateCount("DELETE", 0);

        boolean generatesKeys = false;
        BatchAction action = new BatchAction(batchQuery, adapter, resolver);
        try {
            action.runAsIndividualQueries(
                    mockConnection,
                    batchQueryBuilder,
                    new MockOperationObserver(),
                    generatesKeys);
            fail("No OptimisticLockingFailureException thrown.");
        }
        catch (OptimisticLockException e) {
        }
        assertEquals(0, mockConnection.getNumberCommits());
        assertEquals(0, mockConnection.getNumberRollbacks());
    }
View Full Code Here

            public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
                return adapter;
            }
        });

        MockConnection connection = new MockConnection();

        MockDataSource dataSource = new MockDataSource();
        dataSource.setupConnection(connection);

        Module testModule = new Module() {
View Full Code Here

    public void testGetAdapter() {
        MockDbAdapter realAdapter = new MockDbAdapter();
        MockDbAdapterFactory factory = new MockDbAdapterFactory(realAdapter);

        MockDataSource dataSource = new MockDataSource();
        dataSource.setupConnection(new MockConnection());
        AutoAdapter adapter = new AutoAdapter(factory, dataSource);

        assertSame(realAdapter, adapter.getAdapter());
    }
View Full Code Here

      // 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);
    }
View Full Code Here

      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);
View Full Code Here

      // assume a real JTA tx would enlist and commit the JDBC connection
      assertNoCommitJdbc();
      assertCommitSession();

      MockConnection mockConnection = (MockConnection) mockDataSource.getConnection();
      assertEquals("should call commit on Connection", 0, mockConnection.getNumberCommits());
      assertEquals("should not call rollback on Connection", 0, mockConnection.getNumberRollbacks());

      assertEquals("should not call DataSource.getConnection()", 0, dataSource.getConnectionCount());

    } finally {
      SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
View Full Code Here

  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;
  }
View Full Code Here

    @Test
    public void scriptRunnerShouldBatchSimpleCommands() throws Exception
    {
        ScriptRunner runner = new ScriptRunner(DatabaseType.UNKNOWN);
        Reader reader = new InputStreamReader(getClass().getResourceAsStream("simple.sql"));
        MockConnection connection = new MockConnection();

        runner.execute(connection, reader);

        List statements = connection.getStatementResultSetHandler().getExecutedStatements();

        assertThat(statements.size(), is(2));
        assertThat(statements.get(0).toString(),
                is(equalToIgnoringWhiteSpace("create table users ( username varchar not null, password varchar not null )")));
        assertThat(statements.get(1).toString(),
View Full Code Here

    @Test
    public void scriptRunnerShouldHandleComplexCommands() throws Exception
    {
        ScriptRunner runner = new ScriptRunner(DatabaseType.MYSQL);
        Reader reader = new InputStreamReader(getClass().getResourceAsStream("complex.sql"));
        MockConnection connection = new MockConnection();

        runner.execute(connection, reader);

        List statements = connection.getStatementResultSetHandler().getExecutedStatements();

        String expectedSql = "update dav_file set parent = ( select id from ( select id from dav_file where name = '__SITE_PROTECTED__' ) as x )" +
                " where ( name = 'templates' and parent is null )" +
                " or ( name = 'velocity' and parent is null )" +
                " or ( name = 'tags' and parent is null )" +
View Full Code Here

TOP

Related Classes of com.mockrunner.mock.jdbc.MockConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.