802 |
21 Jun 05 |
nicklas |
1 |
/* |
802 |
21 Jun 05 |
nicklas |
$Id$ |
802 |
21 Jun 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
802 |
21 Jun 05 |
nicklas |
7 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
802 |
21 Jun 05 |
nicklas |
10 |
|
802 |
21 Jun 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
802 |
21 Jun 05 |
nicklas |
modify it under the terms of the GNU General Public License |
4480 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
802 |
21 Jun 05 |
nicklas |
of the License, or (at your option) any later version. |
802 |
21 Jun 05 |
nicklas |
15 |
|
802 |
21 Jun 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
802 |
21 Jun 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
802 |
21 Jun 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
802 |
21 Jun 05 |
nicklas |
GNU General Public License for more details. |
802 |
21 Jun 05 |
nicklas |
20 |
|
802 |
21 Jun 05 |
nicklas |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
802 |
21 Jun 05 |
nicklas |
23 |
*/ |
802 |
21 Jun 05 |
nicklas |
24 |
import net.sf.basedb.core.*; |
5663 |
22 Jun 11 |
nicklas |
25 |
import net.sf.basedb.core.query.ResultList; |
6775 |
17 Mar 15 |
nicklas |
26 |
import net.sf.basedb.util.listable.BioSourceToSampleTransformer; |
6775 |
17 Mar 15 |
nicklas |
27 |
import net.sf.basedb.util.listable.SampleToBioSourceTransformer; |
6775 |
17 Mar 15 |
nicklas |
28 |
import net.sf.basedb.util.listable.SampleToChildSampleTransformer; |
6775 |
17 Mar 15 |
nicklas |
29 |
import net.sf.basedb.util.listable.SampleToParentSampleTransformer; |
6775 |
17 Mar 15 |
nicklas |
30 |
import net.sf.basedb.util.listable.SourceItemTransformer; |
6775 |
17 Mar 15 |
nicklas |
31 |
import net.sf.basedb.util.listable.TransformContext; |
4366 |
02 Jul 08 |
nicklas |
32 |
|
4712 |
19 Dec 08 |
nicklas |
33 |
import java.util.Collections; |
802 |
21 Jun 05 |
nicklas |
34 |
import java.util.Date; |
5340 |
10 May 10 |
nicklas |
35 |
import java.util.Set; |
802 |
21 Jun 05 |
nicklas |
36 |
|
802 |
21 Jun 05 |
nicklas |
37 |
public class TestSample |
802 |
21 Jun 05 |
nicklas |
38 |
{ |
802 |
21 Jun 05 |
nicklas |
39 |
|
802 |
21 Jun 05 |
nicklas |
40 |
static boolean ok = true; |
802 |
21 Jun 05 |
nicklas |
41 |
public static void main(String[] args) |
802 |
21 Jun 05 |
nicklas |
42 |
{ |
802 |
21 Jun 05 |
nicklas |
43 |
TestUtil.checkArgs(args); |
802 |
21 Jun 05 |
nicklas |
44 |
TestUtil.begin(); |
802 |
21 Jun 05 |
nicklas |
45 |
ok = test_all(); |
802 |
21 Jun 05 |
nicklas |
46 |
TestUtil.stop(); |
802 |
21 Jun 05 |
nicklas |
47 |
} |
802 |
21 Jun 05 |
nicklas |
48 |
|
802 |
21 Jun 05 |
nicklas |
49 |
static boolean test_all() |
802 |
21 Jun 05 |
nicklas |
50 |
{ |
802 |
21 Jun 05 |
nicklas |
51 |
write("++Testing samples"); |
802 |
21 Jun 05 |
nicklas |
52 |
write_header(); |
802 |
21 Jun 05 |
nicklas |
// Standard tests: create, load, list |
4705 |
16 Dec 08 |
nicklas |
54 |
int bioSourceId = TestBioSource.test_create(null, false); |
6100 |
04 Sep 12 |
nicklas |
55 |
int id = test_create(0, "Sample #1 (standalone)", 0, true); |
6100 |
04 Sep 12 |
nicklas |
56 |
int id2 = test_create(bioSourceId, "Sample #2 (biosource parent)", 0, false); |
6100 |
04 Sep 12 |
nicklas |
57 |
int id3 = test_create(id, "Sample #3 (sample parent)", 0, false); |
5663 |
22 Jun 11 |
nicklas |
58 |
int id4 = test_create_pooled("Sample #4 (pooled)", id, id2, id3); |
802 |
21 Jun 05 |
nicklas |
59 |
|
802 |
21 Jun 05 |
nicklas |
60 |
test_load(id); |
802 |
21 Jun 05 |
nicklas |
61 |
test_list(-1); |
802 |
21 Jun 05 |
nicklas |
62 |
|
817 |
23 Jun 05 |
nicklas |
63 |
write_events_header(); |
817 |
23 Jun 05 |
nicklas |
64 |
test_add_event(id, 100.0f); |
5663 |
22 Jun 11 |
nicklas |
65 |
test_list_events(id, 4); // creation event, create event for id3+id4, and extra event |
817 |
23 Jun 05 |
nicklas |
66 |
|
5663 |
22 Jun 11 |
nicklas |
67 |
write_parents_header(); |
817 |
23 Jun 05 |
nicklas |
68 |
test_list_sources(id4, 3); // The three id, id2 and id3 samples |
5663 |
22 Jun 11 |
nicklas |
69 |
test_list_children(id, 2); // id3 and id4 |
802 |
21 Jun 05 |
nicklas |
70 |
|
5663 |
22 Jun 11 |
nicklas |
// Transformers |
5663 |
22 Jun 11 |
nicklas |
72 |
test_childrenTransformer(id, 2); |
5663 |
22 Jun 11 |
nicklas |
73 |
test_parentsTransformer(id4, 3); |
5663 |
22 Jun 11 |
nicklas |
74 |
test_sampleToBioSourceTransformer(id2, 1); |
5663 |
22 Jun 11 |
nicklas |
75 |
test_bioSourceToSampleTransformer(bioSourceId, 1); |
5663 |
22 Jun 11 |
nicklas |
76 |
|
802 |
21 Jun 05 |
nicklas |
// Standard test: Delete |
1529 |
27 Oct 05 |
nicklas |
78 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
817 |
23 Jun 05 |
nicklas |
79 |
test_delete(id4); |
817 |
23 Jun 05 |
nicklas |
80 |
test_delete(id3); |
817 |
23 Jun 05 |
nicklas |
81 |
test_delete(id2); |
802 |
21 Jun 05 |
nicklas |
82 |
test_delete(id); |
802 |
21 Jun 05 |
nicklas |
83 |
TestBioSource.test_delete(bioSourceId); |
802 |
21 Jun 05 |
nicklas |
84 |
|
802 |
21 Jun 05 |
nicklas |
85 |
write("++Testing samples "+(ok ? "OK" : "Failed")+"\n"); |
802 |
21 Jun 05 |
nicklas |
86 |
return ok; |
802 |
21 Jun 05 |
nicklas |
87 |
} |
802 |
21 Jun 05 |
nicklas |
88 |
|
6100 |
04 Sep 12 |
nicklas |
89 |
static int test_create(int parentId, String name, int subtypeId, boolean setAll) |
802 |
21 Jun 05 |
nicklas |
90 |
{ |
802 |
21 Jun 05 |
nicklas |
91 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.SAMPLE)) return 0; |
802 |
21 Jun 05 |
nicklas |
92 |
int id = 0; |
802 |
21 Jun 05 |
nicklas |
93 |
DbControl dc = null; |
802 |
21 Jun 05 |
nicklas |
94 |
try |
802 |
21 Jun 05 |
nicklas |
95 |
{ |
802 |
21 Jun 05 |
nicklas |
96 |
dc = TestUtil.getDbControl(); |
802 |
21 Jun 05 |
nicklas |
97 |
Sample s = Sample.getNew(dc); |
802 |
21 Jun 05 |
nicklas |
98 |
if (setAll) |
802 |
21 Jun 05 |
nicklas |
99 |
{ |
802 |
21 Jun 05 |
nicklas |
100 |
s.setName("Test sample"); |
802 |
21 Jun 05 |
nicklas |
101 |
s.setDescription("Added at "+new Date()); |
802 |
21 Jun 05 |
nicklas |
102 |
s.setExternalId("XCV-455-SAMPLE"); |
802 |
21 Jun 05 |
nicklas |
103 |
s.setOriginalQuantity(500.0f); |
802 |
21 Jun 05 |
nicklas |
104 |
} |
5663 |
22 Jun 11 |
nicklas |
105 |
if (parentId != 0) |
802 |
21 Jun 05 |
nicklas |
106 |
{ |
5663 |
22 Jun 11 |
nicklas |
107 |
BioMaterial parent = BioMaterial.getById(dc, parentId); |
5663 |
22 Jun 11 |
nicklas |
108 |
s.getCreationEvent().setSource(parent); |
5663 |
22 Jun 11 |
nicklas |
109 |
s.setName(parent.getName() + ".s"); |
802 |
21 Jun 05 |
nicklas |
110 |
} |
4740 |
05 Feb 09 |
nicklas |
111 |
if (name != null) s.setName(name); |
6100 |
04 Sep 12 |
nicklas |
112 |
if (subtypeId != 0) s.setItemSubtype(ItemSubtype.getById(dc, subtypeId)); |
802 |
21 Jun 05 |
nicklas |
113 |
dc.saveItem(s); |
802 |
21 Jun 05 |
nicklas |
114 |
dc.commit(); |
802 |
21 Jun 05 |
nicklas |
115 |
id = s.getId(); |
806 |
22 Jun 05 |
nicklas |
116 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
117 |
dc.reattachItem(s, false); |
802 |
21 Jun 05 |
nicklas |
118 |
write_item(0, s); |
802 |
21 Jun 05 |
nicklas |
119 |
write("--Create sample OK"); |
802 |
21 Jun 05 |
nicklas |
120 |
} |
802 |
21 Jun 05 |
nicklas |
121 |
catch (Throwable ex) |
802 |
21 Jun 05 |
nicklas |
122 |
{ |
802 |
21 Jun 05 |
nicklas |
123 |
write("--Create sample FAILED"); |
802 |
21 Jun 05 |
nicklas |
124 |
ex.printStackTrace(); |
802 |
21 Jun 05 |
nicklas |
125 |
ok = false; |
802 |
21 Jun 05 |
nicklas |
126 |
} |
802 |
21 Jun 05 |
nicklas |
127 |
finally |
802 |
21 Jun 05 |
nicklas |
128 |
{ |
802 |
21 Jun 05 |
nicklas |
129 |
if (dc != null) dc.close(); |
802 |
21 Jun 05 |
nicklas |
130 |
} |
802 |
21 Jun 05 |
nicklas |
131 |
return id; |
802 |
21 Jun 05 |
nicklas |
132 |
} |
802 |
21 Jun 05 |
nicklas |
133 |
|
5663 |
22 Jun 11 |
nicklas |
134 |
static int test_create_pooled(String name, int... sourceIds) |
817 |
23 Jun 05 |
nicklas |
135 |
{ |
817 |
23 Jun 05 |
nicklas |
136 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.SAMPLE)) return 0; |
817 |
23 Jun 05 |
nicklas |
137 |
int id = 0; |
817 |
23 Jun 05 |
nicklas |
138 |
DbControl dc = null; |
817 |
23 Jun 05 |
nicklas |
139 |
try |
817 |
23 Jun 05 |
nicklas |
140 |
{ |
817 |
23 Jun 05 |
nicklas |
141 |
dc = TestUtil.getDbControl(); |
817 |
23 Jun 05 |
nicklas |
142 |
Sample s = Sample.getNew(dc); |
5663 |
22 Jun 11 |
nicklas |
143 |
s.setName(name); |
817 |
23 Jun 05 |
nicklas |
144 |
s.setDescription("Added at "+new Date()); |
817 |
23 Jun 05 |
nicklas |
145 |
s.setExternalId("POOLED-455-SAMPLE"); |
817 |
23 Jun 05 |
nicklas |
146 |
s.setOriginalQuantity(500.0f); |
817 |
23 Jun 05 |
nicklas |
147 |
BioMaterialEvent evt = s.getCreationEvent(); |
817 |
23 Jun 05 |
nicklas |
148 |
for (int sourceId : sourceIds) |
817 |
23 Jun 05 |
nicklas |
149 |
{ |
817 |
23 Jun 05 |
nicklas |
150 |
Sample src = Sample.getById(dc, sourceId); |
817 |
23 Jun 05 |
nicklas |
151 |
Float original = src.getOriginalQuantity(); |
5662 |
20 Jun 11 |
nicklas |
152 |
BioMaterialEventSource eventSource = evt.addSource(src); |
5662 |
20 Jun 11 |
nicklas |
153 |
if (original != null) |
5662 |
20 Jun 11 |
nicklas |
154 |
{ |
5662 |
20 Jun 11 |
nicklas |
155 |
eventSource.setUsedQuantity(original/2); |
5662 |
20 Jun 11 |
nicklas |
156 |
} |
817 |
23 Jun 05 |
nicklas |
157 |
} |
817 |
23 Jun 05 |
nicklas |
158 |
dc.saveItem(s); |
817 |
23 Jun 05 |
nicklas |
159 |
dc.commit(); |
817 |
23 Jun 05 |
nicklas |
160 |
id = s.getId(); |
817 |
23 Jun 05 |
nicklas |
161 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
162 |
dc.reattachItem(s, false); |
817 |
23 Jun 05 |
nicklas |
163 |
write_item(0, s); |
817 |
23 Jun 05 |
nicklas |
164 |
write("--Create pooled sample OK"); |
817 |
23 Jun 05 |
nicklas |
165 |
} |
817 |
23 Jun 05 |
nicklas |
166 |
catch (Throwable ex) |
817 |
23 Jun 05 |
nicklas |
167 |
{ |
817 |
23 Jun 05 |
nicklas |
168 |
write("--Create pooled sample FAILED"); |
817 |
23 Jun 05 |
nicklas |
169 |
ex.printStackTrace(); |
817 |
23 Jun 05 |
nicklas |
170 |
ok = false; |
817 |
23 Jun 05 |
nicklas |
171 |
} |
817 |
23 Jun 05 |
nicklas |
172 |
finally |
817 |
23 Jun 05 |
nicklas |
173 |
{ |
817 |
23 Jun 05 |
nicklas |
174 |
if (dc != null) dc.close(); |
817 |
23 Jun 05 |
nicklas |
175 |
} |
817 |
23 Jun 05 |
nicklas |
176 |
return id; |
817 |
23 Jun 05 |
nicklas |
177 |
} |
817 |
23 Jun 05 |
nicklas |
178 |
|
802 |
21 Jun 05 |
nicklas |
179 |
static void test_load(int id) |
802 |
21 Jun 05 |
nicklas |
180 |
{ |
802 |
21 Jun 05 |
nicklas |
181 |
if (id == 0) return; |
802 |
21 Jun 05 |
nicklas |
182 |
DbControl dc = null; |
802 |
21 Jun 05 |
nicklas |
183 |
try |
802 |
21 Jun 05 |
nicklas |
184 |
{ |
802 |
21 Jun 05 |
nicklas |
185 |
dc = TestUtil.getDbControl(); |
802 |
21 Jun 05 |
nicklas |
186 |
Sample s = Sample.getById(dc, id); |
802 |
21 Jun 05 |
nicklas |
187 |
write_item(0, s); |
802 |
21 Jun 05 |
nicklas |
188 |
write("--Load sample OK"); |
802 |
21 Jun 05 |
nicklas |
189 |
} |
802 |
21 Jun 05 |
nicklas |
190 |
catch (Throwable ex) |
802 |
21 Jun 05 |
nicklas |
191 |
{ |
802 |
21 Jun 05 |
nicklas |
192 |
write("--Load sample FAILED"); |
802 |
21 Jun 05 |
nicklas |
193 |
ex.printStackTrace(); |
802 |
21 Jun 05 |
nicklas |
194 |
ok = false; |
802 |
21 Jun 05 |
nicklas |
195 |
} |
802 |
21 Jun 05 |
nicklas |
196 |
finally |
802 |
21 Jun 05 |
nicklas |
197 |
{ |
802 |
21 Jun 05 |
nicklas |
198 |
if (dc != null) dc.close(); |
802 |
21 Jun 05 |
nicklas |
199 |
} |
802 |
21 Jun 05 |
nicklas |
200 |
} |
802 |
21 Jun 05 |
nicklas |
201 |
|
5696 |
12 Aug 11 |
nicklas |
202 |
static boolean test_list(int expectedResults) |
802 |
21 Jun 05 |
nicklas |
203 |
{ |
802 |
21 Jun 05 |
nicklas |
204 |
DbControl dc = null; |
802 |
21 Jun 05 |
nicklas |
205 |
try |
802 |
21 Jun 05 |
nicklas |
206 |
{ |
802 |
21 Jun 05 |
nicklas |
207 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
208 |
ItemResultList<Sample> l = Sample.getQuery().list(dc); |
802 |
21 Jun 05 |
nicklas |
209 |
for (int i = 0; i<l.size(); i++) |
802 |
21 Jun 05 |
nicklas |
210 |
{ |
802 |
21 Jun 05 |
nicklas |
211 |
write_item(i, l.get(i)); |
802 |
21 Jun 05 |
nicklas |
212 |
} |
802 |
21 Jun 05 |
nicklas |
213 |
if (expectedResults >= 0 && expectedResults != l.size()) |
802 |
21 Jun 05 |
nicklas |
214 |
{ |
802 |
21 Jun 05 |
nicklas |
215 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
802 |
21 Jun 05 |
nicklas |
216 |
} |
802 |
21 Jun 05 |
nicklas |
217 |
write("--List samples OK ("+l.size()+")"); |
802 |
21 Jun 05 |
nicklas |
218 |
} |
802 |
21 Jun 05 |
nicklas |
219 |
catch (Throwable ex) |
802 |
21 Jun 05 |
nicklas |
220 |
{ |
802 |
21 Jun 05 |
nicklas |
221 |
write("--List samples FAILED"); |
802 |
21 Jun 05 |
nicklas |
222 |
ex.printStackTrace(); |
802 |
21 Jun 05 |
nicklas |
223 |
ok = false; |
5696 |
12 Aug 11 |
nicklas |
224 |
return false; |
802 |
21 Jun 05 |
nicklas |
225 |
} |
802 |
21 Jun 05 |
nicklas |
226 |
finally |
802 |
21 Jun 05 |
nicklas |
227 |
{ |
802 |
21 Jun 05 |
nicklas |
228 |
if (dc != null) dc.close(); |
802 |
21 Jun 05 |
nicklas |
229 |
} |
5696 |
12 Aug 11 |
nicklas |
230 |
return true; |
802 |
21 Jun 05 |
nicklas |
231 |
} |
802 |
21 Jun 05 |
nicklas |
232 |
|
802 |
21 Jun 05 |
nicklas |
233 |
static void test_delete(int id) |
802 |
21 Jun 05 |
nicklas |
234 |
{ |
802 |
21 Jun 05 |
nicklas |
235 |
if (id == 0) return; |
802 |
21 Jun 05 |
nicklas |
236 |
DbControl dc = null; |
802 |
21 Jun 05 |
nicklas |
237 |
try |
802 |
21 Jun 05 |
nicklas |
238 |
{ |
802 |
21 Jun 05 |
nicklas |
239 |
dc = TestUtil.getDbControl(); |
802 |
21 Jun 05 |
nicklas |
240 |
Sample s = Sample.getById(dc, id); |
802 |
21 Jun 05 |
nicklas |
241 |
dc.deleteItem(s); |
5340 |
10 May 10 |
nicklas |
242 |
Set<ItemProxy> using = s.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
243 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
244 |
{ |
5340 |
10 May 10 |
nicklas |
245 |
throw new BaseException(s + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
246 |
} |
802 |
21 Jun 05 |
nicklas |
247 |
dc.commit(); |
802 |
21 Jun 05 |
nicklas |
248 |
write("--Delete sample OK"); |
802 |
21 Jun 05 |
nicklas |
249 |
} |
802 |
21 Jun 05 |
nicklas |
250 |
catch (Throwable ex) |
802 |
21 Jun 05 |
nicklas |
251 |
{ |
802 |
21 Jun 05 |
nicklas |
252 |
write("--Delete sample FAILED"); |
802 |
21 Jun 05 |
nicklas |
253 |
ex.printStackTrace(); |
802 |
21 Jun 05 |
nicklas |
254 |
ok = false; |
802 |
21 Jun 05 |
nicklas |
255 |
} |
802 |
21 Jun 05 |
nicklas |
256 |
finally |
802 |
21 Jun 05 |
nicklas |
257 |
{ |
802 |
21 Jun 05 |
nicklas |
258 |
if (dc != null) dc.close(); |
802 |
21 Jun 05 |
nicklas |
259 |
} |
802 |
21 Jun 05 |
nicklas |
260 |
} |
802 |
21 Jun 05 |
nicklas |
261 |
|
4366 |
02 Jul 08 |
nicklas |
262 |
static void test_delete_all() |
4366 |
02 Jul 08 |
nicklas |
263 |
{ |
4366 |
02 Jul 08 |
nicklas |
264 |
DbControl dc = null; |
4366 |
02 Jul 08 |
nicklas |
265 |
try |
4366 |
02 Jul 08 |
nicklas |
266 |
{ |
4366 |
02 Jul 08 |
nicklas |
267 |
dc = TestUtil.getDbControl(); |
4366 |
02 Jul 08 |
nicklas |
268 |
ItemResultList<Sample> l = Sample.getQuery().list(dc); |
5688 |
10 Aug 11 |
nicklas |
269 |
int numDeleted = Trashcan.delete(dc.getSessionControl(), l, true, null); |
5688 |
10 Aug 11 |
nicklas |
270 |
if (numDeleted != l.size()) throw new BaseException("Could not delete all items: " + numDeleted + " of " + l.size()); |
4366 |
02 Jul 08 |
nicklas |
271 |
dc.commit(); |
4366 |
02 Jul 08 |
nicklas |
272 |
write("--Delete all samples OK ("+l.size()+")"); |
4366 |
02 Jul 08 |
nicklas |
273 |
} |
4366 |
02 Jul 08 |
nicklas |
274 |
catch (Throwable ex) |
4366 |
02 Jul 08 |
nicklas |
275 |
{ |
4366 |
02 Jul 08 |
nicklas |
276 |
write("--Delete all samples FAILED"); |
4366 |
02 Jul 08 |
nicklas |
277 |
ex.printStackTrace(); |
4366 |
02 Jul 08 |
nicklas |
278 |
ok = false; |
4366 |
02 Jul 08 |
nicklas |
279 |
} |
4366 |
02 Jul 08 |
nicklas |
280 |
finally |
4366 |
02 Jul 08 |
nicklas |
281 |
{ |
4366 |
02 Jul 08 |
nicklas |
282 |
if (dc != null) dc.close(); |
4366 |
02 Jul 08 |
nicklas |
283 |
} |
4366 |
02 Jul 08 |
nicklas |
284 |
} |
4366 |
02 Jul 08 |
nicklas |
285 |
|
802 |
21 Jun 05 |
nicklas |
286 |
static void write_header() |
802 |
21 Jun 05 |
nicklas |
287 |
{ |
802 |
21 Jun 05 |
nicklas |
288 |
if (!TestUtil.getSilent()) |
802 |
21 Jun 05 |
nicklas |
289 |
{ |
6100 |
04 Sep 12 |
nicklas |
290 |
write(" \tID \tName \tSubtype\tDescription\tExternal id\tParent\tQuantity\tRemain"); |
6100 |
04 Sep 12 |
nicklas |
291 |
write("-- \t-- \t--------- \t-------\t-----------\t-----------\t------\t--------\t------"); |
802 |
21 Jun 05 |
nicklas |
292 |
} |
802 |
21 Jun 05 |
nicklas |
293 |
} |
802 |
21 Jun 05 |
nicklas |
294 |
static void write_item(int i, Sample s) |
802 |
21 Jun 05 |
nicklas |
295 |
throws BaseException |
802 |
21 Jun 05 |
nicklas |
296 |
{ |
6100 |
04 Sep 12 |
nicklas |
297 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+s.getId()+"\t"+s.getName()+"\t"+s.getItemSubtype()+"\t"+s.getDescription()+ |
5663 |
22 Jun 11 |
nicklas |
298 |
"\t"+s.getExternalId()+"\t"+s.getParent()+"\t"+s.getOriginalQuantity()+"\t"+s.getRemainingQuantity()); |
802 |
21 Jun 05 |
nicklas |
299 |
} |
817 |
23 Jun 05 |
nicklas |
300 |
static void write_events_header() |
817 |
23 Jun 05 |
nicklas |
301 |
{ |
817 |
23 Jun 05 |
nicklas |
302 |
if (!TestUtil.getSilent()) |
817 |
23 Jun 05 |
nicklas |
303 |
{ |
817 |
23 Jun 05 |
nicklas |
304 |
write(" \tID \tBiomaterial\tEvent type\tEvent date\tEntry date\tUsed quantity\tComment"); |
817 |
23 Jun 05 |
nicklas |
305 |
write("-- \t-- \t-----------\t----------\t----------\t----------\t-------------\t-------"); |
817 |
23 Jun 05 |
nicklas |
306 |
} |
817 |
23 Jun 05 |
nicklas |
307 |
} |
817 |
23 Jun 05 |
nicklas |
308 |
static void write_item(int i, BioMaterialEvent evt, Sample s) |
817 |
23 Jun 05 |
nicklas |
309 |
throws BaseException |
817 |
23 Jun 05 |
nicklas |
310 |
{ |
817 |
23 Jun 05 |
nicklas |
311 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+evt.getId()+"\t"+evt.getBioMaterial()+"\t"+evt.getEventType()+ |
817 |
23 Jun 05 |
nicklas |
312 |
"\t"+evt.getEventDate()+"\t"+evt.getEntryDate()+"\t"+evt.getUsedQuantity(s)+"\t"+evt.getComment()); |
817 |
23 Jun 05 |
nicklas |
313 |
} |
5663 |
22 Jun 11 |
nicklas |
314 |
|
5663 |
22 Jun 11 |
nicklas |
315 |
static void write_parents_header() |
817 |
23 Jun 05 |
nicklas |
316 |
{ |
817 |
23 Jun 05 |
nicklas |
317 |
if (!TestUtil.getSilent()) |
817 |
23 Jun 05 |
nicklas |
318 |
{ |
5663 |
22 Jun 11 |
nicklas |
319 |
write(" \tID \tName \tDescription\tExternal id\tQuantity\tRemain\tUsed"); |
5663 |
22 Jun 11 |
nicklas |
320 |
write("-- \t-- \t--------- \t-----------\t-----------\t--------\t------\t----"); |
817 |
23 Jun 05 |
nicklas |
321 |
} |
817 |
23 Jun 05 |
nicklas |
322 |
} |
5663 |
22 Jun 11 |
nicklas |
323 |
|
5663 |
22 Jun 11 |
nicklas |
324 |
static void write_item(int i, BioMaterialEventSource evtSrc) |
817 |
23 Jun 05 |
nicklas |
325 |
throws BaseException |
817 |
23 Jun 05 |
nicklas |
326 |
{ |
5663 |
22 Jun 11 |
nicklas |
327 |
if (!TestUtil.getSilent()) |
5663 |
22 Jun 11 |
nicklas |
328 |
{ |
5663 |
22 Jun 11 |
nicklas |
329 |
MeasuredBioMaterial bm = (MeasuredBioMaterial)evtSrc.getBioMaterial(); |
5663 |
22 Jun 11 |
nicklas |
330 |
System.out.println(i+":\t"+bm.getId()+"\t"+bm.getName()+"\t"+bm.getDescription()+ |
5663 |
22 Jun 11 |
nicklas |
331 |
"\t"+bm.getExternalId()+"\t"+"\t"+bm.getOriginalQuantity()+"\t"+bm.getRemainingQuantity()+ |
5663 |
22 Jun 11 |
nicklas |
332 |
"\t"+evtSrc.getUsedQuantity()); |
5663 |
22 Jun 11 |
nicklas |
333 |
} |
817 |
23 Jun 05 |
nicklas |
334 |
} |
817 |
23 Jun 05 |
nicklas |
335 |
|
802 |
21 Jun 05 |
nicklas |
336 |
static void write(String message) |
802 |
21 Jun 05 |
nicklas |
337 |
{ |
802 |
21 Jun 05 |
nicklas |
338 |
System.out.println(message); |
802 |
21 Jun 05 |
nicklas |
339 |
} |
817 |
23 Jun 05 |
nicklas |
340 |
|
817 |
23 Jun 05 |
nicklas |
341 |
static int test_add_event(int sampleId, float usedQuantity) |
817 |
23 Jun 05 |
nicklas |
342 |
{ |
817 |
23 Jun 05 |
nicklas |
343 |
if (sampleId == 0) return 0; |
817 |
23 Jun 05 |
nicklas |
344 |
int eventId = 0; |
817 |
23 Jun 05 |
nicklas |
345 |
DbControl dc = null; |
817 |
23 Jun 05 |
nicklas |
346 |
try |
817 |
23 Jun 05 |
nicklas |
347 |
{ |
817 |
23 Jun 05 |
nicklas |
348 |
dc = TestUtil.getDbControl(); |
817 |
23 Jun 05 |
nicklas |
349 |
Sample s = Sample.getById(dc, sampleId); |
947 |
18 Jul 05 |
nicklas |
350 |
BioMaterialEvent bme = s.newEvent(); |
947 |
18 Jul 05 |
nicklas |
351 |
bme.setUsedQuantity(usedQuantity); |
817 |
23 Jun 05 |
nicklas |
352 |
bme.setComment("Added a new event"); |
817 |
23 Jun 05 |
nicklas |
353 |
dc.saveItem(bme); |
817 |
23 Jun 05 |
nicklas |
354 |
dc.commit(); |
817 |
23 Jun 05 |
nicklas |
355 |
eventId = bme.getId(); |
817 |
23 Jun 05 |
nicklas |
356 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
357 |
dc.reattachItem(bme, false); |
817 |
23 Jun 05 |
nicklas |
358 |
write_item(0, bme, s); |
817 |
23 Jun 05 |
nicklas |
359 |
write("--Add event for sample OK"); |
817 |
23 Jun 05 |
nicklas |
360 |
} |
817 |
23 Jun 05 |
nicklas |
361 |
catch (Throwable ex) |
817 |
23 Jun 05 |
nicklas |
362 |
{ |
817 |
23 Jun 05 |
nicklas |
363 |
write("--Add event for sample FAILED"); |
817 |
23 Jun 05 |
nicklas |
364 |
ex.printStackTrace(); |
817 |
23 Jun 05 |
nicklas |
365 |
ok = false; |
817 |
23 Jun 05 |
nicklas |
366 |
} |
817 |
23 Jun 05 |
nicklas |
367 |
finally |
817 |
23 Jun 05 |
nicklas |
368 |
{ |
817 |
23 Jun 05 |
nicklas |
369 |
if (dc != null) dc.close(); |
817 |
23 Jun 05 |
nicklas |
370 |
} |
817 |
23 Jun 05 |
nicklas |
371 |
return eventId; |
817 |
23 Jun 05 |
nicklas |
372 |
} |
817 |
23 Jun 05 |
nicklas |
373 |
|
817 |
23 Jun 05 |
nicklas |
374 |
static void test_list_events(int sampleId, int expectedResults) |
817 |
23 Jun 05 |
nicklas |
375 |
{ |
817 |
23 Jun 05 |
nicklas |
376 |
if (sampleId == 0) return; |
817 |
23 Jun 05 |
nicklas |
377 |
DbControl dc = null; |
817 |
23 Jun 05 |
nicklas |
378 |
try |
817 |
23 Jun 05 |
nicklas |
379 |
{ |
817 |
23 Jun 05 |
nicklas |
380 |
dc = TestUtil.getDbControl(); |
817 |
23 Jun 05 |
nicklas |
381 |
Sample s = Sample.getById(dc, sampleId); |
1418 |
07 Oct 05 |
nicklas |
382 |
ItemResultList<BioMaterialEvent> l = s.getEvents().list(dc); |
817 |
23 Jun 05 |
nicklas |
383 |
for (int i = 0; i<l.size(); i++) |
817 |
23 Jun 05 |
nicklas |
384 |
{ |
817 |
23 Jun 05 |
nicklas |
385 |
write_item(i, l.get(i), s); |
817 |
23 Jun 05 |
nicklas |
386 |
} |
817 |
23 Jun 05 |
nicklas |
387 |
if (expectedResults >= 0 && expectedResults != l.size()) |
817 |
23 Jun 05 |
nicklas |
388 |
{ |
817 |
23 Jun 05 |
nicklas |
389 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
817 |
23 Jun 05 |
nicklas |
390 |
} |
817 |
23 Jun 05 |
nicklas |
391 |
write("--List events for sample OK ("+l.size()+")"); |
817 |
23 Jun 05 |
nicklas |
392 |
} |
817 |
23 Jun 05 |
nicklas |
393 |
catch (Throwable ex) |
817 |
23 Jun 05 |
nicklas |
394 |
{ |
817 |
23 Jun 05 |
nicklas |
395 |
write("--List events for sample FAILED"); |
817 |
23 Jun 05 |
nicklas |
396 |
ex.printStackTrace(); |
817 |
23 Jun 05 |
nicklas |
397 |
ok = false; |
817 |
23 Jun 05 |
nicklas |
398 |
} |
817 |
23 Jun 05 |
nicklas |
399 |
finally |
817 |
23 Jun 05 |
nicklas |
400 |
{ |
817 |
23 Jun 05 |
nicklas |
401 |
if (dc != null) dc.close(); |
817 |
23 Jun 05 |
nicklas |
402 |
} |
817 |
23 Jun 05 |
nicklas |
403 |
} |
817 |
23 Jun 05 |
nicklas |
404 |
|
817 |
23 Jun 05 |
nicklas |
405 |
static void test_list_sources(int sampleId, int expectedResults) |
817 |
23 Jun 05 |
nicklas |
406 |
{ |
817 |
23 Jun 05 |
nicklas |
407 |
if (sampleId == 0) return; |
817 |
23 Jun 05 |
nicklas |
408 |
DbControl dc = null; |
817 |
23 Jun 05 |
nicklas |
409 |
try |
817 |
23 Jun 05 |
nicklas |
410 |
{ |
817 |
23 Jun 05 |
nicklas |
411 |
dc = TestUtil.getDbControl(); |
817 |
23 Jun 05 |
nicklas |
412 |
Sample s = Sample.getById(dc, sampleId); |
817 |
23 Jun 05 |
nicklas |
413 |
BioMaterialEvent evt = s.getCreationEvent(); |
5663 |
22 Jun 11 |
nicklas |
414 |
ResultList<BioMaterialEventSource> l = evt.getEventSources().list(dc); |
817 |
23 Jun 05 |
nicklas |
415 |
for (int i = 0; i<l.size(); i++) |
817 |
23 Jun 05 |
nicklas |
416 |
{ |
5663 |
22 Jun 11 |
nicklas |
417 |
write_item(i, l.get(i)); |
817 |
23 Jun 05 |
nicklas |
418 |
} |
817 |
23 Jun 05 |
nicklas |
419 |
if (expectedResults >= 0 && expectedResults != l.size()) |
817 |
23 Jun 05 |
nicklas |
420 |
{ |
817 |
23 Jun 05 |
nicklas |
421 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
817 |
23 Jun 05 |
nicklas |
422 |
} |
817 |
23 Jun 05 |
nicklas |
423 |
write("--List sources for sample OK ("+l.size()+")"); |
817 |
23 Jun 05 |
nicklas |
424 |
} |
817 |
23 Jun 05 |
nicklas |
425 |
catch (Throwable ex) |
817 |
23 Jun 05 |
nicklas |
426 |
{ |
817 |
23 Jun 05 |
nicklas |
427 |
write("--List sources for sample FAILED"); |
817 |
23 Jun 05 |
nicklas |
428 |
ex.printStackTrace(); |
817 |
23 Jun 05 |
nicklas |
429 |
ok = false; |
817 |
23 Jun 05 |
nicklas |
430 |
} |
817 |
23 Jun 05 |
nicklas |
431 |
finally |
817 |
23 Jun 05 |
nicklas |
432 |
{ |
817 |
23 Jun 05 |
nicklas |
433 |
if (dc != null) dc.close(); |
817 |
23 Jun 05 |
nicklas |
434 |
} |
817 |
23 Jun 05 |
nicklas |
435 |
} |
5663 |
22 Jun 11 |
nicklas |
436 |
|
5663 |
22 Jun 11 |
nicklas |
437 |
static void test_list_children(int sampleId, int expectedResults) |
4559 |
03 Oct 08 |
martin |
438 |
{ |
4559 |
03 Oct 08 |
martin |
439 |
if (sampleId == 0) return; |
4559 |
03 Oct 08 |
martin |
440 |
DbControl dc = null; |
4559 |
03 Oct 08 |
martin |
441 |
try |
4559 |
03 Oct 08 |
martin |
442 |
{ |
4559 |
03 Oct 08 |
martin |
443 |
dc = TestUtil.getDbControl(); |
4559 |
03 Oct 08 |
martin |
444 |
Sample s = Sample.getById(dc, sampleId); |
5663 |
22 Jun 11 |
nicklas |
445 |
ItemResultList<Sample> ev = s.getChildSamples().list(dc); |
4559 |
03 Oct 08 |
martin |
446 |
|
4559 |
03 Oct 08 |
martin |
447 |
for (int i=0; i<ev.size(); i++) |
4559 |
03 Oct 08 |
martin |
448 |
{ |
5663 |
22 Jun 11 |
nicklas |
449 |
write_item(i, ev.get(i)); |
4559 |
03 Oct 08 |
martin |
450 |
} |
4559 |
03 Oct 08 |
martin |
451 |
if (expectedResults >= 0 && expectedResults != ev.size()) |
4559 |
03 Oct 08 |
martin |
452 |
{ |
4559 |
03 Oct 08 |
martin |
453 |
throw new BaseException("Expected "+expectedResults+" results, not "+ev.size()); |
4559 |
03 Oct 08 |
martin |
454 |
} |
5663 |
22 Jun 11 |
nicklas |
455 |
write("--List children for sample OK ("+ev.size()+")"); |
4559 |
03 Oct 08 |
martin |
456 |
} |
4559 |
03 Oct 08 |
martin |
457 |
catch (Throwable ex) |
4559 |
03 Oct 08 |
martin |
458 |
{ |
5663 |
22 Jun 11 |
nicklas |
459 |
write("--List children for sample FAILED"); |
4559 |
03 Oct 08 |
martin |
460 |
ex.printStackTrace(); |
4559 |
03 Oct 08 |
martin |
461 |
ok = false; |
4559 |
03 Oct 08 |
martin |
462 |
} |
4559 |
03 Oct 08 |
martin |
463 |
finally |
4559 |
03 Oct 08 |
martin |
464 |
{ |
4559 |
03 Oct 08 |
martin |
465 |
if (dc != null) dc.close(); |
4559 |
03 Oct 08 |
martin |
466 |
} |
4559 |
03 Oct 08 |
martin |
467 |
} |
5663 |
22 Jun 11 |
nicklas |
468 |
|
5663 |
22 Jun 11 |
nicklas |
469 |
static void test_childrenTransformer(int sampleId, int expectedResults) |
5663 |
22 Jun 11 |
nicklas |
470 |
{ |
5663 |
22 Jun 11 |
nicklas |
471 |
if (sampleId == 0) return; |
5663 |
22 Jun 11 |
nicklas |
472 |
DbControl dc = null; |
5663 |
22 Jun 11 |
nicklas |
473 |
try |
5663 |
22 Jun 11 |
nicklas |
474 |
{ |
5663 |
22 Jun 11 |
nicklas |
475 |
dc = TestUtil.getDbControl(); |
5663 |
22 Jun 11 |
nicklas |
476 |
Sample s = Sample.getById(dc, sampleId); |
6775 |
17 Mar 15 |
nicklas |
477 |
SourceItemTransformer transformer = new SampleToChildSampleTransformer(false); |
6775 |
17 Mar 15 |
nicklas |
478 |
TransformContext tfc = new TransformContext(dc); |
6775 |
17 Mar 15 |
nicklas |
479 |
Set<Integer> children = transformer.transform(tfc, Collections.singleton(s.getId())); |
4712 |
19 Dec 08 |
nicklas |
480 |
|
5663 |
22 Jun 11 |
nicklas |
481 |
int i = 0; |
6775 |
17 Mar 15 |
nicklas |
482 |
for (int childId : children) |
5663 |
22 Jun 11 |
nicklas |
483 |
{ |
6775 |
17 Mar 15 |
nicklas |
484 |
write_item(i, Sample.getById(dc, childId)); |
5663 |
22 Jun 11 |
nicklas |
485 |
i++; |
5663 |
22 Jun 11 |
nicklas |
486 |
} |
5663 |
22 Jun 11 |
nicklas |
487 |
if (expectedResults >= 0 && expectedResults != children.size()) |
5663 |
22 Jun 11 |
nicklas |
488 |
{ |
5663 |
22 Jun 11 |
nicklas |
489 |
throw new BaseException("Expected "+expectedResults+" results, not "+children.size()); |
5663 |
22 Jun 11 |
nicklas |
490 |
} |
5663 |
22 Jun 11 |
nicklas |
491 |
write("--List children for sample using transformer OK ("+children.size()+")"); |
5663 |
22 Jun 11 |
nicklas |
492 |
} |
5663 |
22 Jun 11 |
nicklas |
493 |
catch (Throwable ex) |
5663 |
22 Jun 11 |
nicklas |
494 |
{ |
5663 |
22 Jun 11 |
nicklas |
495 |
write("--List children for sample using transformer FAILED"); |
5663 |
22 Jun 11 |
nicklas |
496 |
ex.printStackTrace(); |
5663 |
22 Jun 11 |
nicklas |
497 |
ok = false; |
5663 |
22 Jun 11 |
nicklas |
498 |
} |
5663 |
22 Jun 11 |
nicklas |
499 |
finally |
5663 |
22 Jun 11 |
nicklas |
500 |
{ |
5663 |
22 Jun 11 |
nicklas |
501 |
if (dc != null) dc.close(); |
5663 |
22 Jun 11 |
nicklas |
502 |
} |
5663 |
22 Jun 11 |
nicklas |
503 |
} |
5663 |
22 Jun 11 |
nicklas |
504 |
|
5663 |
22 Jun 11 |
nicklas |
505 |
static void test_parentsTransformer(int sampleId, int expectedResults) |
4712 |
19 Dec 08 |
nicklas |
506 |
{ |
4712 |
19 Dec 08 |
nicklas |
507 |
if (sampleId == 0) return; |
4712 |
19 Dec 08 |
nicklas |
508 |
DbControl dc = null; |
4712 |
19 Dec 08 |
nicklas |
509 |
try |
4712 |
19 Dec 08 |
nicklas |
510 |
{ |
4712 |
19 Dec 08 |
nicklas |
511 |
dc = TestUtil.getDbControl(); |
4712 |
19 Dec 08 |
nicklas |
512 |
Sample s = Sample.getById(dc, sampleId); |
6775 |
17 Mar 15 |
nicklas |
513 |
|
6775 |
17 Mar 15 |
nicklas |
514 |
SourceItemTransformer transformer = new SampleToParentSampleTransformer(false); |
6775 |
17 Mar 15 |
nicklas |
515 |
TransformContext tfc = new TransformContext(dc); |
6775 |
17 Mar 15 |
nicklas |
516 |
Set<Integer> parents = transformer.transform(tfc, Collections.singleton(s.getId())); |
4712 |
19 Dec 08 |
nicklas |
517 |
|
5663 |
22 Jun 11 |
nicklas |
518 |
int i = 0; |
6775 |
17 Mar 15 |
nicklas |
519 |
for (int parentId : parents) |
4712 |
19 Dec 08 |
nicklas |
520 |
{ |
6775 |
17 Mar 15 |
nicklas |
521 |
write_item(i, Sample.getById(dc, parentId)); |
5663 |
22 Jun 11 |
nicklas |
522 |
i++; |
4712 |
19 Dec 08 |
nicklas |
523 |
} |
5663 |
22 Jun 11 |
nicklas |
524 |
if (expectedResults >= 0 && expectedResults != parents.size()) |
4712 |
19 Dec 08 |
nicklas |
525 |
{ |
5663 |
22 Jun 11 |
nicklas |
526 |
throw new BaseException("Expected "+expectedResults+" results, not "+parents.size()); |
4712 |
19 Dec 08 |
nicklas |
527 |
} |
5663 |
22 Jun 11 |
nicklas |
528 |
write("--List parents for sample using transformer OK ("+parents.size()+")"); |
4712 |
19 Dec 08 |
nicklas |
529 |
} |
4712 |
19 Dec 08 |
nicklas |
530 |
catch (Throwable ex) |
4712 |
19 Dec 08 |
nicklas |
531 |
{ |
5663 |
22 Jun 11 |
nicklas |
532 |
write("--List parents for sample using transformer FAILED"); |
4712 |
19 Dec 08 |
nicklas |
533 |
ex.printStackTrace(); |
4712 |
19 Dec 08 |
nicklas |
534 |
ok = false; |
4712 |
19 Dec 08 |
nicklas |
535 |
} |
4712 |
19 Dec 08 |
nicklas |
536 |
finally |
4712 |
19 Dec 08 |
nicklas |
537 |
{ |
4712 |
19 Dec 08 |
nicklas |
538 |
if (dc != null) dc.close(); |
4712 |
19 Dec 08 |
nicklas |
539 |
} |
4712 |
19 Dec 08 |
nicklas |
540 |
} |
4712 |
19 Dec 08 |
nicklas |
541 |
|
5663 |
22 Jun 11 |
nicklas |
542 |
static void test_sampleToBioSourceTransformer(int sampleId, int expectedResults) |
5663 |
22 Jun 11 |
nicklas |
543 |
{ |
5663 |
22 Jun 11 |
nicklas |
544 |
if (sampleId == 0) return; |
5663 |
22 Jun 11 |
nicklas |
545 |
DbControl dc = null; |
5663 |
22 Jun 11 |
nicklas |
546 |
try |
5663 |
22 Jun 11 |
nicklas |
547 |
{ |
5663 |
22 Jun 11 |
nicklas |
548 |
dc = TestUtil.getDbControl(); |
5663 |
22 Jun 11 |
nicklas |
549 |
Sample s = Sample.getById(dc, sampleId); |
6775 |
17 Mar 15 |
nicklas |
550 |
SourceItemTransformer transformer = new SampleToBioSourceTransformer(); |
6775 |
17 Mar 15 |
nicklas |
551 |
TransformContext tfc = new TransformContext(dc); |
6775 |
17 Mar 15 |
nicklas |
552 |
Set<Integer> parents = transformer.transform(tfc, Collections.singleton(s.getId())); |
6775 |
17 Mar 15 |
nicklas |
553 |
|
5663 |
22 Jun 11 |
nicklas |
554 |
int i = 0; |
6775 |
17 Mar 15 |
nicklas |
555 |
for (int parentId : parents) |
5663 |
22 Jun 11 |
nicklas |
556 |
{ |
6775 |
17 Mar 15 |
nicklas |
557 |
TestBioSource.write_item(i, BioSource.getById(dc, parentId)); |
5663 |
22 Jun 11 |
nicklas |
558 |
i++; |
5663 |
22 Jun 11 |
nicklas |
559 |
} |
5663 |
22 Jun 11 |
nicklas |
560 |
if (expectedResults >= 0 && expectedResults != parents.size()) |
5663 |
22 Jun 11 |
nicklas |
561 |
{ |
5663 |
22 Jun 11 |
nicklas |
562 |
throw new BaseException("Expected "+expectedResults+" results, not "+parents.size()); |
5663 |
22 Jun 11 |
nicklas |
563 |
} |
5663 |
22 Jun 11 |
nicklas |
564 |
write("--List biosource for sample using transformer OK ("+parents.size()+")"); |
5663 |
22 Jun 11 |
nicklas |
565 |
} |
5663 |
22 Jun 11 |
nicklas |
566 |
catch (Throwable ex) |
5663 |
22 Jun 11 |
nicklas |
567 |
{ |
5663 |
22 Jun 11 |
nicklas |
568 |
write("--List biosource for sample using transformer FAILED"); |
5663 |
22 Jun 11 |
nicklas |
569 |
ex.printStackTrace(); |
5663 |
22 Jun 11 |
nicklas |
570 |
ok = false; |
5663 |
22 Jun 11 |
nicklas |
571 |
} |
5663 |
22 Jun 11 |
nicklas |
572 |
finally |
5663 |
22 Jun 11 |
nicklas |
573 |
{ |
5663 |
22 Jun 11 |
nicklas |
574 |
if (dc != null) dc.close(); |
5663 |
22 Jun 11 |
nicklas |
575 |
} |
5663 |
22 Jun 11 |
nicklas |
576 |
} |
5663 |
22 Jun 11 |
nicklas |
577 |
|
5663 |
22 Jun 11 |
nicklas |
578 |
static void test_bioSourceToSampleTransformer(int bioSourceId, int expectedResults) |
5663 |
22 Jun 11 |
nicklas |
579 |
{ |
5663 |
22 Jun 11 |
nicklas |
580 |
if (bioSourceId == 0) return; |
5663 |
22 Jun 11 |
nicklas |
581 |
DbControl dc = null; |
5663 |
22 Jun 11 |
nicklas |
582 |
try |
5663 |
22 Jun 11 |
nicklas |
583 |
{ |
5663 |
22 Jun 11 |
nicklas |
584 |
dc = TestUtil.getDbControl(); |
5663 |
22 Jun 11 |
nicklas |
585 |
BioSource bs = BioSource.getById(dc, bioSourceId); |
6775 |
17 Mar 15 |
nicklas |
586 |
|
6775 |
17 Mar 15 |
nicklas |
587 |
SourceItemTransformer transformer = new BioSourceToSampleTransformer(); |
6775 |
17 Mar 15 |
nicklas |
588 |
TransformContext tfc = new TransformContext(dc); |
6775 |
17 Mar 15 |
nicklas |
589 |
Set<Integer> children = transformer.transform(tfc, Collections.singleton(bs.getId())); |
5663 |
22 Jun 11 |
nicklas |
590 |
|
5663 |
22 Jun 11 |
nicklas |
591 |
int i = 0; |
6775 |
17 Mar 15 |
nicklas |
592 |
for (int childId : children) |
5663 |
22 Jun 11 |
nicklas |
593 |
{ |
6775 |
17 Mar 15 |
nicklas |
594 |
write_item(i, Sample.getById(dc, childId)); |
5663 |
22 Jun 11 |
nicklas |
595 |
i++; |
5663 |
22 Jun 11 |
nicklas |
596 |
} |
5663 |
22 Jun 11 |
nicklas |
597 |
if (expectedResults >= 0 && expectedResults != children.size()) |
5663 |
22 Jun 11 |
nicklas |
598 |
{ |
5663 |
22 Jun 11 |
nicklas |
599 |
throw new BaseException("Expected "+expectedResults+" results, not "+children.size()); |
5663 |
22 Jun 11 |
nicklas |
600 |
} |
5663 |
22 Jun 11 |
nicklas |
601 |
write("--List sample for biosource using transformer OK ("+children.size()+")"); |
5663 |
22 Jun 11 |
nicklas |
602 |
} |
5663 |
22 Jun 11 |
nicklas |
603 |
catch (Throwable ex) |
5663 |
22 Jun 11 |
nicklas |
604 |
{ |
5663 |
22 Jun 11 |
nicklas |
605 |
write("--List sample for biosource using transformer FAILED"); |
5663 |
22 Jun 11 |
nicklas |
606 |
ex.printStackTrace(); |
5663 |
22 Jun 11 |
nicklas |
607 |
ok = false; |
5663 |
22 Jun 11 |
nicklas |
608 |
} |
5663 |
22 Jun 11 |
nicklas |
609 |
finally |
5663 |
22 Jun 11 |
nicklas |
610 |
{ |
5663 |
22 Jun 11 |
nicklas |
611 |
if (dc != null) dc.close(); |
5663 |
22 Jun 11 |
nicklas |
612 |
} |
5663 |
22 Jun 11 |
nicklas |
613 |
} |
5663 |
22 Jun 11 |
nicklas |
614 |
|
802 |
21 Jun 05 |
nicklas |
615 |
} |