comparison 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
comparison
equal deleted inserted replaced
657:af3f56758f59 662:755dd2fa4a0a
1 /**
2 *
3 */
4 package de.intevation.gnv.geobackend.base.query;
5
6 import java.io.FileInputStream;
7 import java.io.InputStream;
8 import java.util.Collection;
9 import java.util.Iterator;
10 import java.util.Properties;
11
12 import org.apache.log4j.BasicConfigurator;
13 import org.apache.log4j.Logger;
14
15 import de.intevation.gnv.geobackend.base.Result;
16 import de.intevation.gnv.geobackend.base.ResultDescriptor;
17 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory;
18 import de.intevation.gnv.geobackend.base.query.container.QueryContainerFactory;
19 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
20 import junit.framework.TestCase;
21
22 /**
23 * TestCase for the QueryExecutor interface
24 * @author Tim Englich <tim.englich@intevation.de>
25 *
26 */
27 public class QueryExecutorTestCase extends TestCase {
28
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(QueryExecutorTestCase.class);
38 }
39
40 /**
41 * Constructor
42 * @param name
43 */
44 public QueryExecutorTestCase(String name) {
45 super(name);
46 }
47
48
49 public void testSpatialQuery(){
50 try {
51
52 this.testQuery(5, "spatial_query", null);
53 } catch (QueryException e) {
54 log.error(e,e);
55 fail();
56 }
57 }
58
59 public void testSpatialQueryWithoutIntersects(){
60 try {
61 // this.testQuery(286, "spatial_query_without_intersects", null);
62 this.testQuery(0, "spatial_query_without_intersects2", null);
63 this.testQuery(2060, "spatial_query_without_intersects3", null);
64 this.testQuery(0, "spatial_query_without_intersects4", null);
65 this.testQuery(27031, "spatial_query_without_intersects5", null);
66 this.testQuery(8464, "spatial_query_without_intersects6", null);
67 } catch (QueryException e) {
68 log.error(e,e);
69 fail();
70 }
71 }
72
73 public void testSpatialQueryWithInnerSelect(){
74 try {
75 this.testQuery(1998, "spatial_query_with_innerselect", null);
76 } catch (QueryException e) {
77 log.error(e,e);
78 fail();
79 }
80 }
81
82
83 public void testChooseFis(){
84 try {
85 this.testQuery(1, "choose_fis_query", null);
86 } catch (QueryException e) {
87 log.error(e, e);
88 fail();
89 }
90 }
91
92
93 /**
94 * Tests if the Databaseconnection can be established and
95 * Data could be read from the Database
96 */
97 public void testQueryExecutor(){
98
99 try {
100
101 this.testQuery(6, "mesh", null);
102
103 this.testQuery(1, "mesh_id", new String[]{"5"});
104
105
106
107 } catch (QueryException e) {
108 log.error(e,e);
109 fail();
110 }
111 }
112
113 public void testTimeSeriesQueries(){
114
115 try{
116 // Test zum initialisieren der umgebung
117 this.testQuery(6, "mesh", null);
118
119
120 this.testQuery(11, "timeseries_stations", new String[]{"4"});
121 this.testQuery(11, "timeseries_stations_op", new String[]{"4"});
122 this.testQuery(1, "timeseries_interval", new String[]{"500042 ", "54"});
123
124 } catch (QueryException e) {
125 log.error(e,e);
126 fail();
127 }
128
129 }
130
131 /**
132 * @param resultsize
133 * @param queryID
134 * @param filter
135 * @throws QueryException
136 */
137 private void testQuery(int resultsize, String queryID, String[] filter)
138 throws QueryException {
139 long start = System.currentTimeMillis();
140 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
141 Collection<Result> results = queryExecutor.executeQuery(queryID, filter);
142 // if (results == null || results.size() == 0){
143 // log.error("Keine Daten erhalten");
144 // fail();
145 // }else {
146 assertEquals(resultsize, results.size());
147 log.debug(resultsize+" Datensätze erhalten");
148 Iterator<Result> it = results.iterator();
149 while (it.hasNext()){
150 Result tmpResult = it.next();
151 ResultDescriptor resultDescriptor = tmpResult.getResultDescriptor();
152 int columns = resultDescriptor.getColumnCount();
153 for (int i = 0; i < columns; i++){
154 String columnName = resultDescriptor.getColumnName(i);
155 Object value = tmpResult.getString(columnName);
156 log.debug(columnName + " ==> "+value.toString());
157 }
158 }
159 // }
160 log.debug("Query dauerte: "+(System.currentTimeMillis()-start) +"ms");
161 }
162
163
164
165 /**
166 * @see junit.framework.TestCase#setUp()
167 */
168 @Override
169 protected void setUp() throws Exception {
170
171 super.setUp();
172 InputStream inputStream = new FileInputStream("src/test/ressources/ArcSDEConnectionPoolTestCase.properties");
173 Properties properties = new Properties();
174 properties.load(inputStream);
175
176 ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance();
177 cpf.initializeConnectionPool(properties);
178
179
180 inputStream = new FileInputStream("src/test/ressources/QueryExecutorTestCase.properties");
181 properties = new Properties();
182 properties.load(inputStream);
183
184 QueryContainerFactory qcf = QueryContainerFactory.getInstance();
185 qcf.initializeQueryContainer(properties);
186 }
187
188 }

http://dive4elements.wald.intevation.org