Mercurial > dive4elements > gnv-client
comparison geo-backend/src/test/java/de/intevation/gnv/geobackend/base/query/QueryExecutorTestCase.java @ 139:9f2eaefe9dd4
Some Log Messages Added.
Testcases modified to test Spatialquery support.
geo-backend/trunk@105 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 21 Sep 2009 11:41:33 +0000 |
parents | 56655046194f |
children | 5bbdbc0bbddc |
comparison
equal
deleted
inserted
replaced
138:c5d50a4bb1e1 | 139:9f2eaefe9dd4 |
---|---|
43 */ | 43 */ |
44 public QueryExecutorTestCase(String name) { | 44 public QueryExecutorTestCase(String name) { |
45 super(name); | 45 super(name); |
46 } | 46 } |
47 | 47 |
48 | |
49 public void testSpatialQuery(){ | |
50 try { | |
51 | |
52 this.testQuery(27031, "spatial_query", null); | |
53 } catch (QueryException e) { | |
54 log.error(e,e); | |
55 fail(); | |
56 } | |
57 } | |
58 | |
59 | |
48 /** | 60 /** |
49 * Tests if the Databaseconnection can be established and | 61 * Tests if the Databaseconnection can be established and |
50 * Data could be read from the Database | 62 * Data could be read from the Database |
51 */ | 63 */ |
52 public void testQueryExecutor(){ | 64 public void testQueryExecutor(){ |
53 | 65 |
54 try { | 66 try { |
55 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); | |
56 Collection<Result> results = queryExecutor.executeQuery("mesh", null); | |
57 if (results == null || results.size() == 0){ | |
58 log.error("Keine Daten erhalten"); | |
59 fail(); | |
60 }else { | |
61 assertEquals(6, results.size()); | |
62 log.debug("6 Datensätze erhalten"); | |
63 Iterator<Result> it = results.iterator(); | |
64 while (it.hasNext()){ | |
65 Result tmpResult = it.next(); | |
66 ResultDescriptor resultDescriptor = tmpResult.getResultDescriptor(); | |
67 int columns = resultDescriptor.getColumnCount(); | |
68 for (int i = 0; i < columns; i++){ | |
69 String columnName = resultDescriptor.getColumnName(i); | |
70 Object value = tmpResult.getObject(columnName); | |
71 log.debug(columnName + " ==> "+value.toString()); | |
72 } | |
73 } | |
74 } | |
75 | 67 |
76 // Quering Data with where clause | 68 this.testQuery(6, "mesh", null); |
77 results = queryExecutor.executeQuery("mesh_id", new String[]{"5"}); | 69 |
78 if (results == null || results.size() == 0){ | 70 this.testQuery(1, "mesh_id", new String[]{"5"}); |
79 log.error("Keine Daten erhalten"); | 71 |
80 fail(); | 72 |
81 }else { | |
82 assertEquals(1, results.size()); | |
83 log.debug("1 Datensatz erhalten"); | |
84 log.debug("Daten erhalten"); | |
85 Iterator<Result> it = results.iterator(); | |
86 while (it.hasNext()){ | |
87 Result tmpResult = it.next(); | |
88 ResultDescriptor resultDescriptor = tmpResult.getResultDescriptor(); | |
89 int columns = resultDescriptor.getColumnCount(); | |
90 for (int i = 0; i < columns; i++){ | |
91 String columnName = resultDescriptor.getColumnName(i); | |
92 Object value = tmpResult.getObject(columnName); | |
93 log.debug(columnName + " ==> "+value.toString()); | |
94 } | |
95 } | |
96 } | |
97 | 73 |
98 } catch (QueryException e) { | 74 } catch (QueryException e) { |
99 log.error(e,e); | 75 log.error(e,e); |
100 fail(); | 76 fail(); |
101 } | 77 } |
102 } | 78 } |
79 | |
80 public void testTimeSeriesQueries(){ | |
81 | |
82 try{ | |
83 // Test zum initialisieren der umgebung | |
84 this.testQuery(6, "mesh", null); | |
85 | |
86 | |
87 this.testQuery(11, "timeseries_stations", new String[]{"4"}); | |
88 this.testQuery(11, "timeseries_stations_op", new String[]{"4"}); | |
89 this.testQuery(1, "timeseries_interval", new String[]{"500042 ", "54"}); | |
90 | |
91 } catch (QueryException e) { | |
92 log.error(e,e); | |
93 fail(); | |
94 } | |
95 | |
96 } | |
97 | |
98 /** | |
99 * @param resultsize | |
100 * @param queryID | |
101 * @param filter | |
102 * @throws QueryException | |
103 */ | |
104 private void testQuery(int resultsize, String queryID, String[] filter) | |
105 throws QueryException { | |
106 long start = System.currentTimeMillis(); | |
107 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); | |
108 Collection<Result> results = queryExecutor.executeQuery(queryID, filter); | |
109 if (results == null || results.size() == 0){ | |
110 log.error("Keine Daten erhalten"); | |
111 fail(); | |
112 }else { | |
113 assertEquals(resultsize, results.size()); | |
114 log.debug(resultsize+" Datensätze erhalten"); | |
115 Iterator<Result> it = results.iterator(); | |
116 while (it.hasNext()){ | |
117 Result tmpResult = it.next(); | |
118 ResultDescriptor resultDescriptor = tmpResult.getResultDescriptor(); | |
119 int columns = resultDescriptor.getColumnCount(); | |
120 for (int i = 0; i < columns; i++){ | |
121 String columnName = resultDescriptor.getColumnName(i); | |
122 Object value = tmpResult.getObject(columnName); | |
123 log.debug(columnName + " ==> "+value.toString()); | |
124 } | |
125 } | |
126 } | |
127 log.debug("Query dauerte: "+(System.currentTimeMillis()-start) +"ms"); | |
128 } | |
129 | |
103 | 130 |
104 | 131 |
105 /** | 132 /** |
106 * @see junit.framework.TestCase#setUp() | 133 * @see junit.framework.TestCase#setUp() |
107 */ | 134 */ |