Search in sources :

Example 41 with CleanDatabaseTestSetup

use of org.apache.derbyTesting.junit.CleanDatabaseTestSetup in project derby by apache.

the class ImportExportBinaryDataTest method suite.

/**
 * Runs the tests in the default embedded configuration and then
 * the client server configuration.
 */
public static Test suite() {
    BaseTestSuite suite = new BaseTestSuite(ImportExportBinaryDataTest.class);
    suite.addTest(TestConfiguration.clientServerSuite(ImportExportBinaryDataTest.class));
    Test test = suite;
    test = new SupportFilesSetup(test);
    return new CleanDatabaseTestSetup(test) {

        protected void decorateSQL(Statement s) throws SQLException {
            // table used to test  export.
            s.execute("CREATE TABLE BIN_TAB (id int," + "C_BD CHAR(4) FOR BIT DATA," + "C_VBD VARCHAR(10) FOR BIT DATA, " + "C_LVBD LONG VARCHAR FOR BIT DATA)");
            // load some data into the above table.
            loadData(s);
            // table used to test import.
            s.execute("CREATE TABLE BIN_TAB_IMP(id int," + "C_BD CHAR(4) FOR BIT DATA," + "C_VBD VARCHAR(10) FOR BIT DATA, " + "C_LVBD LONG VARCHAR FOR BIT DATA)");
            // Create a table that holds some invalid hex strings.
            s.execute("CREATE TABLE hex_tab(id int," + "C1 varchar(20)," + "C2 varchar(20)," + "C3 varchar(20))");
            // Create a table to test
            // DERBY-2925: Prevent export from overwriting existing files
            s.execute("create table derby_2925_tab(a varchar( 50 )," + "b varchar( 50 ))");
        }
    };
}
Also used : Test(junit.framework.Test) CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) Statement(java.sql.Statement) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) SupportFilesSetup(org.apache.derbyTesting.junit.SupportFilesSetup)

Example 42 with CleanDatabaseTestSetup

use of org.apache.derbyTesting.junit.CleanDatabaseTestSetup in project derby by apache.

the class st_derby1939 method suite.

public static Test suite() {
    Properties sysprops = new Properties();
    sysprops.setProperty("derby.language.maxMemoryPerTable", "140");
    sysprops.setProperty("derby.optimizer.noTimeout", "true");
    return new SystemPropertyTestSetup(new CleanDatabaseTestSetup(TestConfiguration.embeddedSuite(st_derby1939.class)), sysprops, true);
}
Also used : CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) SystemPropertyTestSetup(org.apache.derbyTesting.junit.SystemPropertyTestSetup) Properties(java.util.Properties)

Example 43 with CleanDatabaseTestSetup

use of org.apache.derbyTesting.junit.CleanDatabaseTestSetup in project derby by apache.

the class st_derby715 method suite.

public static Test suite() {
    Test test = TestConfiguration.embeddedSuite(st_derby715.class);
    test = DatabasePropertyTestSetup.setLockTimeouts(test, 1, 60);
    test = new CleanDatabaseTestSetup(test);
    return test;
}
Also used : Test(junit.framework.Test) CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup)

Example 44 with CleanDatabaseTestSetup

use of org.apache.derbyTesting.junit.CleanDatabaseTestSetup in project derby by apache.

the class CacheSessionDataTest method baseSuite.

/**
 * Creates a new BaseTestSuite with all the tests, and wraps it in a
 * CleanDatabaseSetup with a custom decorator.
 * @param name BaseTestSuite name
 * @return wrapped TestSuite
 */
