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());
}
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());
}
}
Aggregations