Search in sources :

Example 1 with TestJDBCDataSource

use of org.apache.wiki.TestJDBCDataSource in project jspwiki by apache.

the class JDBCGroupDatabaseTest method setUp.

/**
 */
@Before
public void setUp() throws Exception {
    m_hu.setUp();
    Properties props = TestEngine.getTestProperties();
    WikiEngine engine = new TestEngine(props);
    m_wiki = engine.getApplicationName();
    // Set up the mock JNDI initial context
    TestJNDIContext.initialize();
    Context initCtx = new InitialContext();
    try {
        initCtx.bind("java:comp/env", new TestJNDIContext());
    } catch (NameAlreadyBoundException e) {
    // ignore
    }
    Context ctx = (Context) initCtx.lookup("java:comp/env");
    DataSource ds = new TestJDBCDataSource(new File("target/test-classes/jspwiki-custom.properties"));
    ctx.bind(JDBCGroupDatabase.DEFAULT_GROUPDB_DATASOURCE, ds);
    try {
        m_conn = ds.getConnection();
    } catch (SQLException e) {
        Assert.fail("Looks like your database could not be connected to - " + "please make sure that you have started your database, exception: " + e.getMessage());
    }
    // Initialize the user database
    m_db = new JDBCGroupDatabase();
    m_db.initialize(engine, new Properties());
}
Also used : InitialContext(javax.naming.InitialContext) TestJNDIContext(org.apache.wiki.TestJNDIContext) Context(javax.naming.Context) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) TestJDBCDataSource(org.apache.wiki.TestJDBCDataSource) SQLException(java.sql.SQLException) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) WikiEngine(org.apache.wiki.WikiEngine) TestJNDIContext(org.apache.wiki.TestJNDIContext) File(java.io.File) InitialContext(javax.naming.InitialContext) TestJDBCDataSource(org.apache.wiki.TestJDBCDataSource) DataSource(javax.sql.DataSource) Before(org.junit.Before)

Example 2 with TestJDBCDataSource

use of org.apache.wiki.TestJDBCDataSource in project jspwiki by apache.

the class JDBCUserDatabaseTest method setUp.

/**
 */
@Before
public void setUp() throws Exception {
    m_hu.setUp();
    // Set up the mock JNDI initial context
    TestJNDIContext.initialize();
    Context initCtx = new InitialContext();
    try {
        initCtx.bind("java:comp/env", new TestJNDIContext());
    } catch (NameAlreadyBoundException e) {
    // ignore
    }
    Context ctx = (Context) initCtx.lookup("java:comp/env");
    DataSource ds = new TestJDBCDataSource(new File("target/test-classes/jspwiki-custom.properties"));
    ctx.bind(JDBCUserDatabase.DEFAULT_DB_JNDI_NAME, ds);
    // Get the JDBC connection and init tables
    try {
        Connection conn = ds.getConnection();
        Statement stmt = conn.createStatement();
        String sql;
        sql = "DELETE FROM " + JDBCUserDatabase.DEFAULT_DB_TABLE + ";";
        stmt.executeUpdate(sql);
        // Create a new test user 'janne'
        stmt.executeUpdate(INSERT_JANNE);
        // Create a new test user 'user'
        stmt.executeUpdate(INSERT_USER);
        stmt.close();
        conn.close();
        // Initialize the user database
        m_db = new JDBCUserDatabase();
        m_db.initialize(null, new Properties());
    } catch (SQLException e) {
        Assert.fail("Looks like your database could not be connected to - " + "please make sure that you have started your database, exception: " + e.getMessage());
    }
}
Also used : InitialContext(javax.naming.InitialContext) TestJNDIContext(org.apache.wiki.TestJNDIContext) Context(javax.naming.Context) TestJDBCDataSource(org.apache.wiki.TestJDBCDataSource) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) TestJDBCDataSource(org.apache.wiki.TestJDBCDataSource) DataSource(javax.sql.DataSource) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) TestJNDIContext(org.apache.wiki.TestJNDIContext) File(java.io.File) Before(org.junit.Before)

Aggregations

File (java.io.File)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 Context (javax.naming.Context)2 InitialContext (javax.naming.InitialContext)2 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)2 DataSource (javax.sql.DataSource)2 TestJDBCDataSource (org.apache.wiki.TestJDBCDataSource)2 TestJNDIContext (org.apache.wiki.TestJNDIContext)2 Before (org.junit.Before)2 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 TestEngine (org.apache.wiki.TestEngine)1 WikiEngine (org.apache.wiki.WikiEngine)1