comparison 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
comparison
equal deleted inserted replaced
657:af3f56758f59 662:755dd2fa4a0a
1 package de.intevation.gnv.geobackend.sde.datasources;
2
3 import java.io.FileInputStream;
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.sql.Connection;
8 import java.sql.SQLException;
9 import java.sql.Statement;
10 import java.util.Properties;
11 import java.sql.ResultSet;
12
13 import junit.framework.TestCase;
14
15 import org.apache.log4j.BasicConfigurator;
16 import org.apache.log4j.Logger;
17
18 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool;
19 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory;
20 import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException;
21 import de.intevation.gnv.geobackend.sde.connectionpool.ArcSDEPoolableObjectFactory;
22
23 /**
24 * TestCase for the usage of the ArcSDEConnectionPool.
25 * @author Tim Englich <tim.englich@intevation.de>
26 *
27 */
28 public class ArcSDEConnectionPoolTestCase extends TestCase {
29
30 /**
31 * the logger, used to log exceptions and additonaly information
32 */
33 private static Logger log = null;
34
35 static {
36 BasicConfigurator.configure();
37 log = Logger.getLogger(ArcSDEPoolableObjectFactory.class);
38 }
39 /**
40 *
41 */
42 public ArcSDEConnectionPoolTestCase() {
43 super();
44 }
45
46 /**
47 *
48 * @param name
49 */
50 public ArcSDEConnectionPoolTestCase(String name) {
51 super(name);
52 }
53
54 /**
55 * Test if the ArcSDEConnectionPool can be established
56 * and if a Request could be done.
57 */
58 public void testArcSDEConnectionPool(){
59 log.debug("ArcSDEConnectionPoolTestCase.testArcSDEConnectionPool");
60 try {
61 InputStream inputStream = new FileInputStream("src/test/ressources/ArcSDEConnectionPoolTestCase.properties");
62 Properties properties = new Properties();
63 properties.load(inputStream);
64
65 ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance();
66 cpf.initializeConnectionPool(properties);
67
68 assertTrue(cpf.isInitialized());
69 log.debug("ConnectionPoolFactory ist initialisiert.");
70
71 ConnectionPool cp = cpf.getConnectionPool();
72 assertNotNull(cp);
73 log.debug("ConnectionPool ist initialisiert.");
74
75 Connection connection = null;
76 try{
77 try {
78 connection = cp.getConnection("N/N");
79 assertNotNull(connection);
80 log.debug("Connection ist initialisiert.");
81 } catch (ConnectionException e) {
82 log.error("Es traten Probleme bei der Verbinung zur Datenbank auf.");
83 fail();
84 }
85
86
87 try {
88 Statement stmt = connection.createStatement();
89 ResultSet rs = stmt.executeQuery("Select MESHID, NAME from MEDIAN.MESH");
90
91 while (rs.next()){
92 log.debug(rs.getInt(1));
93 log.debug(rs.getString(2));
94
95 log.debug(rs.getInt("MESHID"));
96 log.debug(rs.getString("NAME"));
97 }
98
99 } catch (SQLException e) {
100 log.error(e,e);
101 }
102 }finally{
103 if (connection != null){
104 try {
105 connection.close();
106 } catch (SQLException e) {
107 log.error(e,e);
108 fail();
109 }
110 }
111 }
112 } catch (FileNotFoundException e) {
113 log.error(e,e);
114 fail();
115 } catch (IOException e) {
116 log.error(e,e);
117 fail();
118 }
119 }
120 }

http://dive4elements.wald.intevation.org