private static Test baseSuite(String name) {
    BaseTestSuite suite = new BaseTestSuite(name);
    suite.addTestSuite(CacheSessionDataTest.class);
    return new CleanDatabaseTestSetup(suite) {

        /**
         * Creates the tables, stored procedures, and functions
         * shared by all test cases.
         * @throws SQLException
         */
        protected void decorateSQL(Statement s) throws SQLException {
            s.execute("CREATE TABLE ISOLATION_NAMES(ISOLEVEL INT, JDBCNAME " + "VARCHAR(30), SQLNAME VARCHAR(2))");
            PreparedStatement insert = s.getConnection().prepareStatement("INSERT INTO ISOLATION_NAMES VALUES (?, ?, ?)");
            insert.setInt(1, Connection.TRANSACTION_NONE);
            insert.setString(2, "TRANSACTION_NONE");
            insert.setNull(3, Types.VARCHAR);
            insert.execute();
            insert.setInt(1, Connection.TRANSACTION_READ_UNCOMMITTED);
            insert.setString(2, "TRANSACTION_READ_UNCOMMITTED");
            insert.setString(3, "UR");
            insert.execute();
            insert.setInt(1, Connection.TRANSACTION_READ_COMMITTED);
            insert.setString(2, "TRANSACTION_READ_COMMITTED");
            insert.setString(3, "CS");
            insert.execute();
            insert.setInt(1, Connection.TRANSACTION_REPEATABLE_READ);
            insert.setString(2, "TRANSACTION_REPEATABLE_READ");
            insert.setString(3, "RS");
            insert.execute();
            insert.setInt(1, Connection.TRANSACTION_SERIALIZABLE);
            insert.setString(2, "TRANSACTION_SERIALIZABLE");
            insert.setString(3, "RR");
            insert.execute();
            insert.close();
            s.execute("CREATE TABLE BIG(C1 VARCHAR(32672), " + "C2 VARCHAR(32672), C3 VARCHAR(32672), C4 VARCHAR(32672))");
            s.execute("CREATE PROCEDURE INSERTDATA1(IN A INT) LANGUAGE JAVA " + "PARAMETER STYLE JAVA EXTERNAL NAME " + "'org.apache.derbyTesting.functionTests.util." + "ProcedureTest.bigTestData'");
            CallableStatement cs = s.getConnection().prepareCall("CALL INSERTDATA1(?)");
            cs.setInt(1, 9);
            for (int i = 0; i < 10; ++i) {
                cs.execute();
            }
            ResultSet x = s.executeQuery("SELECT COUNT(*) FROM BIG");
            x.next();
            println("BIG has " + x.getInt(1) + " rows");
            // Create procedures
            s.execute("CREATE PROCEDURE SET_ISOLATION_JDBC" + " (ISO INT) NO SQL LANGUAGE JAVA PARAMETER STYLE " + "JAVA EXTERNAL NAME '" + CacheSessionDataTest.class.getName() + ".setIsolationJDBC'");
            s.execute("CREATE PROCEDURE SET_ISOLATION_SQL " + "(SQLNAME VARCHAR(2)) MODIFIES SQL DATA LANGUAGE JAVA PARAMETER STYLE " + "JAVA EXTERNAL NAME '" + CacheSessionDataTest.class.getName() + ".setIsolationSQL'");
            // Create functions
            s.execute("CREATE FUNCTION GET_TRANSACTION_ISOLATION_JDBC " + "() RETURNS INT NO SQL LANGUAGE JAVA " + "PARAMETER STYLE JAVA EXTERNAL NAME '" + CacheSessionDataTest.class.getName() + ".getTransactionIsolationJDBC'");
            s.execute("CREATE FUNCTION GET_CYCLE_ISOLATION_JDBC " + "() RETURNS INT NO SQL LANGUAGE JAVA " + "PARAMETER STYLE JAVA EXTERNAL NAME '" + CacheSessionDataTest.class.getName() + ".getCycleIsolationJDBC'");
            s.execute("CREATE FUNCTION GET_CYCLE_ISOLATION_SQL " + "() RETURNS VARCHAR(2) READS SQL DATA LANGUAGE JAVA " + "PARAMETER STYLE JAVA EXTERNAL NAME '" + CacheSessionDataTest.class.getName() + ".getCycleIsolationSQL'");
            // Schema testing
            s.execute("CREATE SCHEMA FOO");
            String unicodeschema = "\u00bbMY\u20ac\u00ab";
            s.execute("CREATE SCHEMA \"" + unicodeschema + "\"");
            s.execute("CREATE PROCEDURE APP.SET_SCHEMA (SCHEMANAME " + "VARCHAR(128)) MODIFIES SQL DATA LANGUAGE JAVA " + "PARAMETER STYLE JAVA EXTERNAL NAME '" + CacheSessionDataTest.class.getName() + ".setSchema'");
            s.execute("CREATE FUNCTION APP.GET_SCHEMA_TRANSITION " + "(SCHEMANAME VARCHAR(128)) RETURNS VARCHAR(128) READS " + "SQL DATA LANGUAGE JAVA PARAMETER STYLE JAVA EXTERNAL " + "NAME '" + CacheSessionDataTest.class.getName() + ".getSchemaTransition'");
            s.execute("CREATE TABLE APP.LARGE(X VARCHAR(32000), " + "SCHEMANAME VARCHAR(128), Y VARCHAR(32000))");
            char[] carray = new char[32000];
            Arrays.fill(carray, 'x');
            String xs = new String(carray);
            Arrays.fill(carray, 'y');
            String ys = new String(carray);
            s.execute("INSERT INTO APP.LARGE (SELECT '" + xs + "', " + "SCHEMANAME, " + " '" + ys + "' FROM SYS.SYSSCHEMAS)");
        }
    };
}
Also used : CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) PreparedStatement(java.sql.PreparedStatement)

