Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javamuseum.dbunit;
- import java.io.FileInputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.util.List;
- import java.util.Properties;
- import org.dbunit.DBTestCase;
- import org.dbunit.database.DatabaseConnection;
- import org.dbunit.database.IDatabaseConnection;
- import org.dbunit.dataset.IDataSet;
- import org.dbunit.dataset.xml.FlatXmlDataSet;
- import org.dbunit.operation.DatabaseOperation;
- public class ExhibitsDAOTest extends DBTestCase {
- private ExhibitsDAO dao;
- IDataSet loadedDataSet;
- IDatabaseConnection conn;
- @Override
- public void setUp(){
- try {
- //set connection info for DAO
- super.setUp();
- dao = new ExhibitsDAO();
- }
- catch (Exception e) {}
- }
- @Override
- public void tearDown(){
- //dao.close();
- }
- @Override
- protected IDatabaseConnection getConnection() throws Exception {
- System.out.println("getConnection");
- Properties properties = new Properties();
- properties.load(this.getClass().getClassLoader().getResourceAsStream("db.properties"));
- String driver = properties.getProperty("DRIVER");
- String dburl = properties.getProperty("DBURL");
- String user = properties.getProperty("USER");
- String password = properties.getProperty("PASSWORD");
- Class.forName(driver);
- Connection jdbcConnection = DriverManager.getConnection(dburl, user, password);
- return new DatabaseConnection(jdbcConnection);
- }
- @Override
- protected IDataSet getDataSet() throws Exception {
- System.out.println("getDataSet");
- try {
- System.out.println("before return");
- loadedDataSet = new FlatXmlDataSet(new FileInputStream(
- "src/com/javamuseum/dbunit/exhibits.xml"));
- System.out.println("dataset" + loadedDataSet);
- }
- catch(Exception e) {
- System.out.println("error in getDataset" + e.getMessage());
- }
- System.out.println("after loading xml");
- return loadedDataSet;
- }
- @Override
- protected DatabaseOperation getSetUpOperation() throws Exception {
- //return DatabaseOperation.REFRESH;
- return DatabaseOperation.CLEAN_INSERT;
- }
- @Override
- protected DatabaseOperation getTearDownOperation() throws Exception {
- return DatabaseOperation.NONE;
- }
- // public void testAllExhibitsQuery(){
- // List<Exhibit> exhibits = dao.getExhibits();
- // System.out.println("num..." + dao.getExhibits().size());
- //
- // assertTrue( exhibits.contains(new Exhibit("OKeefes", 0, true)) );
- // assertTrue( exhibits.contains(new Exhibit("ElginMarbles", 825, false)) );
- // System.out.println("num..." + dao.getExhibits().size());
- // }
- public void testCheckLoginDataLoaded() throws Exception{
- assertNotNull(loadedDataSet);
- int rowCount = loadedDataSet.getTable("TABLE_EXHIBITS").getRowCount();
- System.out.println("rowCount="+rowCount);
- assertEquals(2, rowCount);
- }
- // public void testPermanentExhibitsQuery(){
- // List<Exhibit> exhibits = dao.getPermanentExhibits();
- // assertTrue( "should contain permanent", exhibits.contains(new Exhibit("OKeefes", 0, true)) );
- // assertFalse( "should not contain visiting", exhibits.contains(new Exhibit("ElginMarbles", 825, false)) );
- // }
- //
- // public void testPermanentExhibitsQueryPerformance(){
- // long start = System.nanoTime();
- // testPermanentExhibitsQuery();
- // long end = System.nanoTime();
- // assertTrue( (end-start) < 1000*1000 ); // 1 million nanoseconds = 1ms
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement