Search in sources :

Example 26 with SystemPropertyTestSetup

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

the class MissingPermissionsTest method makeTest.

private static Test makeTest(String fixture, String policy) {
    Test t = new MissingPermissionsTest(fixture);
    t = new SecurityManagerSetup(t, policy);
    final Properties props = new Properties();
    props.setProperty("derby.connection.requireAuthentication", "true");
    props.setProperty("derby.database.sqlAuthorization", "true");
    props.setProperty("derby.authentication.provider", "BUILTIN");
    props.setProperty("derby.user.APP", "APPPW");
    t = new SystemPropertyTestSetup(t, props, true);
    t = TestConfiguration.changeUserDecorator(t, "APP", "APPPW");
    t = TestConfiguration.singleUseDatabaseDecorator(t);
    return t;
}
Also used : Test(junit.framework.Test) SystemPropertyTestSetup(org.apache.derbyTesting.junit.SystemPropertyTestSetup) SecurityManagerSetup(org.apache.derbyTesting.junit.SecurityManagerSetup) Properties(java.util.Properties)

Example 27 with SystemPropertyTestSetup

use of org.apache.derbyTesting.junit.SystemPropertyTestSetup 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 28 with SystemPropertyTestSetup

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

the class AuthenticationTest method setBaseProps.

private static void setBaseProps(BaseTestSuite suite, Test test, Properties extraDbProps) {
    // Use DatabasePropertyTestSetup.builtinAuthentication decorator
    // to set the user properties required by this test (and shutdown
    // the database for the property to take effect).
    // DatabasePropertyTestSetup uses SYSCS_SET_DATABASE_PROPERTY
    // so that is database level setting.
    // Additionally use DatabasePropertyTestSetup to add some
    // possibly useful settings
    // Finally SystemPropertyTestSetup sets up system level users
    Properties props = new Properties();
    props.setProperty("derby.infolog.append", "true");
    props.setProperty("derby.debug.true", "AuthenticationTrace");
    if (extraDbProps != null) {
        props.putAll(extraDbProps);
    }
    Properties sysprops = new Properties();
    sysprops.put("derby.user.system", "admin");
    sysprops.put("derby.user.mickey", "mouse");
    test = DatabasePropertyTestSetup.builtinAuthentication(test, USERS, PASSWORD_SUFFIX);
    test = new DatabasePropertyTestSetup(test, props, true);
    suite.addTest(new SystemPropertyTestSetup(test, sysprops));
}
Also used : DatabasePropertyTestSetup(org.apache.derbyTesting.junit.DatabasePropertyTestSetup) SystemPropertyTestSetup(org.apache.derbyTesting.junit.SystemPropertyTestSetup) Properties(java.util.Properties)

Example 29 with SystemPropertyTestSetup

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

the class LocalizedDisplayScriptTest method getSuite.

/**
 * Return a localized test based on the script name.
 * The test is surrounded in a decorator that sets up the
 * desired properties which is wrapped in a decorator
 * which sets up the timezone wrapped in a decorator
 * that cleans the database.
 */
private static Test getSuite() {
    BaseTestSuite suite = new BaseTestSuite("localized Display");
    Properties uiProps = new Properties();
    uiProps.put("derby.ui.locale", "es_AR");
    uiProps.put("derby.ui.codeset", ENCODING);
    suite.addTest(new TimeZoneTestSetup(new SystemPropertyTestSetup(new LocalizedDisplayScriptTest("LocalizedDisplay"), uiProps), "America/Los_Angeles"));
    return getIJConfig(suite);
}
Also used : SystemPropertyTestSetup(org.apache.derbyTesting.junit.SystemPropertyTestSetup) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) Properties(java.util.Properties) TimeZoneTestSetup(org.apache.derbyTesting.junit.TimeZoneTestSetup)

Example 30 with SystemPropertyTestSetup

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

the class LocalizedAttributeScriptTest method getSuite.

/**
 * Return a suite of localized tests based on the
 * script name. The test is surrounded in a decorator
 * that sets localization properties wrapped in a decorator
 * that cleans the database.
 */
private static Test getSuite() {
    BaseTestSuite suite = new BaseTestSuite("localized scripts");
    Properties uiProps = new Properties();
    uiProps.put("derby.ui.locale", "de_DE");
    uiProps.put("derby.ui.codeset", "ISO-8859-1");
    suite.addTest(new SystemPropertyTestSetup(new LocalizedAttributeScriptTest("LocalizedConnectionAttribute"), uiProps));
    return getIJConfig(suite);
}
Also used : SystemPropertyTestSetup(org.apache.derbyTesting.junit.SystemPropertyTestSetup) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) Properties(java.util.Properties)

Aggregations

SystemPropertyTestSetup (org.apache.derbyTesting.junit.SystemPropertyTestSetup)55 Properties (java.util.Properties)54 BaseTestSuite (org.apache.derbyTesting.junit.BaseTestSuite)34 Test (junit.framework.Test)33 CleanDatabaseTestSetup (org.apache.derbyTesting.junit.CleanDatabaseTestSetup)20 PreparedStatement (java.sql.PreparedStatement)8 Statement (java.sql.Statement)8 SupportFilesSetup (org.apache.derbyTesting.junit.SupportFilesSetup)8 DatabasePropertyTestSetup (org.apache.derbyTesting.junit.DatabasePropertyTestSetup)6 Connection (java.sql.Connection)3 TestSetup (junit.extensions.TestSetup)3 JDBCClientSetup (org.apache.derbyTesting.junit.JDBCClientSetup)2 NetworkServerTestSetup (org.apache.derbyTesting.junit.NetworkServerTestSetup)2 SecurityManagerSetup (org.apache.derbyTesting.junit.SecurityManagerSetup)2 File (java.io.File)1 URL (java.net.URL)1 CallableStatement (java.sql.CallableStatement)1 SQLException (java.sql.SQLException)1 Locale (java.util.Locale)1 Random (java.util.Random)1