develog

[junit] ExtSpringJUnit4ClassRunner 본문

Dev/junit

[junit] ExtSpringJUnit4ClassRunner

냐옴 2013. 12. 9. 15:54

 

import org.junit.internal.runners.InitializationError;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.jndi.JndiTemplate;
import org.springframework.mock.jndi.SimpleNamingContextBuilder;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

public class ExtSpringJUnit4ClassRunner extends SpringJUnit4ClassRunner {

    public ExtSpringJUnit4ClassRunner(Class<?> clazz) throws InitializationError, Exception {
        super(clazz);
        bindJndi();
    }

    private void bindJndi() throws Exception {
        SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
        builder.activate();

        DriverManagerDataSource ds = new DriverManagerDataSource();
        ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
        ds.setUrl("jdbc:oracle:thin:@127.0.0.1:1521:ORCL");
        ds.setUsername("scott");
        ds.setPassword("tiger");
        
        JndiTemplate jt = new JndiTemplate();
        jt.bind("jdbc/oracle", ds);
    }

}

'Dev > junit' 카테고리의 다른 글

[JUnit] JUnit Transaction Rollback  (0) 2015.05.06
JUnit 에서 ApplicationContext 접근  (0) 2013.12.11
JUnit 버전 확인  (0) 2013.12.09
JUnit 4 in 60 Seconds  (0) 2013.08.07
JUnit Test Project '.classpath'  (0) 2013.07.09
Comments