/[eiffelstudio]/branches/eth/eve/Src/library/abel/apps/test/abel_test/ps_repository_tests.e
ViewVC logotype

Contents of /branches/eth/eve/Src/library/abel/apps/test/abel_test/ps_repository_tests.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 88483 - (show annotations)
Thu Mar 29 21:30:22 2012 UTC (7 years, 6 months ago) by romanschmocker
File size: 15682 byte(s)
finished implementation if PS_PREDEFINED_CRITERION, added some unit tests for new functionality
1 note
2 description: "Test class for all backend-neutral tests, can be inherited and made effective for each backend."
3 author: "Roman Schmocker"
4 date: "$Date$"
5 revision: "$Revision$"
6
7 deferred class
8 PS_REPOSITORY_TESTS
9
10 inherit
11
12 EQA_TEST_SET
13 undefine
14 on_prepare
15 end
16
17 feature
18
19 on_prepare
20 deferred
21 end
22
23 feature {NONE} -- Test criteria setting
24
25 test_criteria_agents -- Some simple tests: strings and numbers with agent criteria
26 do
27 test_query_no_result
28 test_query_one_result_agent_greater_than
29 test_query_one_result_agent_equals_to
30 test_query_one_result_agent_matching_string
31 test_query_one_result_agent_less_than
32 test_query_one_result_agent_string_contains
33 test_query_one_result_two_agent_criteria_anded
34 test_query_one_result_two_agent_criteria_ored
35 end
36
37 test_query_no_result
38 -- Test a query using agent criterion `items_greater_than' yielding no result.
39 local
40 q: PS_OBJECT_QUERY [PERSON]
41 p: PERSON
42 do
43 create q.make
44 q.set_criterion (factory [[agent p_dao.items_greater_than(?, 7)]])
45 person_executor.execute_query (q)
46 --assert ("The result list has " + q.matched.count.out + " items instead of 0.", q.matched.count = 0)
47 assert ("The result list is not empty, but it should be.", q.result_cursor.after)
48
49 -- How to establish the difference between the empty result list because there is no data matching
50 -- and the empty list because the retrieval did not work correctly?
51 -- You know the answer by looking at the last_error attribute.
52 end
53
54 test_query_one_result_agent_greater_than
55 -- Test a query using agent criterion `items_greater_than' yielding one result.
56 local
57 q: PS_OBJECT_QUERY [PERSON]
58 p: PERSON
59 do
60 create q.make
61 q.set_criterion (factory [[agent p_dao.items_greater_than(?, 3)]])
62 person_executor.execute_query (q)
63 --assert ("The result list has " + q.matched.count.out + " items instead of 1.", q.matched.count = 1)
64 assert ("The result list is empty", not q.result_cursor.after)
65 p := q.result_cursor.item
66 q.result_cursor.forth
67 assert ("The result list has more than one item", q.result_cursor.after)
68
69
70 assert ("The person in result is supposed to own 5 items but owns " + p.items_owned.out + " instead.", p.items_owned = 5)
71 end
72
73 test_query_one_result_agent_equals_to
74 -- Test a query using agent criterion `items_equals_to'. One result expected.
75 local
76 q: PS_OBJECT_QUERY [PERSON]
77 p: PERSON
78 do
79 create q.make
80 q.set_criterion (factory [[agent p_dao.items_equal_to(?, 5)]])
81 person_executor.execute_query (q)
82 --assert ("The result list has " + q.matched.count.out + " items instead of 1.", q.matched.count = 1)
83 assert ("The result list is empty", not q.result_cursor.after)
84 p := q.result_cursor.item
85 q.result_cursor.forth
86 assert ("The result list has more than one item", q.result_cursor.after)
87
88 assert ("The person in result is supposed to own 5 items but owns " + p.items_owned.out + " instead.", p.items_owned = 5)
89 assert ("The person in result is supposed to be called Berno but is called " + p.first_name + " instead.", p.first_name.is_equal ("Berno"))
90 end
91
92 test_query_one_result_agent_matching_string
93 -- Test a query using agent criterion `first_name_matches'. One result expected.
94 local
95 q: PS_OBJECT_QUERY [PERSON]
96 p: PERSON
97 do
98 create q.make
99 q.set_criterion (factory [[agent p_dao.first_name_matches(?, "Crispo")]])
100 person_executor.execute_query (q)
101 --assert ("The result list has " + q.matched.count.out + " items instead of 1.", q.matched.count = 1)
102 assert ("The result list is empty", not q.result_cursor.after)
103 p := q.result_cursor.item
104 q.result_cursor.forth
105 assert ("The result list has more than one item", q.result_cursor.after)
106
107 assert ("The person in result is supposed to be called Crispo but is called " + p.first_name + " instead.", p.first_name.is_equal ("Crispo"))
108 end
109
110 test_query_one_result_agent_less_than
111 -- Test a query using agent criterion `items_less_than'. One result expected.
112 local
113 q: PS_OBJECT_QUERY [PERSON]
114 p: PERSON
115 do
116 create q.make
117 q.set_criterion (factory [[agent p_dao.items_less_than(?, 3)]])
118 person_executor.execute_query (q)
119 --assert ("The result list has " + q.matched.count.out + " items instead of 1.", q.matched.count = 1)
120 assert ("The result list is empty", not q.result_cursor.after)
121 p := q.result_cursor.item
122 q.result_cursor.forth
123 assert ("The result list has more than one item", q.result_cursor.after)
124
125 assert ("The person in result is supposed to own 2 items but owns " + p.items_owned.out + " instead.", p.items_owned = 2)
126 end
127
128 test_query_one_result_agent_string_contains
129 -- Test a query using agent criterion `string_contains'. One result expected.
130 local
131 q: PS_OBJECT_QUERY [PERSON]
132 p: PERSON
133 do
134 create q.make
135 q.set_criterion (factory [[agent p_dao.first_name_contains(?, "ris")]])
136 person_executor.execute_query (q)
137 --assert ("The result list has " + q.matched.count.out + " items instead of 1.", q.matched.count = 1)
138 assert ("The result list is empty", not q.result_cursor.after)
139 p := q.result_cursor.item
140 q.result_cursor.forth
141 assert ("The result list has more than one item", q.result_cursor.after)
142
143 assert ("The person in result is supposed to be called Crispo but is called " + p.first_name + " instead.", p.first_name.is_equal ("Crispo"))
144 end
145
146 test_query_one_result_two_agent_criteria_anded
147 -- Test a query using agent `items_reater_than' anded with agent `first_name_matches'. One result expected.
148 local
149 q: PS_OBJECT_QUERY [PERSON]
150 p: PERSON
151 do
152 create q.make
153 q.set_criterion (factory [[agent p_dao.items_greater_than(?, 3)]] and factory [[agent p_dao.first_name_matches(?, "Berno")]])
154 person_executor.execute_query (q)
155 --assert ("The result list has " + q.matched.count.out + " items instead of 1.", q.matched.count = 1)
156 assert ("The result list is empty", not q.result_cursor.after)
157 p := q.result_cursor.item
158 q.result_cursor.forth
159 assert ("The result list has more than one item", q.result_cursor.after)
160
161 assert ("The person in result is supposed to be called Berno but is called " + p.first_name + " instead.", p.first_name.is_equal ("Berno"))
162 assert ("The person in result is supposed to own 5 items but owns " + p.items_owned.out + " instead.", p.items_owned = 5)
163 end
164
165 test_query_one_result_two_agent_criteria_ored
166 -- Test a query using agent `items_greater_than' ored with agent `first_name_matches'. One result expected.
167 local
168 p: PERSON
169 q: PS_OBJECT_QUERY [PERSON]
170 do
171 create q.make
172 q.set_criterion (factory [[agent p_dao.items_less_than(?, 3)]] or factory [[agent p_dao.items_greater_than(?, 5)]])
173 person_executor.execute_query (q)
174 --assert ("The result list has " + q.matched.count.out + " items instead of 1.", q.matched.count = 1)
175 assert ("The result list is empty", not q.result_cursor.after)
176 p := q.result_cursor.item
177 q.result_cursor.forth
178 assert ("The result list has more than one item", q.result_cursor.after)
179
180 assert ("The person in result is supposed to be called Dumbo but is called " + p.first_name + " instead.", p.first_name.is_equal ("Dumbo"))
181 assert ("The person in result is supposed to own 2 items but owns " + p.items_owned.out + " instead.", p.items_owned = 2)
182 end
183 -- Tests with predefined criteria and projection
184
185 test_criteria_predefined
186 -- all tests with predefined criteria and projections combined
187 do
188 test_query_one_result_greater_than
189 test_query_one_result_equals_to
190 test_query_one_result_like_string
191 test_query_no_result_like_string
192 test_query_four_results_like_string
193 test_query_many_results_two_criteria_anded
194 test_query_many_results_two_criteria_ored
195 end
196
197 test_query_one_result_greater_than
198 -- Test a query using criterion greater_than. One result expected.
199 local
200 query: PS_OBJECT_QUERY [PERSON]
201 p: PERSON
202 do
203 create query.make
204 --query.set_projection (<<"first_name", "last_name", "items_owned">>)
205 query.set_criterion (factory [["items_owned", factory.greater, 3]])
206 person_executor.execute_query (query)
207 --assert ("The result list has " + query.matched.count.out + " items instead of 1.", query.matched.count = 1)
208 assert ("The result list is empty", not query.result_cursor.after)
209 p := query.result_cursor.item
210 query.result_cursor.forth
211 assert ("The result list has more than one item", query.result_cursor.after)
212
213 assert ("The person in result is supposed to own 5 items but owns " + p.items_owned.out + " instead.", p.items_owned = 5)
214 end
215
216 test_query_one_result_equals_to
217 -- Test a query using criterion equals_to. One result expected.
218 local
219 query: PS_OBJECT_QUERY [PERSON]
220 p: PERSON
221 do
222 create query.make
223 --query.set_projection (<<"first_name", "items_owned">>)
224 query.set_criterion (factory [["items_owned", factory.equals, 5]])
225 person_executor.execute_query (query)
226 --assert ("The result list has " + query.matched.count.out + " items instead of 1.", query.matched.count = 1)
227 assert ("The result list is empty", not query.result_cursor.after)
228 p := query.result_cursor.item
229 query.result_cursor.forth
230 assert ("The result list has more than one item", query.result_cursor.after)
231
232 assert ("The person in result is supposed to own 5 items but owns " + p.items_owned.out + " instead.", p.items_owned = 5)
233 end
234
235 test_query_no_result_like_string
236 -- Test a query using criterion equals_to. One result expected.
237 local
238 query: PS_OBJECT_QUERY [PERSON]
239 p: PERSON
240 do
241 create query.make
242 query.set_criterion (factory [["first_name", factory.like_string, "*lb*"]] and factory[["last_name", factory.like_string, "it*ssi"]])
243 person_executor.execute_query (query)
244 assert ("The result list is not empty, but it should be.", query.result_cursor.after)
245 end
246
247 test_query_one_result_like_string
248 -- Test a query using criterion equals_to. One result expected.
249 local
250 query: PS_OBJECT_QUERY [PERSON]
251 p: PERSON
252 do
253 create query.make
254 query.set_criterion (factory [["first_name", factory.like_string, "*lb*"]] and factory[["last_name", factory.like_string, "*?ssi"]])
255 person_executor.execute_query (query)
256 assert ("The result list is empty", not query.result_cursor.after)
257 p := query.result_cursor.item
258 query.result_cursor.forth
259 assert ("The result list has more than one item", query.result_cursor.after)
260
261 assert ("The person in result is supposed to own 3 items but owns " + p.items_owned.out + " instead.", p.items_owned = 3)
262 end
263
264 test_query_four_results_like_string
265 -- Test a query using criterion equals_to. One result expected.
266 local
267 query: PS_OBJECT_QUERY [PERSON]
268 p1: PERSON
269 p2: PERSON
270 p3: PERSON
271 p4: PERSON
272 sum:INTEGER
273 do
274 create query.make
275 query.set_criterion (factory [["last_name", factory.like_string, "*i"]])
276 person_executor.execute_query (query)
277 assert ("The result list is empty", not query.result_cursor.after)
278 p1 := query.result_cursor.item
279 query.result_cursor.forth
280 assert ("The result list only has one item, but it should have 4", not query.result_cursor.after)
281 p2:= query.result_cursor.item
282 query.result_cursor.forth
283 assert ("The result list only has two items, but it should have 4", not query.result_cursor.after)
284 p3:= query.result_cursor.item
285 query.result_cursor.forth
286 assert ("The result list only has three items, but it should have 4", not query.result_cursor.after)
287 p4:= query.result_cursor.item
288 query.result_cursor.forth
289 assert ("The result list has more than four items", query.result_cursor.after)
290 sum:= p1.items_owned + p2.items_owned + p3.items_owned + p4.items_owned
291 assert ("The person in result is supposed to own 13 items but owns " + sum.out + " instead.", sum = 13)
292 end
293
294 test_query_many_results_two_criteria_anded
295 -- Test a query using two criteria anded.
296 local
297 query: PS_OBJECT_QUERY [PERSON]
298 p1: PERSON
299 p2: PERSON
300 do
301 create query.make
302 --query.set_projection (<<"last_name", "items_owned">>)
303 query.set_criterion (factory [["items_owned", ">", 2]] and factory [["items_owned", factory.less, 5]])
304 person_executor.execute_query (query)
305 --assert ("The result list has " + query.matched.count.out + " items instead of 2.", query.matched.count = 2)
306 assert ("The result list is empty", not query.result_cursor.after)
307 p1 := query.result_cursor.item
308 query.result_cursor.forth
309 p2 := query.result_cursor.item
310 query.result_cursor.forth
311 assert ("The result list has more than two item", query.result_cursor.after)
312
313 assert ("The sum of the items owned by the retrieved persons is supposed to be 6 items but is " + (p1.items_owned + p2.items_owned).out + " instead.", p1.items_owned + p2.items_owned = 6)
314 end
315
316 test_query_many_results_two_criteria_ored
317 -- Test a query using two criteria ored.
318 local
319 query: PS_OBJECT_QUERY [PERSON]
320 p1: PERSON
321 p2: PERSON
322 do
323 create query.make
324 --query.set_projection (<<"last_name", "items_owned">>)
325 query.set_criterion (factory [["items_owned", ">", 3]] or factory [["items_owned", factory.less, 3]])
326 person_executor.execute_query (query)
327 --assert ("The result list has " + query.matched.count.out + " items instead of 2.", query.matched.count = 2)
328 assert ("The result list is empty", not query.result_cursor.after)
329 p1 := query.result_cursor.item
330 query.result_cursor.forth
331 p2 := query.result_cursor.item
332 query.result_cursor.forth
333 assert ("The result list has more than two item", query.result_cursor.after)
334
335 assert ("The sum of the items owned by the retrieved persons is supposed to be 7 items but is " + (p1.items_owned + p2.items_owned).out + " instead.", p1.items_owned + p2.items_owned = 7)
336 end
337
338 test_criteria_agents_and_predefined
339 -- all tests with predefined and agent criteria combined
340 do
341 test_query_many_results_three_mixed_criteria
342 end
343
344 test_query_many_results_three_mixed_criteria
345 -- Test a query using theree criteria, two predefined and one using an agent.
346 local
347 query: PS_OBJECT_QUERY [PERSON]
348 p1, p2: PERSON
349 do
350 create query.make
351 --query.set_projection (<<"last_name", "items_owned">>)
352 query.set_criterion (factory [["items_owned", factory.greater, 3]] or factory [["items_owned", factory.less, 3]] and factory [[agent p_dao.items_equal_to(?, 2)]])
353 person_executor.execute_query (query)
354 --assert ("The result list has " + query.matched.count.out + " items instead of 2.", query.matched.count = 2)
355 assert ("The result list is empty", not query.result_cursor.after)
356 p1 := query.result_cursor.item
357 query.result_cursor.forth
358 p2 := query.result_cursor.item
359 query.result_cursor.forth
360 assert ("The result list has more than two item", query.result_cursor.after)
361
362 assert ("The sum of the items owned by the retrieved persons is supposed to be 7 items but is " + (p1.items_owned + p2.items_owned).out + " instead.", p1.items_owned + p2.items_owned = 7)
363 end
364
365 feature {NONE} -- Initialization
366
367 initialize (rep: PS_REPOSITORY)
368 -- make sure this function is called when redefining onCreate
369 do
370 repository := rep
371 create factory
372 create test_data.make
373 create person_executor.make_with_repository (repository)
374 across
375 test_data.people as p
376 loop
377 person_executor.insert (p.item)
378 end
379 create p_dao
380 create tuple_query.make
381 --across tuple_query.projection as proj loop print (proj.item) end
382 end
383
384 factory: PS_CRITERION_FACTORY
385
386 repository: PS_REPOSITORY
387
388 test_data: PS_TEST_DATA
389
390 person_executor: PS_CRUD_EXECUTOR [PERSON]
391
392 p_dao: PERSON_DAO
393
394 tuple_query: PS_TUPLE_QUERY [PERSON]
395
396 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23