/**
* @author 54chen(ιθ») [chenzhen@xiaomi.com czhttp@gmail.com]
* @since 2012-8-1 δΈε04:59:16
*/
package com.chen.dao;
import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import junit.framework.Assert;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class TestDAOTest {
@Autowired
private TestDAO testDAO;
@Qualifier("jade.dataSource.com.chen.dao")
@Autowired
private BasicDataSource dataSource;
@Before
public void init() {
try {
Connection conn = dataSource.getConnection();
Statement st = conn.createStatement();
st.execute("drop all objects;");
st.execute("runscript from '" + new DefaultResourceLoader().getResource("schema.sql").getURL().toString() + "'");
st.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getTestTest() {
com.chen.model.Test t = testDAO.getTest();
Assert.assertEquals(111, t.getId());
}
}