Search in sources :

Example 71 with CleanDatabaseTestSetup

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

the class LobSortTest method suite.

public static Test suite() {
    Properties props = new Properties();
    // Adjust sort buffer size to trigger the bug situation with less data.
    props.setProperty("derby.storage.sortBufferMax", "4");
    BaseTestSuite suite = new BaseTestSuite(LobSortTest.class, "LobSortTestEmbedded");
    return new CleanDatabaseTestSetup(new SystemPropertyTestSetup(suite, props, true)) {

        /**
         * Generates a table with Blob and Clobs of mixed size.
         */
        protected void decorateSQL(Statement s) throws SQLException {
            Random rnd = new Random(SEED);
            Connection con = s.getConnection();
            con.setAutoCommit(false);
            s.executeUpdate("create table MIXED_LOBS (" + "c clob, clen int, b blob, blen int, rnd int)");
            PreparedStatement ps = con.prepareStatement("insert into MIXED_LOBS values (?,?,?,?,?)");
            // Make sure we get at least one zero-length CLOB and BLOB.
            ps.setString(1, "");
            ps.setInt(2, 0);
            ps.setBytes(3, new byte[0]);
            ps.setInt(4, 0);
            ps.setInt(5, rnd.nextInt());
            ps.executeUpdate();
            for (int i = 0; i < 100; i++) {
                CharAlphabet ca = getCharAlphabet(1 + rnd.nextInt(3));
                int length = (int) (rnd.nextDouble() * 64.0 * 1024.0);
                if (rnd.nextInt(1000) < 500) {
                    // Specify the length.
                    ps.setCharacterStream(1, new LoopingAlphabetReader(length, ca), length);
                } else {
                    // Don't specify the length.
                    ps.setCharacterStream(1, new LoopingAlphabetReader(length, ca));
                }
                ps.setInt(2, length);
                length = (int) (rnd.nextDouble() * 64.0 * 1024.0);
                if (rnd.nextInt(1000) < 500) {
                    // Specify the length.
                    ps.setBinaryStream(3, new LoopingAlphabetStream(length), length);
                } else {
                    // Don't specify the length.
                    ps.setBinaryStream(3, new LoopingAlphabetStream(length));
                }
                ps.setInt(4, length);
                ps.setInt(5, rnd.nextInt());
                ps.executeUpdate();
            }
            con.commit();
            ps.close();
        }

        /**
         * Returns a character alphabet.
         */
        private CharAlphabet getCharAlphabet(int i) {
            switch(i) {
                case 1:
                    return CharAlphabet.modernLatinLowercase();
                case 2:
                    return CharAlphabet.tamil();
                case 3:
                    return CharAlphabet.cjkSubset();
                default:
                    fail("Unknown alphabet identifier: " + i);
            }
            // Will never be reached.
            return null;
        }
    };
}
Also used : Random(java.util.Random) CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SystemPropertyTestSetup(org.apache.derbyTesting.junit.SystemPropertyTestSetup) Connection(java.sql.Connection) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) PreparedStatement(java.sql.PreparedStatement) LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream) Properties(java.util.Properties) CharAlphabet(org.apache.derbyTesting.functionTests.util.streams.CharAlphabet) LoopingAlphabetReader(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)

Example 72 with CleanDatabaseTestSetup

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

the class ConnectionMethodsTest method baseSuite.

public static Test baseSuite(String name) {
    BaseTestSuite suite = new BaseTestSuite(ConnectionMethodsTest.class, name);
    Test test = new SupportFilesSetup(suite, new String[] { "functionTests/testData/ConnectionMethods/short.txt" });
    return new CleanDatabaseTestSetup(test) {

        protected void decorateSQL(Statement s) throws SQLException {
            s.execute("create table clobtable2(n int,clobcol CLOB)");
            s.execute("create table blobtable2(n int,blobcol BLOB)");
            s.execute("create table abort_table(a int)");
            s.execute("create schema foo");
            s.execute("create table foo.set_schema_table( a int )");
        }
    };
}
Also used : Test(junit.framework.Test) CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) SupportFilesSetup(org.apache.derbyTesting.junit.SupportFilesSetup)

Example 73 with CleanDatabaseTestSetup

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

the class Derby3650Test method baseSuite.

protected static Test baseSuite(String name) {
    BaseTestSuite suite = new BaseTestSuite(name);
    suite.addTestSuite(Derby3650Test.class);
    return new CleanDatabaseTestSetup(DatabasePropertyTestSetup.setLockTimeouts(suite, 2, 4)) {

        /**
         * Creates the tables used in the test cases.
         * @exception SQLException if a database error occurs
         */
        protected void decorateSQL(Statement stmt) throws SQLException {
            try {
                initializeClobTables(stmt);
                initializeBlobTables(stmt);
            } catch (IOException ioe) {
                fail("Unexpected I/O exception during setup: " + ioe);
            }
        }
    };
}
Also used : CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) IOException(java.io.IOException)

Example 74 with CleanDatabaseTestSetup

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

the class UrlLocaleTest method suite.

public static Test suite() {
    BaseTestSuite suite = new BaseTestSuite();
    suite.addTestSuite(UrlLocaleTest.class);
    suite.addTest(new LocaleTestSetup(new UrlLocaleTest("messageLocale_unknown"), new Locale("rr", "TT")));
    suite.addTest(new LocaleTestSetup(new UrlLocaleTest("messageLocale_Germany"), Locale.GERMANY));
    Test tsuite = new CleanDatabaseTestSetup(suite) {

        /**
         * Creates the table used in the test cases.
         */
        protected void decorateSQL(Statement s) throws SQLException {
            createLocaleProcedures(s.getConnection());
        }
    };
    tsuite = new SupportFilesSetup(tsuite);
    return tsuite;
}
Also used : Locale(java.util.Locale) Test(junit.framework.Test) CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) Statement(java.sql.Statement) LocaleTestSetup(org.apache.derbyTesting.junit.LocaleTestSetup) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) SupportFilesSetup(org.apache.derbyTesting.junit.SupportFilesSetup)

Example 75 with CleanDatabaseTestSetup

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

the class AbortTest method baseSuite.

public static Test baseSuite(boolean hasSecurityManager) {
    AbortTest abortTest = new AbortTest("test_basic", hasSecurityManager);
    Test test = new CleanDatabaseTestSetup(abortTest) {

        protected void decorateSQL(Statement s) throws SQLException {
            s.execute("create table abort_table( a int )");
        }
    };
    if (hasSecurityManager) {
        return new SecurityManagerSetup(test, "org/apache/derbyTesting/functionTests/tests/jdbc4/noAbortPermission.policy");
    } else {
        return SecurityManagerSetup.noSecurityManager(test);
    }
}
Also used : Test(junit.framework.Test) CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SecurityManagerSetup(org.apache.derbyTesting.junit.SecurityManagerSetup)

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