comparison testing/utp_1.1/utps/ao/utp_ao_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 7d2e2e065cf1
comparison
equal deleted inserted replaced
43:bc767aaa99a8 44:409a22968d5e
1 % UTP_AO_SUBMIT a set of UTPs for the ao/submit method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_submit.m,v 1.15 2010/08/18 09:25:55 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The bsubmit method of the ao class submits a collection of objects in XML
11 % form to an LTPDA Repository. The type of the objects are independent.
12 %
13 % </MethodDescription>
14
15 function results = utp_ao_submit(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'ao';
22 mthd = 'submit';
23
24 results = [];
25 disp('******************************************************');
26 disp(['**** Running UTPs for ' class '/' mthd]);
27 disp('******************************************************');
28
29 [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao;
30 plForAutoTest = plist('no dialog', true, 'use selector', false);
31
32 connPl = utpGetConnectionPlist();
33 rm = LTPDARepositoryManager();
34 conn = rm.getConnection(connPl);
35 try
36
37 experiment_title = 'utp_ao_submit: submit ao';
38 experiment_description = 'utp_ao_submit: description';
39 analysis_description = '<utp_ao_submit>';
40 quantity = 'none';
41 keywords = 'none';
42 reference_ids = '';
43 additional_comments = 'none';
44 additional_authors = 'no one';
45
46 plsinfo = plist(...
47 'experiment title', experiment_title, ...
48 'experiment description', experiment_description, ...
49 'analysis description', analysis_description, ...
50 'quantity', quantity, ...
51 'keywords', keywords, ...
52 'reference ids', reference_ids, ...
53 'additional comments', additional_comments, ...
54 'additional authors', additional_authors);
55
56 % Exception list for the UTPs:
57 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
58
59 % Run the tests
60 results = [results utp_01]; % getInfo call
61 results = [results utp_02]; % Vector input
62 results = [results utp_03]; % Matrix input
63 results = [results utp_04]; % List input
64 results = [results utp_05]; % Test with mixed input
65 results = [results utp_06]; % Test history is working
66 results = [results utp_07]; % Test output of the data
67 catch
68 end
69
70 disp('Done.');
71 disp('******************************************************');
72
73 elseif nargin == 1 % Check for UTP functions
74 if strcmp(varargin{1}, 'isutp')
75 results = 1;
76 elseif strcmpi(varargin{1}, 'needs repository')
77 results = 2;
78 else
79 results = 0;
80 end
81 else
82 error('### Incorrect inputs')
83 end
84
85 %% UTP_01
86
87 % <TestDescription>
88 %
89 % Tests that the getInfo call works for this method.
90 %
91 % </TestDescription>
92 function result = utp_01
93
94
95 % <SyntaxDescription>
96 %
97 % Test that the getInfo call works for no sets, all sets, and each set
98 % individually.
99 %
100 % </SyntaxDescription>
101
102 try
103 % <SyntaxCode>
104 % Call for no sets
105 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
106 % Call for all sets
107 io(2) = eval([class '.getInfo(''' mthd ''')']);
108 % Call for each set
109 for kk=1:numel(io(2).sets)
110 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
111 end
112 % </SyntaxCode>
113 stest = true;
114 catch err
115 disp(err.message)
116 stest = false;
117 end
118
119 % <AlgoDescription>
120 %
121 % 1) Check that getInfo call returned an minfo object in all cases.
122 % 2) Check that all plists have the correct parameters.
123 %
124 % </AlgoDescription>
125
126 atest = true;
127 if stest
128 % <AlgoCode>
129 % check we have minfo objects
130 if isa(io, 'minfo')
131 prefs = getappdata(0, 'LTPDApreferences');
132 hosts = utils.helper.jArrayList2CellArray(prefs.getRepoPrefs.getHostnames());
133 % SET 'None'
134 if ~isempty(io(1).sets), atest = false; end
135 if ~isempty(io(1).plists), atest = false; end
136 % Check all Sets
137 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
138 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
139 % SET 'Default'
140 % Check key
141 if io(3).plists.nparams ~= 16, atest = false; end
142 if ~io(3).plists.isparam('hostname'), atest = false; end
143 if ~io(3).plists.isparam('database'), atest = false; end
144 if ~io(3).plists.isparam('username'), atest = false; end
145 if ~io(3).plists.isparam('password'), atest = false; end
146 if ~io(3).plists.isparam('experiment title'), atest = false; end
147 if ~io(3).plists.isparam('experiment description'), atest = false; end
148 if ~io(3).plists.isparam('analysis description'), atest = false; end
149 if ~io(3).plists.isparam('quantity'), atest = false; end
150 if ~io(3).plists.isparam('keywords'), atest = false; end
151 if ~io(3).plists.isparam('reference ids'), atest = false; end
152 if ~io(3).plists.isparam('additional comments'), atest = false; end
153 if ~io(3).plists.isparam('additional authors'), atest = false; end
154 if ~io(3).plists.isparam('no dialog'), atest = false; end
155 if ~io(3).plists.isparam('use selector'), atest = false; end
156 if ~io(3).plists.isparam('sinfo filename'), atest = false; end
157 if ~io(3).plists.isparam('binary'), atest = false; end
158 % Check default value
159 if ~isequal(io(3).plists.find('hostname'), hosts{1}), atest = false; end
160 if ~isEmptyChar(io(3).plists.find('database')), atest = false; end
161 if ~isEmptyChar(io(3).plists.find('username')), atest = false; end
162 if ~isEmptyChar(io(3).plists.find('password')), atest = false; end
163 if ~isEmptyChar(io(3).plists.find('experiment title')), atest = false; end
164 if ~isEmptyChar(io(3).plists.find('experiment description')), atest = false; end
165 if ~isEmptyChar(io(3).plists.find('analysis description')), atest = false; end
166 if ~isEmptyChar(io(3).plists.find('quantity')), atest = false; end
167 if ~isEmptyChar(io(3).plists.find('keywords')), atest = false; end
168 if ~isEmptyChar(io(3).plists.find('reference ids')), atest = false; end
169 if ~isEmptyChar(io(3).plists.find('additional comments')), atest = false; end
170 if ~isEmptyChar(io(3).plists.find('additional authors')), atest = false; end
171 if ~isequal(io(3).plists.find('no dialog'), false), atest = false; end
172 if ~isequal(io(3).plists.find('use selector'), true), atest = false; end
173 if ~isEmptyChar(io(3).plists.find('sinfo filename')), atest = false; end
174 if ~isequal(io(3).plists.find('binary'), false), atest = false; end
175 end
176 % </AlgoCode>
177 else
178 atest = false;
179 end
180
181 % Return a result structure
182 result = utp_prepare_result(atest, stest, dbstack, mfilename);
183 end % END UTP_01
184
185 %% UTP_02
186
187 % <TestDescription>
188 %
189 % Tests that the submit method works with a vector of AOs as input.
190 %
191 % </TestDescription>
192 function result = utp_02
193
194 % <SyntaxDescription>
195 %
196 % Test that the submit method works for a vector of AOs as input.
197 %
198 % </SyntaxDescription>
199
200 try
201 % <SyntaxCode>
202 [ids, cids] = submit(atvec, connPl, plsinfo, plForAutoTest);
203 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids);
204 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids);
205 robjs3 = ltpda_uo.retrieve(conn, 'binary', ids(1), ids(2), ids(3));
206 % </SyntaxCode>
207 stest = true;
208 catch err
209 disp(err.message)
210 stest = false;
211 end
212
213 % <AlgoDescription>
214 %
215 % 1) Check the number of retrieved objects.
216 % 2) Check that the retrieved object is the same as the submitted
217 %
218 % </AlgoDescription>
219
220 atest = true;
221 if stest
222 % <AlgoCode>
223 % Check we have the correct number of outputs
224 if numel(robjs1) ~= numel(atvec), atest = false; end
225 if numel(robjs2) ~= numel(atvec), atest = false; end
226 if numel(robjs3) ~= numel(atvec), atest = false; end
227 % Check the retrieved object against the submitted
228 if ~eq(atvec, [robjs1{:}]), atest = false; end
229 if ~eq(atvec, [robjs2{:}]), atest = false; end
230 if ~eq(atvec, [robjs3{:}]), atest = false; end
231 % </AlgoCode>
232 else
233 atest = false;
234 end
235
236 % Return a result structure
237 result = utp_prepare_result(atest, stest, dbstack, mfilename);
238 end % END UTP_02
239
240 %% UTP_03
241
242 % <TestDescription>
243 %
244 % Tests that the submit method works with a matrix of AOs as input.
245 %
246 % </TestDescription>
247 function result = utp_03
248
249 % <SyntaxDescription>
250 %
251 % Tests that the submit method works with a matrix of AOs as input.
252 %
253 % </SyntaxDescription>
254
255 try
256 % <SyntaxCode>
257 [ids, cids] = submit(atmat, connPl, plsinfo, plForAutoTest);
258 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids);
259 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids);
260 robjs3 = ltpda_uo.retrieve(conn, 'binary', ids(1), ids(2), ids(3), ids(4), ids(5), ids(6));
261 % </SyntaxCode>
262 stest = true;
263 catch err
264 disp(err.message)
265 stest = false;
266 end
267
268 % <AlgoDescription>
269 %
270 % 1) Check the number of retrieved objects.
271 % 2) Check that the retrieved object is the same as the submitted
272 %
273 % </AlgoDescription>
274
275 atest = true;
276 if stest
277 % <AlgoCode>
278 % Check we have the correct number of outputs
279 if numel(robjs1) ~= numel(atmat), atest = false; end
280 if numel(robjs2) ~= numel(atmat), atest = false; end
281 if numel(robjs3) ~= numel(atmat), atest = false; end
282 % Check the retrieved object against the submitted
283 if ~eq(atmat, reshape([robjs1{:}], size(atmat))), atest = false; end
284 if ~eq(atmat, reshape([robjs2{:}], size(atmat))), atest = false; end
285 if ~eq(atmat, reshape([robjs3{:}], size(atmat))), atest = false; end
286 % </AlgoCode>
287 else
288 atest = false;
289 end
290
291 % Return a result structure
292 result = utp_prepare_result(atest, stest, dbstack, mfilename);
293 end % END UTP_03
294
295 %% UTP_04
296
297 % <TestDescription>
298 %
299 % Tests that the submit method works with a list of AOs as input.
300 %
301 % </TestDescription>
302 function result = utp_04
303
304 % <SyntaxDescription>
305 %
306 % Tests that the submit method works with a list of AOs as input. Use
307 % for this a mix of different object types.
308 %
309 % </SyntaxDescription>
310
311 try
312 % <SyntaxCode>
313 pl = smodel('a');
314 iir = miir(plist('type', 'highpass'));
315 [ids, cids] = submit(at1, pl, iir, connPl, plsinfo, plForAutoTest);
316 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids);
317 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids);
318 robjs3 = ltpda_uo.retrieve(conn, 'binary', ids(1), ids(2), ids(3));
319 % </SyntaxCode>
320 stest = true;
321 catch err
322 disp(err.message)
323 stest = false;
324 end
325
326 % <AlgoDescription>
327 %
328 % 1) Check the number of retrieved objects.
329 % 2) Check that the retrieved object is the same as the submitted
330 %
331 % </AlgoDescription>
332
333 atest = true;
334 if stest
335 % <AlgoCode>
336 % Check we have the correct number of outputs
337 if numel(robjs1) ~= 3, atest = false; end
338 if numel(robjs2) ~= 3, atest = false; end
339 if numel(robjs3) ~= 3, atest = false; end
340 % Check the retrieved object against the submitted
341 % Check robjs1
342 if ~eq(robjs1{1}, at1), atest = false; end
343 if ~eq(robjs1{2}, pl), atest = false; end
344 if ~eq(robjs1{3}, iir), atest = false; end
345 % Check robjs2
346 if ~eq(robjs2{1}, at1), atest = false; end
347 if ~eq(robjs2{2}, pl), atest = false; end
348 if ~eq(robjs2{3}, iir), atest = false; end
349 % Check robjs3
350 if ~eq(robjs3{1}, at1), atest = false; end
351 if ~eq(robjs3{2}, pl), atest = false; end
352 if ~eq(robjs3{3}, iir), atest = false; end
353 % </AlgoCode>
354 else
355 atest = false;
356 end
357
358 % Return a result structure
359 result = utp_prepare_result(atest, stest, dbstack, mfilename);
360 end % END UTP_04
361
362 %% UTP_05
363
364 % <TestDescription>
365 %
366 % Tests that the abs method works with a mix of different shaped AO
367 % objects as input.
368 %
369 % </TestDescription>
370 function result = utp_05
371
372 % <SyntaxDescription>
373 %
374 % Tests that the submit method works with a list of AOs as input. Use
375 % for this a mix of different object types.
376 %
377 % </SyntaxDescription>
378
379 try
380 % <SyntaxCode>
381 pl = smodel('a+b');
382 iir = miir(plist('type', 'highpass'));
383 [ids, cids] = submit(pl, atmat, iir, atvec, connPl, plsinfo, plForAutoTest);
384 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids);
385 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids);
386 % </SyntaxCode>
387 stest = true;
388 catch err
389 disp(err.message)
390 stest = false;
391 end
392
393 % <AlgoDescription>
394 %
395 % 1) Check the number of retrieved objects.
396 % 2) Check that the retrieved object is the same as the submitted
397 %
398 % </AlgoDescription>
399
400 atest = true;
401 if stest
402 % <AlgoCode>
403 % Check we have the correct number of outputs
404 if numel(robjs1) ~= 2 + numel(atmat) + numel(atvec), atest = false; end
405 if numel(robjs2) ~= 2 + numel(atmat) + numel(atvec), atest = false; end
406 % Check the retrieved object against the submitted
407 % Check robjs1
408 if ~eq(robjs1{1}, pl), atest = false; end
409 if ~eq(robjs1{2}, atmat(1)), atest = false; end
410 if ~eq(robjs1{3}, atmat(2)), atest = false; end
411 if ~eq(robjs1{4}, atmat(3)), atest = false; end
412 if ~eq(robjs1{5}, atmat(4)), atest = false; end
413 if ~eq(robjs1{6}, atmat(5)), atest = false; end
414 if ~eq(robjs1{7}, atmat(6)), atest = false; end
415 if ~eq(robjs1{8}, iir), atest = false; end
416 if ~eq(robjs1{9}, atvec(1)), atest = false; end
417 if ~eq(robjs1{10}, atvec(2)), atest = false; end
418 if ~eq(robjs1{11}, atvec(3)), atest = false; end
419 % Check robjs2
420 if ~isequalwithequalnans(robjs1, robjs2), atest = false; 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(at1, at2, connPl, plsinfo, plForAutoTest);
493
494 [o1, o2] = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids);
495 o3 = ltpda_uo.retrieve(conn, 'binary', '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, at1), atest = false; end
518 if ~eq(o2, at2), atest = false; end
519 if ~eq(o3{1}, at1), atest = false; end
520 if ~eq(o3{2}, at2), 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