반응형
JDBC test
package com.test.persistence;
import static org.junit.Assert.fail;
import java.sql.Connection;
import java.sql.DriverManager;
import org.junit.Test;
import lombok.extern.log4j.Log4j;
@Log4j
public class JDBCTests {
static {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(Exception e) {
e.printStackTrace();
}
}
@Test
public void testConnection() {
try(Connection con =
DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:XE",
"test",
"test")){
log.info(con);
}catch(Exception e) {
fail(e.getMessage());
}
}
}
dataSource test
package com.test.persistence;
import static org.junit.Assert.fail;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import lombok.Setter;
import lombok.extern.log4j.Log4j;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
@Log4j
public class DataSourceTests {
@Setter
private DataSource dataSource;
@Test
public void testConnection() {
try(java.sql.Connection con = dataSource.getConnection()){
log.info(con);
}catch(Exception e) {
fail(e.getMessage());
}
}
}
끝!
반응형
'Spring Framework > 환경설정' 카테고리의 다른 글
[Spring Tool Suite4] 종합설정 (0) | 2021.02.09 |
---|---|
Spring Legacy Project 생성 및 기본설정 (0) | 2021.01.07 |
Spring 구동순서 (0) | 2021.01.07 |
Spring 설정파일 (0) | 2021.01.07 |