Example 45 with CleanDatabaseTestSetup

use of org.apache.derbyTesting.junit.CleanDatabaseTestSetup in project derby by apache.

the class CallableTest method baseSuite.

private static Test baseSuite(String name) {
    BaseTestSuite suite = new BaseTestSuite(name);
    // Add tests that every JVM should be able to run.
    suite.addTestSuite(CallableTest.class);
    // Add tests that require JDBC 3
    if (JDBC.vmSupportsJDBC3()) {
        // Tests that require DriverManager.
        suite.addTest(new CallableTest("xtestUpdateLongBinaryProc"));
        // Tests that require DriverManager and batch update.
        suite.addTest(new CallableTest("xtestBatchUpdate"));
        suite.addTest(new CallableTest("xtestBatchUpdateError"));
        // Tests that get/set BigDecimal
        suite.addTest(new CallableTest("xtestBigDecimalInAndOutProc"));
        suite.addTest(new CallableTest("xtestNumericTypesInAndOutProc"));
        // Test that both requires DriverManager and BigDecimal
        suite.addTest(new CallableTest("xtestNumericBoundariesProc"));
    }
    return new CleanDatabaseTestSetup(suite) {

        /**
         * Creates the tables and the stored procedures used in the test
         * cases.
         * @throws SQLException
         */
        protected void decorateSQL(Statement s) throws SQLException {
            for (int i = 0; i < ROUTINES.length; i++) {
                s.execute(ROUTINES[i]);
            }
            for (int i = 0; i < TABLES.length; i++) {
                s.execute(TABLES[i][1]);
            }
        }
    };
}
Also used : CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite)

Aggregations

CleanDatabaseTestSetup (org.apache.derbyTesting.junit.CleanDatabaseTestSetup)147 BaseTestSuite (org.apache.derbyTesting.junit.BaseTestSuite)118 Statement (java.sql.Statement)95 PreparedStatement (java.sql.PreparedStatement)77 Test (junit.framework.Test)77 Properties (java.util.Properties)25 CallableStatement (java.sql.CallableStatement)21 Connection (java.sql.Connection)20 SystemPropertyTestSetup (org.apache.derbyTesting.junit.SystemPropertyTestSetup)20 SupportFilesSetup (org.apache.derbyTesting.junit.SupportFilesSetup)19 SQLException (java.sql.SQLException)7 DatabasePropertyTestSetup (org.apache.derbyTesting.junit.DatabasePropertyTestSetup)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Random (java.util.Random)3 TestSetup (junit.extensions.TestSetup)3 LocaleTestSetup (org.apache.derbyTesting.junit.LocaleTestSetup)3 ResultSet (java.sql.ResultSet)2 Locale (java.util.Locale)2 PrepareStatementTest (org.apache.derbyTesting.functionTests.tests.derbynet.PrepareStatementTest)2 AnsiTrimTest (org.apache.derbyTesting.functionTests.tests.lang.AnsiTrimTest)2