diff geo-backend/src/test/java/de/intevation/gnv/geobackend/base/query/QueryExecutorTestCase.java @ 132:5a583cff97ea

Implementation of the Datainfrastructure for fetching Data from different DataStores. geo-backend/trunk@12 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 04 Sep 2009 08:11:30 +0000
parents
children 56655046194f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/geo-backend/src/test/java/de/intevation/gnv/geobackend/base/query/QueryExecutorTestCase.java	Fri Sep 04 08:11:30 2009 +0000
@@ -0,0 +1,104 @@
+/**
+ *
+ */
+package de.intevation.gnv.geobackend.base.query;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Logger;
+
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.geobackend.base.ResultDescriptor;
+import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory;
+import de.intevation.gnv.geobackend.base.query.container.QueryContainerFactory;
+import de.intevation.gnv.geobackend.base.query.exception.QueryException;
+import junit.framework.TestCase;
+
+/**
+ * TestCase for the QueryExecutor interface
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class QueryExecutorTestCase extends TestCase {
+    
+    
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = null;
+    
+    static{
+        BasicConfigurator.configure();
+        log = Logger.getLogger(QueryExecutorTestCase.class);
+    }
+    
+    /**
+     * Constructor
+     * @param name
+     */
+    public QueryExecutorTestCase(String name) {
+        super(name);
+    }
+    
+    /**
+     * Tests if the Databaseconnection can be established and
+     * Data could be read from the Database
+     */
+    public void testQueryExecutor(){
+        
+        try {
+            QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
+            Collection<Result> results = queryExecutor.executeQuery("mesh", null);
+            if (results == null || results.size() == 0){
+                log.error("Keine Daten erhalten");
+                fail();
+            }else {
+                log.debug("Datem erhalten");
+                Iterator<Result> it = results.iterator();
+                while (it.hasNext()){
+                    Result tmpResult = it.next();
+                    ResultDescriptor resultDescriptor = tmpResult.getResultDescriptor();
+                    int columns = resultDescriptor.getColumnCount();
+                    for (int i = 0; i < columns; i++){
+                        String columnName = resultDescriptor.getColumnName(i);
+                        Object value = tmpResult.getObject(columnName);
+                        log.debug(columnName + " ==> "+value.toString());
+                    }
+                }
+            }
+        } catch (QueryException e) {
+            log.error(e,e);
+            fail();
+        }
+    }
+
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    @Override
+    protected void setUp() throws Exception {
+        
+        super.setUp();
+        InputStream inputStream = new FileInputStream("src/test/ressources/ArcSDEConnectionPoolTestCase.properties");
+        Properties properties = new Properties();
+        properties.load(inputStream);
+        
+        ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance();
+        cpf.initializeConnectionPool(properties);
+        
+        
+        inputStream = new FileInputStream("src/test/ressources/QueryExecutorTestCase.properties");
+        properties = new Properties();
+        properties.load(inputStream);
+        
+        QueryContainerFactory qcf = QueryContainerFactory.getInstance();
+        qcf.initializeQueryContainer(properties);
+    }
+
+}

http://dive4elements.wald.intevation.org