package eu.dnetlib.dlms.jdbc;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.sql.SQLException;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Test class for DorotyDataSource. Tested methods are those related to the connection (others are just properties'
 * setter/getter).
 * 
 * @author lexis
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class TestDorotyDataSource {

	/** Logger. */
	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(TestDorotyDataSource.class);

	/** Entity under test. */
	@Resource
	private DorotyDataSource dataSource;

	/**
	 * Test method for {@link eu.dnetlib.dlms.jdbc.DorotyDataSource#getConnection()}.
	 * 
	 * @throws SQLException
	 *             getting the connection or asking the connection state
	 */
	@Test
	@DirtiesContext
	public void testGetConnection() throws SQLException {
		DorotyConnection dorCon = this.dataSource.getConnection();
		assertTrue(dorCon.isValid(0));
		assertNotNull(dorCon.getMetaData());
		dorCon.close();
		assertFalse(dorCon.isValid(0));
		assertTrue(dorCon.isClosed());
	}
}
