Mercurial > dive4elements > gnv-client
diff geo-backend/src/test/java/de/intevation/gnv/geobackend/base/query/QueryExecutorTestCase.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 | 31595c0a1a33 |
children | 1c3efbd2fc5a |
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 28 12:13:53 2012 +0200 @@ -0,0 +1,188 @@ +/** + * + */ +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); + } + + + public void testSpatialQuery(){ + try { + + this.testQuery(5, "spatial_query", null); + } catch (QueryException e) { + log.error(e,e); + fail(); + } + } + + public void testSpatialQueryWithoutIntersects(){ + try { +// this.testQuery(286, "spatial_query_without_intersects", null); + this.testQuery(0, "spatial_query_without_intersects2", null); + this.testQuery(2060, "spatial_query_without_intersects3", null); + this.testQuery(0, "spatial_query_without_intersects4", null); + this.testQuery(27031, "spatial_query_without_intersects5", null); + this.testQuery(8464, "spatial_query_without_intersects6", null); + } catch (QueryException e) { + log.error(e,e); + fail(); + } + } + + public void testSpatialQueryWithInnerSelect(){ + try { + this.testQuery(1998, "spatial_query_with_innerselect", null); + } catch (QueryException e) { + log.error(e,e); + fail(); + } + } + + + public void testChooseFis(){ + try { + this.testQuery(1, "choose_fis_query", null); + } catch (QueryException e) { + log.error(e, e); + fail(); + } + } + + + /** + * Tests if the Databaseconnection can be established and + * Data could be read from the Database + */ + public void testQueryExecutor(){ + + try { + + this.testQuery(6, "mesh", null); + + this.testQuery(1, "mesh_id", new String[]{"5"}); + + + + } catch (QueryException e) { + log.error(e,e); + fail(); + } + } + + public void testTimeSeriesQueries(){ + + try{ + // Test zum initialisieren der umgebung + this.testQuery(6, "mesh", null); + + + this.testQuery(11, "timeseries_stations", new String[]{"4"}); + this.testQuery(11, "timeseries_stations_op", new String[]{"4"}); + this.testQuery(1, "timeseries_interval", new String[]{"500042 ", "54"}); + + } catch (QueryException e) { + log.error(e,e); + fail(); + } + + } + + /** + * @param resultsize + * @param queryID + * @param filter + * @throws QueryException + */ + private void testQuery(int resultsize, String queryID, String[] filter) + throws QueryException { + long start = System.currentTimeMillis(); + QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); + Collection<Result> results = queryExecutor.executeQuery(queryID, filter); +// if (results == null || results.size() == 0){ +// log.error("Keine Daten erhalten"); +// fail(); +// }else { + assertEquals(resultsize, results.size()); + log.debug(resultsize+" Datensätze 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.getString(columnName); + log.debug(columnName + " ==> "+value.toString()); + } + } +// } + log.debug("Query dauerte: "+(System.currentTimeMillis()-start) +"ms"); + } + + + + /** + * @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); + } + +}