Package com.chen.dao

Source Code of com.chen.dao.TestDAOTest

/**
* @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());
    }

}
TOP

Related Classes of com.chen.dao.TestDAOTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.