comparison testing/utp_1.1/utps/plist/utp_plist_submit.m @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents
children
comparison
equal deleted inserted replaced
43:bc767aaa99a8 44:409a22968d5e
1 % UTP_PLIST_SUBMIT a set of UTPs for the plist/submit method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_plist_submit.m,v 1.14 2010/08/18 09:25:55 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The bsubmit method of the plist class submits a collection of objects
11 % in XML form to an LTPDA Repository. The type of the objects are
12 % independent.
13 %
14 % </MethodDescription>
15
16 function results = utp_plist_submit(varargin)
17
18 % Check the inputs
19 if nargin == 0
20
21 % Some keywords
22 class = 'plist';
23 mthd = 'submit';
24
25 results = [];
26 disp('******************************************************');
27 disp(['**** Running UTPs for ' class '/' mthd]);
28 disp('******************************************************');
29
30 [pl1, pl2, pl3, pl4, plv, plm] = get_test_objects_plist;
31 plForAutoTest = plist('no dialog', true, 'use selector', false);
32
33 try
34 conn = utpGetConnection();
35
36 sinfo.conn = conn;
37 sinfo.experiment_title = 'utp_plist_submit: submit plist';
38 sinfo.experiment_description = 'utp_plist_submit: description';
39 sinfo.analysis_description = '<utp_plist_submit>';
40 sinfo.quantity = 'none';
41 sinfo.keywords = 'none';
42 sinfo.reference_ids = '';
43 sinfo.additional_comments = 'none';
44 sinfo.additional_authors = 'no one';
45
46 % Exception list for the UTPs:
47 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
48
49 % Run the tests
50 results = [results utp_01]; % getInfo call
51 results = [results utp_02]; % Vector input
52 results = [results utp_03]; % Matrix input
53 results = [results utp_04]; % List input
54 results = [results utp_05]; % Test with mixed input
55 results = [results utp_06]; % Test history is working
56 results = [results utp_07]; % Test output of the data
57 catch
58 end
59
60 % Close connection
61 utpCloseConnection(conn)
62
63 disp('Done.');
64 disp('******************************************************');
65
66 elseif nargin == 1 % Check for UTP functions
67 if strcmp(varargin{1}, 'isutp')
68 results = 1;
69 elseif strcmpi(varargin{1}, 'needs repository')
70 results = 2;
71 else
72 results = 0;
73 end
74 else
75 error('### Incorrect inputs')
76 end
77
78 %% UTP_01
79
80 % <TestDescription>
81 %
82 % Tests that the getInfo call works for this method.
83 %
84 % </TestDescription>
85 function result = utp_01
86
87
88 % <SyntaxDescription>
89 %
90 % Test that the getInfo call works for no sets, all sets, and each set
91 % individually.
92 %
93 % </SyntaxDescription>
94
95 try
96 % <SyntaxCode>
97 % Call for no sets
98 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
99 % Call for all sets
100 io(2) = eval([class '.getInfo(''' mthd ''')']);
101 % Call for each set
102 for kk=1:numel(io(2).sets)
103 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
104 end
105 % </SyntaxCode>
106 stest = true;
107 catch err
108 disp(err.message)
109 stest = false;
110 end
111
112 % <AlgoDescription>
113 %
114 % 1) Check that getInfo call returned an minfo object in all cases.
115 % 2) Check that all plists have the correct parameters.
116 %
117 % </AlgoDescription>
118
119 atest = true;
120 if stest
121 % <AlgoCode>
122 % check we have minfo objects
123 if isa(io, 'minfo')
124 prefs = getappdata(0, 'LTPDApreferences');
125 hosts = utils.helper.jArrayList2CellArray(prefs.getRepoPrefs.getHostnames());
126 % SET 'None'
127 if ~isempty(io(1).sets), atest = false; end
128 if ~isempty(io(1).plists), atest = false; end
129 % Check all Sets
130 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
131 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
132 % SET 'Default'
133 % Check key
134 if io(3).plists.nparams ~= 16, atest = false; end
135 if ~io(3).plists.isparam('hostname'), atest = false; end
136 if ~io(3).plists.isparam('database'), atest = false; end
137 if ~io(3).plists.isparam('username'), atest = false; end
138 if ~io(3).plists.isparam('password'), atest = false; end
139 if ~io(3).plists.isparam('experiment title'), atest = false; end
140 if ~io(3).plists.isparam('experiment description'), atest = false; end
141 if ~io(3).plists.isparam('analysis description'), atest = false; end
142 if ~io(3).plists.isparam('quantity'), atest = false; end
143 if ~io(3).plists.isparam('keywords'), atest = false; end
144 if ~io(3).plists.isparam('reference ids'), atest = false; end
145 if ~io(3).plists.isparam('additional comments'), atest = false; end
146 if ~io(3).plists.isparam('additional authors'), atest = false; end
147 if ~io(3).plists.isparam('no dialog'), atest = false; end
148 if ~io(3).plists.isparam('use selector'), atest = false; end
149 if ~io(3).plists.isparam('sinfo filename'), atest = false; end
150 if ~io(3).plists.isparam('binary'), atest = false; end
151 % Check default value
152 if ~isequal(io(3).plists.find('hostname'), hosts{1}), atest = false; end
153 if ~isEmptyChar(io(3).plists.find('database')), atest = false; end
154 if ~isEmptyChar(io(3).plists.find('username')), atest = false; end
155 if ~isEmptyChar(io(3).plists.find('password')), atest = false; end
156 if ~isEmptyChar(io(3).plists.find('experiment title')), atest = false; end
157 if ~isEmptyChar(io(3).plists.find('experiment description')), atest = false; end
158 if ~isEmptyChar(io(3).plists.find('analysis description')), atest = false; end
159 if ~isEmptyChar(io(3).plists.find('quantity')), atest = false; end
160 if ~isEmptyChar(io(3).plists.find('keywords')), atest = false; end
161 if ~isEmptyChar(io(3).plists.find('reference ids')), atest = false; end
162 if ~isEmptyChar(io(3).plists.find('additional comments')), atest = false; end
163 if ~isEmptyChar(io(3).plists.find('additional authors')), atest = false; end
164 if ~isequal(io(3).plists.find('no dialog'), false), atest = false; end
165 if ~isequal(io(3).plists.find('use selector'), true), atest = false; end
166 if ~isEmptyChar(io(3).plists.find('sinfo filename')), atest = false; end
167 if ~isequal(io(3).plists.find('binary'), false), atest = false; end
168 end
169 % </AlgoCode>
170 else
171 atest = false;
172 end
173
174 % Return a result structure
175 result = utp_prepare_result(atest, stest, dbstack, mfilename);
176 end % END UTP_01
177
178 %% UTP_02
179
180 % <TestDescription>
181 %
182 % Tests that the submit method works with a vector of PLIST objects as
183 % input.
184 %
185 % </TestDescription>
186 function result = utp_02
187
188 % <SyntaxDescription>
189 %
190 % Test that the submit method works for a vector of PLIST objects as
191 % input.
192 %
193 % </SyntaxDescription>
194
195 try
196 % <SyntaxCode>
197 [ids, cids] = submit(plv, sinfo, plForAutoTest);
198 robjs1 = ltpda_uo.retrieve(conn, 'Collection', cids);
199 robjs2 = ltpda_uo.retrieve(conn, ids);
200 robjs3 = ltpda_uo.retrieve(conn, ids(1), ids(2), ids(3));
201 % </SyntaxCode>
202 stest = true;
203 catch err
204 disp(err.message)
205 stest = false;
206 end
207
208 % <AlgoDescription>
209 %
210 % 1) Check the number of retrieved objects.
211 % 2) Check that the retrieved object is the same as the submitted
212 %
213 % </AlgoDescription>
214
215 atest = true;
216 if stest
217 % <AlgoCode>
218 % Check we have the correct number of outputs
219 if numel(robjs1) ~= numel(plv), atest = false; end
220 if numel(robjs2) ~= numel(plv), atest = false; end
221 if numel(robjs3) ~= numel(plv), atest = false; end
222 % Check the retrieved object against the submitted
223 if ~eq(plv, [robjs1{:}]), atest = false; end
224 if ~eq(plv, [robjs2{:}]), atest = false; end
225 if ~eq(plv, [robjs3{:}]), atest = false; end
226 % </AlgoCode>
227 else
228 atest = false;
229 end
230
231 % Return a result structure
232 result = utp_prepare_result(atest, stest, dbstack, mfilename);
233 end % END UTP_02
234
235 %% UTP_03
236
237 % <TestDescription>
238 %
239 % Tests that the submit method works with a matrix of PLIST objects as
240 % input.
241 %
242 % </TestDescription>
243 function result = utp_03
244
245 % <SyntaxDescription>
246 %
247 % Tests that the submit method works with a matrix of PLIST objects
248 % as input.
249 %
250 % </SyntaxDescription>
251
252 try
253 % <SyntaxCode>
254 [ids, cids] = submit(plm, sinfo, plForAutoTest);
255 robjs1 = ltpda_uo.retrieve(conn, 'Collection', cids);
256 robjs2 = ltpda_uo.retrieve(conn, ids);
257 robjs3 = ltpda_uo.retrieve(conn, ids(1), ids(2), ids(3), ids(4), ids(5), ids(6));
258 % </SyntaxCode>
259 stest = true;
260 catch err
261 disp(err.message)
262 stest = false;
263 end
264
265 % <AlgoDescription>
266 %
267 % 1) Check the number of retrieved objects.
268 % 2) Check that the retrieved object is the same as the submitted
269 %
270 % </AlgoDescription>
271
272 atest = true;
273 if stest
274 % <AlgoCode>
275 % Check we have the correct number of outputs
276 if numel(robjs1) ~= numel(plm), atest = false; end
277 if numel(robjs2) ~= numel(plm), atest = false; end
278 if numel(robjs3) ~= numel(plm), atest = false; end
279 % Check the retrieved object against the submitted
280 if ~eq(plm, [robjs1{:}]), atest = false; end
281 if ~eq(plm, [robjs2{:}]), atest = false; end
282 if ~eq(plm, [robjs3{:}]), atest = false; end
283 % </AlgoCode>
284 else
285 atest = false;
286 end
287
288 % Return a result structure
289 result = utp_prepare_result(atest, stest, dbstack, mfilename);
290 end % END UTP_03
291
292 %% UTP_04
293
294 % <TestDescription>
295 %
296 % Tests that the submit method works with a list of PLIST objects as
297 % input.
298 %
299 % </TestDescription>
300 function result = utp_04
301
302 % <SyntaxDescription>
303 %
304 % Tests that the submit method works with a list of PLIST objects as
305 % input. Use for this a mix of different object types.
306 %
307 % </SyntaxDescription>
308
309 try
310 % <SyntaxCode>
311 pl = plist('key1', 'val', 'key2', 2);
312 iir = miir(plist('type', 'highpass'));
313 [ids, cids] = submit(pl1, pl, iir, sinfo, plForAutoTest);
314 robjs1 = ltpda_uo.retrieve(conn, 'Collection', cids);
315 robjs2 = ltpda_uo.retrieve(conn, ids);
316 robjs3 = ltpda_uo.retrieve(conn, ids(1), ids(2), ids(3));
317 % </SyntaxCode>
318 stest = true;
319 catch err
320 disp(err.message)
321 stest = false;
322 end
323
324 % <AlgoDescription>
325 %
326 % 1) Check the number of retrieved objects.
327 % 2) Check that the retrieved object is the same as the submitted
328 %
329 % </AlgoDescription>
330
331 atest = true;
332 if stest
333 % <AlgoCode>
334 % Check we have the correct number of outputs
335 if numel(robjs1) ~= 3, atest = false; end
336 if numel(robjs2) ~= 3, atest = false; end
337 if numel(robjs3) ~= 3, atest = false; end
338 % Check the retrieved object against the submitted
339 % Check robjs1
340 if ~eq(robjs1{2}, pl1), atest = false; end
341 if ~eq(robjs1{3}, pl), atest = false; end
342 if ~eq(robjs1{1}, iir), atest = false; end
343 % Check robjs2
344 if ~eq(robjs2{2}, pl1), atest = false; end
345 if ~eq(robjs2{3}, pl), atest = false; end
346 if ~eq(robjs2{1}, iir), atest = false; end
347 % Check robjs3
348 if ~eq(robjs3{2}, pl1), atest = false; end
349 if ~eq(robjs3{3}, pl), atest = false; end
350 if ~eq(robjs3{1}, iir), atest = false; end
351 % </AlgoCode>
352 else
353 atest = false;
354 end
355
356 % Return a result structure
357 result = utp_prepare_result(atest, stest, dbstack, mfilename);
358 end % END UTP_04
359
360 %% UTP_05
361
362 % <TestDescription>
363 %
364 % Tests that the abs method works with a mix of different shaped PLIST
365 % objects as input.
366 %
367 % </TestDescription>
368 function result = utp_05
369
370 % <SyntaxDescription>
371 %
372 % Tests that the submit method works with a list of PLIST objects as
373 % input. Use for this a mix of different object types.
374 %
375 % </SyntaxDescription>
376
377 try
378 % <SyntaxCode>
379 pl = plist('key1', 'val', 'key2', 2);
380 iir = miir(plist('type', 'highpass'));
381 [ids, cids] = submit(pl, plm, iir, plv, sinfo, plForAutoTest);
382 robjs1 = ltpda_uo.retrieve(conn, 'Collection', cids);
383 robjs2 = ltpda_uo.retrieve(conn, ids);
384 % </SyntaxCode>
385 stest = true;
386 catch err
387 disp(err.message)
388 stest = false;
389 end
390
391 % <AlgoDescription>
392 %
393 % 1) Check the number of retrieved objects.
394 % 2) Check that the retrieved object is the same as the submitted
395 %
396 % </AlgoDescription>
397
398 atest = true;
399 if stest
400 % <AlgoCode>
401 % Check we have the correct number of outputs
402 if numel(robjs1) ~= 2 + numel(plm) + numel(plv), atest = false; end
403 if numel(robjs2) ~= 2 + numel(plm) + numel(plv), atest = false; end
404 % Check the retrieved object against the submitted
405 % Check robjs1
406 if ~eq(robjs1{1}, iir), atest = false; end
407 if ~eq(robjs1{2}, pl), atest = false; end
408 if ~eq(robjs1{3}, plm(1)), atest = false; end
409 if ~eq(robjs1{4}, plm(2)), atest = false; end
410 if ~eq(robjs1{5}, plm(3)), atest = false; end
411 if ~eq(robjs1{6}, plm(4)), atest = false; end
412 if ~eq(robjs1{7}, plm(5)), atest = false; end
413 if ~eq(robjs1{8}, plm(6)), atest = false; end
414 if ~eq(robjs1{9}, plv(1)), atest = false; end
415 if ~eq(robjs1{10}, plv(2)), atest = false; end
416 if ~eq(robjs1{11}, plv(3)), atest = false; end
417 % Check robjs2
418 for ii = 1:numel(robjs2)
419 if ~eq(robjs1{ii}, robjs2{ii}), atest = false; end
420 end
421 % </AlgoCode>
422 else
423 atest = false;
424 end
425
426 % Return a result structure
427 result = utp_prepare_result(atest, stest, dbstack, mfilename);
428 end % END UTP_05
429
430 %% UTP_06
431
432 % <TestDescription>
433 %
434 % Tthe submit method properly applies history.
435 %
436 % </TestDescription>
437 function result = utp_06
438
439 % <SyntaxDescription>
440 %
441 % Tthe submit method properly applies history.
442 %
443 % </SyntaxDescription>
444
445 try
446 % <SyntaxCode>
447 % </SyntaxCode>
448 stest = true;
449 catch err
450 disp(err.message)
451 stest = false;
452 end
453
454 % <AlgoDescription>
455 %
456 % 1) Nothing to test.
457 %
458 % </AlgoDescription>
459
460 atest = true;
461 if stest
462 % <AlgoCode>
463 % </AlgoCode>
464 else
465 atest = false;
466 end
467
468 % Return a result structure
469 result = utp_prepare_result(atest, stest, dbstack, mfilename);
470 end % END UTP_06
471
472 %% UTP_07
473
474 % <TestDescription>
475 %
476 % Check that the submit method pass back the output objects to a list of
477 % output variables or to a single variable.
478 %
479 % </TestDescription>
480 function result = utp_07
481
482 % <SyntaxDescription>
483 %
484 % Call the method with a list of output variables and with a single
485 % output variable. Additionaly check that the rebuild method works on
486 % the output.
487 %
488 % </SyntaxDescription>
489
490 try
491 % <SyntaxCode>
492 [ids, cids] = submit(pl1, pl2, sinfo, plForAutoTest);
493
494 [o1, o2] = ltpda_uo.retrieve(conn, 'Collection', cids);
495 o3 = ltpda_uo.retrieve(conn, 'Collection', cids);
496 % </SyntaxCode>
497 stest = true;
498 catch err
499 disp(err.message)
500 stest = false;
501 end
502
503 % <AlgoDescription>
504 %
505 % 1) Check that the output contains the right number of objects
506 %
507 % </AlgoDescription>
508
509 atest = true;
510 if stest
511 % <AlgoCode>
512 % Check the number of outputs
513 if numel(o1) ~=1, atest = false; end
514 if numel(o2) ~=1, atest = false; end
515 if numel(o3) ~=2, atest = false; end
516 % Check the output
517 if ~eq(o1, pl1), atest = false; end
518 if ~eq(o2, pl2), atest = false; end
519 if ~eq(o3{1}, pl1), atest = false; end
520 if ~eq(o3{2}, pl2), atest = false; end
521 % </AlgoCode>
522 else
523 atest = false;
524 end
525
526 % Return a result structure
527 result = utp_prepare_result(atest, stest, dbstack, mfilename);
528 end % END UTP_07
529
530 end