Package com.mockrunner.mock.jdbc

Examples of com.mockrunner.mock.jdbc.MockConnection


    @Test
    public void scriptRunnerShouldBatchMySQLFunctionsAndProcedures() throws Exception
    {
        ScriptRunner runner = new ScriptRunner(DatabaseType.MYSQL);
        Reader reader = new InputStreamReader(getClass().getResourceAsStream("stored-procedure-mysql.sql"));
        MockConnection connection = new MockConnection();

        runner.execute(connection, reader);

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

        assertThat(statements.size(), is(3));
        assertThat(statements.get(0).toString(),
                is(equalToIgnoringWhiteSpace("CREATE FUNCTION hello (s CHAR(20)) RETURNS CHAR(50) DETERMINISTIC RETURN CONCAT('Hello, ',s,'!')")));
        assertThat(statements.get(1).toString(),
View Full Code Here


    @Test
    public void scriptRunnerShouldBatchPostgresFunctionsAndProcedures() throws Exception
    {
        ScriptRunner runner = new ScriptRunner(DatabaseType.POSTGRESQL);
        Reader reader = new InputStreamReader(getClass().getResourceAsStream("stored-procedure-postgresql.sql"));
        MockConnection connection = new MockConnection();

        runner.execute(connection, reader);

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

        assertThat(statements.size(), is(4));
        assertThat(statements.get(0).toString(),
                is(equalToIgnoringWhiteSpace("CREATE FUNCTION getQtyOrders(customerID int) RETURNS int AS $$ DECLARE qty int; BEGIN SELECT COUNT(*) INTO qty FROM Orders WHERE accnum = customerID; RETURN qty; END; $$ LANGUAGE plpgsql")));
        assertThat(statements.get(1).toString(),
View Full Code Here

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

        runner.execute(connection, reader);

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

        assertThat(statements.size(), is(3));
        assertThat(statements.get(0).toString(),
                is(equalToIgnoringWhiteSpace("DROP FUNCTION IF EXISTS simpleFunction")));
        assertThat(statements.get(1).toString(),
View Full Code Here

    @Test
    public void scriptRunnerShouldExecuteLastStatementWhenDelimiterIsMissing() throws Exception
    {
        ScriptRunner runner = new ScriptRunner(DatabaseType.UNKNOWN);
        Reader reader = new InputStreamReader(getClass().getResourceAsStream("missing-last-deliminator.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

            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

        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 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

        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

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.