Mercurial > dive4elements > gnv-client
view geo-backend/src/test/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionPoolTestCase.java @ 662:755dd2fa4a0a 0.5
merged geo-backend/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | 5a583cff97ea |
children | 1c3efbd2fc5a |
line wrap: on
line source
package de.intevation.gnv.geobackend.sde.datasources; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; import java.sql.ResultSet; import junit.framework.TestCase; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool; import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory; import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; import de.intevation.gnv.geobackend.sde.connectionpool.ArcSDEPoolableObjectFactory; /** * TestCase for the usage of the ArcSDEConnectionPool. * @author Tim Englich <tim.englich@intevation.de> * */ public class ArcSDEConnectionPoolTestCase extends TestCase { /** * the logger, used to log exceptions and additonaly information */ private static Logger log = null; static { BasicConfigurator.configure(); log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); } /** * */ public ArcSDEConnectionPoolTestCase() { super(); } /** * * @param name */ public ArcSDEConnectionPoolTestCase(String name) { super(name); } /** * Test if the ArcSDEConnectionPool can be established * and if a Request could be done. */ public void testArcSDEConnectionPool(){ log.debug("ArcSDEConnectionPoolTestCase.testArcSDEConnectionPool"); try { InputStream inputStream = new FileInputStream("src/test/ressources/ArcSDEConnectionPoolTestCase.properties"); Properties properties = new Properties(); properties.load(inputStream); ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance(); cpf.initializeConnectionPool(properties); assertTrue(cpf.isInitialized()); log.debug("ConnectionPoolFactory ist initialisiert."); ConnectionPool cp = cpf.getConnectionPool(); assertNotNull(cp); log.debug("ConnectionPool ist initialisiert."); Connection connection = null; try{ try { connection = cp.getConnection("N/N"); assertNotNull(connection); log.debug("Connection ist initialisiert."); } catch (ConnectionException e) { log.error("Es traten Probleme bei der Verbinung zur Datenbank auf."); fail(); } try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("Select MESHID, NAME from MEDIAN.MESH"); while (rs.next()){ log.debug(rs.getInt(1)); log.debug(rs.getString(2)); log.debug(rs.getInt("MESHID")); log.debug(rs.getString("NAME")); } } catch (SQLException e) { log.error(e,e); } }finally{ if (connection != null){ try { connection.close(); } catch (SQLException e) { log.error(e,e); fail(); } } } } catch (FileNotFoundException e) { log.error(e,e); fail(); } catch (IOException e) { log.error(e,e); fail(); } } }