881 |
06 Jul 05 |
nicklas |
1 |
/* |
881 |
06 Jul 05 |
nicklas |
$Id$ |
881 |
06 Jul 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg |
881 |
06 Jul 05 |
nicklas |
6 |
|
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/ |
881 |
06 Jul 05 |
nicklas |
9 |
|
881 |
06 Jul 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
881 |
06 Jul 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 |
881 |
06 Jul 05 |
nicklas |
of the License, or (at your option) any later version. |
881 |
06 Jul 05 |
nicklas |
14 |
|
881 |
06 Jul 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
881 |
06 Jul 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
881 |
06 Jul 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
881 |
06 Jul 05 |
nicklas |
GNU General Public License for more details. |
881 |
06 Jul 05 |
nicklas |
19 |
|
881 |
06 Jul 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/>. |
881 |
06 Jul 05 |
nicklas |
22 |
*/ |
881 |
06 Jul 05 |
nicklas |
23 |
import net.sf.basedb.core.*; |
4239 |
22 Apr 08 |
nicklas |
24 |
import net.sf.basedb.core.data.ReporterData; |
1719 |
15 Dec 05 |
enell |
25 |
import net.sf.basedb.util.Coordinate; |
1719 |
15 Dec 05 |
enell |
26 |
import net.sf.basedb.util.FileUtil; |
2203 |
28 Apr 06 |
nicklas |
27 |
import net.sf.basedb.util.parser.FlatFileParser; |
881 |
06 Jul 05 |
nicklas |
28 |
|
881 |
06 Jul 05 |
nicklas |
29 |
import java.util.Date; |
1719 |
15 Dec 05 |
enell |
30 |
import java.util.HashMap; |
1719 |
15 Dec 05 |
enell |
31 |
import java.util.Iterator; |
5340 |
10 May 10 |
nicklas |
32 |
import java.util.Set; |
1719 |
15 Dec 05 |
enell |
33 |
import java.util.regex.Pattern; |
881 |
06 Jul 05 |
nicklas |
34 |
|
881 |
06 Jul 05 |
nicklas |
35 |
public class TestPlate |
881 |
06 Jul 05 |
nicklas |
36 |
{ |
881 |
06 Jul 05 |
nicklas |
37 |
|
881 |
06 Jul 05 |
nicklas |
38 |
static boolean ok = true; |
881 |
06 Jul 05 |
nicklas |
39 |
public static void main(String[] args) |
881 |
06 Jul 05 |
nicklas |
40 |
{ |
881 |
06 Jul 05 |
nicklas |
41 |
TestUtil.checkArgs(args); |
881 |
06 Jul 05 |
nicklas |
42 |
TestUtil.begin(); |
881 |
06 Jul 05 |
nicklas |
43 |
ok = test_all(); |
881 |
06 Jul 05 |
nicklas |
44 |
TestUtil.stop(); |
881 |
06 Jul 05 |
nicklas |
45 |
} |
881 |
06 Jul 05 |
nicklas |
46 |
|
881 |
06 Jul 05 |
nicklas |
47 |
static boolean test_all() |
881 |
06 Jul 05 |
nicklas |
48 |
{ |
881 |
06 Jul 05 |
nicklas |
49 |
write("++Testing plates"); |
881 |
06 Jul 05 |
nicklas |
50 |
write_header(); |
881 |
06 Jul 05 |
nicklas |
// Standard tests: create, load, list |
881 |
06 Jul 05 |
nicklas |
52 |
int plateGeometryId = TestPlateGeometry.test_create(8, 12, false); |
881 |
06 Jul 05 |
nicklas |
53 |
int plateTypeId = TestPlateType.test_create(plateGeometryId, false); |
881 |
06 Jul 05 |
nicklas |
54 |
int id = test_create(plateTypeId, true); |
881 |
06 Jul 05 |
nicklas |
55 |
int id2 = test_create(plateTypeId, false); |
881 |
06 Jul 05 |
nicklas |
56 |
test_load(id); |
881 |
06 Jul 05 |
nicklas |
57 |
test_list(-1); |
881 |
06 Jul 05 |
nicklas |
58 |
|
881 |
06 Jul 05 |
nicklas |
// Test events |
5630 |
13 May 11 |
nicklas |
60 |
int protocolTypeId = TestItemSubtype.test_create(Item.PROTOCOL, "Plate protocol type"); |
4366 |
02 Jul 08 |
nicklas |
61 |
int protocolId = TestProtocol.test_create(protocolTypeId, null, false); |
881 |
06 Jul 05 |
nicklas |
62 |
int eventTypeId = TestPlateType.test_create_event_type(plateTypeId, protocolTypeId); |
881 |
06 Jul 05 |
nicklas |
63 |
int eventId = test_create_event(id, eventTypeId, protocolId); |
881 |
06 Jul 05 |
nicklas |
64 |
test_list_events(id, 1); |
1529 |
27 Oct 05 |
nicklas |
65 |
|
1529 |
27 Oct 05 |
nicklas |
66 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
881 |
06 Jul 05 |
nicklas |
67 |
test_delete_event(eventId); |
881 |
06 Jul 05 |
nicklas |
68 |
TestPlateType.test_delete_event_type(eventTypeId); |
881 |
06 Jul 05 |
nicklas |
69 |
TestProtocol.test_delete(protocolId); |
5630 |
13 May 11 |
nicklas |
70 |
TestItemSubtype.test_delete(protocolTypeId); |
881 |
06 Jul 05 |
nicklas |
71 |
|
881 |
06 Jul 05 |
nicklas |
// Standard test: Delete |
881 |
06 Jul 05 |
nicklas |
73 |
test_delete(id); |
881 |
06 Jul 05 |
nicklas |
74 |
test_delete(id2); |
881 |
06 Jul 05 |
nicklas |
75 |
TestPlateType.test_delete(plateTypeId); |
881 |
06 Jul 05 |
nicklas |
76 |
TestPlateGeometry.test_delete(plateGeometryId); |
881 |
06 Jul 05 |
nicklas |
77 |
write("++Testing plates "+(ok ? "OK" : "Failed")+"\n"); |
881 |
06 Jul 05 |
nicklas |
78 |
return ok; |
881 |
06 Jul 05 |
nicklas |
79 |
} |
881 |
06 Jul 05 |
nicklas |
80 |
|
881 |
06 Jul 05 |
nicklas |
81 |
static int test_create(int plateTypeId, boolean setAll) |
881 |
06 Jul 05 |
nicklas |
82 |
{ |
881 |
06 Jul 05 |
nicklas |
83 |
if (plateTypeId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.PLATE)) return 0; |
881 |
06 Jul 05 |
nicklas |
84 |
int id = 0; |
881 |
06 Jul 05 |
nicklas |
85 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
86 |
try |
881 |
06 Jul 05 |
nicklas |
87 |
{ |
881 |
06 Jul 05 |
nicklas |
88 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
89 |
PlateType pt = PlateType.getById(dc, plateTypeId); |
881 |
06 Jul 05 |
nicklas |
90 |
Plate p = Plate.getNew(dc, pt); |
881 |
06 Jul 05 |
nicklas |
91 |
if (setAll) |
881 |
06 Jul 05 |
nicklas |
92 |
{ |
881 |
06 Jul 05 |
nicklas |
93 |
p.setName("Test plate"); |
881 |
06 Jul 05 |
nicklas |
94 |
p.setDescription("Added at "+new Date()); |
881 |
06 Jul 05 |
nicklas |
95 |
p.setBarcode("00557788"); |
881 |
06 Jul 05 |
nicklas |
96 |
p.setDestroyed(false); |
4239 |
22 Apr 08 |
nicklas |
97 |
|
4239 |
22 Apr 08 |
nicklas |
98 |
PlateGeometry geometry = pt.getPlateGeometry(); |
4239 |
22 Apr 08 |
nicklas |
99 |
int columns = geometry.getColumns(); |
4239 |
22 Apr 08 |
nicklas |
100 |
int rows = geometry.getRows(); |
4239 |
22 Apr 08 |
nicklas |
101 |
DataQuery<ReporterData> query = Reporter.getQuery(); |
4239 |
22 Apr 08 |
nicklas |
102 |
DataResultIterator<ReporterData> reporters = query.iterate(dc); |
4239 |
22 Apr 08 |
nicklas |
103 |
for (int row = 0; row < rows; ++row) |
4239 |
22 Apr 08 |
nicklas |
104 |
{ |
4239 |
22 Apr 08 |
nicklas |
105 |
for (int column = 0; column < columns; ++column) |
4239 |
22 Apr 08 |
nicklas |
106 |
{ |
4239 |
22 Apr 08 |
nicklas |
107 |
if (reporters.hasNext()) |
4239 |
22 Apr 08 |
nicklas |
108 |
{ |
4239 |
22 Apr 08 |
nicklas |
109 |
p.getWell(row, column).setReporter(reporters.next()); |
4239 |
22 Apr 08 |
nicklas |
110 |
} |
4239 |
22 Apr 08 |
nicklas |
111 |
} |
4239 |
22 Apr 08 |
nicklas |
112 |
} |
4239 |
22 Apr 08 |
nicklas |
113 |
|
4239 |
22 Apr 08 |
nicklas |
// Make first and last well empty |
4239 |
22 Apr 08 |
nicklas |
115 |
p.getWell(0, 0).setReporter(null); |
4239 |
22 Apr 08 |
nicklas |
116 |
p.getWell(rows-1, columns-1).setReporter(null); |
881 |
06 Jul 05 |
nicklas |
117 |
} |
4239 |
22 Apr 08 |
nicklas |
118 |
|
4239 |
22 Apr 08 |
nicklas |
119 |
|
881 |
06 Jul 05 |
nicklas |
120 |
dc.saveItem(p); |
881 |
06 Jul 05 |
nicklas |
121 |
dc.commit(); |
881 |
06 Jul 05 |
nicklas |
122 |
id = p.getId(); |
881 |
06 Jul 05 |
nicklas |
123 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
124 |
dc.reattachItem(p, false); |
881 |
06 Jul 05 |
nicklas |
125 |
write_item(0, p); |
881 |
06 Jul 05 |
nicklas |
126 |
write("--Create plate OK"); |
881 |
06 Jul 05 |
nicklas |
127 |
} |
881 |
06 Jul 05 |
nicklas |
128 |
catch (Throwable ex) |
881 |
06 Jul 05 |
nicklas |
129 |
{ |
881 |
06 Jul 05 |
nicklas |
130 |
write("--Create plate FAILED"); |
881 |
06 Jul 05 |
nicklas |
131 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
132 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
133 |
} |
881 |
06 Jul 05 |
nicklas |
134 |
finally |
881 |
06 Jul 05 |
nicklas |
135 |
{ |
881 |
06 Jul 05 |
nicklas |
136 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
137 |
} |
881 |
06 Jul 05 |
nicklas |
138 |
return id; |
881 |
06 Jul 05 |
nicklas |
139 |
} |
881 |
06 Jul 05 |
nicklas |
140 |
|
881 |
06 Jul 05 |
nicklas |
141 |
static void test_load(int id) |
881 |
06 Jul 05 |
nicklas |
142 |
{ |
881 |
06 Jul 05 |
nicklas |
143 |
if (id == 0) return; |
881 |
06 Jul 05 |
nicklas |
144 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
145 |
try |
881 |
06 Jul 05 |
nicklas |
146 |
{ |
881 |
06 Jul 05 |
nicklas |
147 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
148 |
Plate p = Plate.getById(dc, id); |
881 |
06 Jul 05 |
nicklas |
149 |
write_item(0, p); |
881 |
06 Jul 05 |
nicklas |
150 |
write("--Load plate OK"); |
881 |
06 Jul 05 |
nicklas |
151 |
} |
881 |
06 Jul 05 |
nicklas |
152 |
catch (Throwable ex) |
881 |
06 Jul 05 |
nicklas |
153 |
{ |
881 |
06 Jul 05 |
nicklas |
154 |
write("--Load plate FAILED"); |
881 |
06 Jul 05 |
nicklas |
155 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
156 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
157 |
} |
881 |
06 Jul 05 |
nicklas |
158 |
finally |
881 |
06 Jul 05 |
nicklas |
159 |
{ |
881 |
06 Jul 05 |
nicklas |
160 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
161 |
} |
881 |
06 Jul 05 |
nicklas |
162 |
} |
881 |
06 Jul 05 |
nicklas |
163 |
|
1719 |
15 Dec 05 |
enell |
164 |
static int[] test_import_from_file(String filename, String headerRegexp, int plateTypeId, int plateIdCol, int rowCol, int columnCol, int reporterCol) |
1719 |
15 Dec 05 |
enell |
165 |
{ |
1719 |
15 Dec 05 |
enell |
166 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.PLATE)) return null; |
1719 |
15 Dec 05 |
enell |
167 |
write("--Start import plate from file (" + filename + ")"); |
1719 |
15 Dec 05 |
enell |
168 |
DbControl dc = null; |
1719 |
15 Dec 05 |
enell |
169 |
long time; |
1719 |
15 Dec 05 |
enell |
170 |
int numWells = 0; |
1719 |
15 Dec 05 |
enell |
171 |
HashMap<String, Plate> plates = new HashMap<String, Plate>(); |
1719 |
15 Dec 05 |
enell |
172 |
try |
1719 |
15 Dec 05 |
enell |
173 |
{ |
1719 |
15 Dec 05 |
enell |
174 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
175 |
|
1719 |
15 Dec 05 |
enell |
176 |
FlatFileParser ffp = new FlatFileParser(); |
1719 |
15 Dec 05 |
enell |
177 |
ffp.setDataHeaderRegexp(Pattern.compile(headerRegexp)); |
2203 |
28 Apr 06 |
nicklas |
178 |
ffp.setDataSplitterRegexp(Pattern.compile("\\t")); |
2992 |
01 Dec 06 |
enell |
179 |
ffp.setInputStream(FileUtil.getInputStream(new java.io.File(filename)), "ISO-8859-1"); |
1719 |
15 Dec 05 |
enell |
180 |
ffp.parseHeaders(); |
1719 |
15 Dec 05 |
enell |
181 |
PlateType pt = PlateType.getById(dc, plateTypeId); |
1719 |
15 Dec 05 |
enell |
182 |
time = System.currentTimeMillis(); |
1719 |
15 Dec 05 |
enell |
183 |
while (ffp.hasMoreData()) |
1719 |
15 Dec 05 |
enell |
184 |
{ |
1719 |
15 Dec 05 |
enell |
185 |
FlatFileParser.Data data = ffp.nextData(); |
7665 |
20 Mar 19 |
nicklas |
186 |
String plateId = data.getString(plateIdCol); |
7665 |
20 Mar 19 |
nicklas |
187 |
int row = Coordinate.alphaToNumeric(data.getString(rowCol))-1; |
7665 |
20 Mar 19 |
nicklas |
188 |
int column = Coordinate.alphaToNumeric(data.getString(columnCol))-1; |
7665 |
20 Mar 19 |
nicklas |
189 |
String reporterId = data.getString(reporterCol); |
1719 |
15 Dec 05 |
enell |
190 |
|
1719 |
15 Dec 05 |
enell |
191 |
Plate p = plates.get(plateId); |
1719 |
15 Dec 05 |
enell |
192 |
if (p == null) |
1719 |
15 Dec 05 |
enell |
193 |
{ |
1719 |
15 Dec 05 |
enell |
194 |
p = Plate.getNew(dc, pt); |
1719 |
15 Dec 05 |
enell |
195 |
p.setName(filename+"_"+plateId); |
1719 |
15 Dec 05 |
enell |
196 |
dc.saveItem(p); |
1719 |
15 Dec 05 |
enell |
197 |
plates.put(plateId, p); |
1719 |
15 Dec 05 |
enell |
198 |
} |
1719 |
15 Dec 05 |
enell |
199 |
Well w = p.getWell(row, column); |
1719 |
15 Dec 05 |
enell |
200 |
w.setReporter(Reporter.getByExternalId(dc, reporterId)); |
1719 |
15 Dec 05 |
enell |
201 |
numWells++; |
1719 |
15 Dec 05 |
enell |
202 |
} |
1719 |
15 Dec 05 |
enell |
203 |
dc.commit(); |
1719 |
15 Dec 05 |
enell |
204 |
time = System.currentTimeMillis()-time; |
1719 |
15 Dec 05 |
enell |
205 |
write("--Import plate from file OK ("+numWells+" wells, time="+time+" ms)"); |
1719 |
15 Dec 05 |
enell |
206 |
} |
1719 |
15 Dec 05 |
enell |
207 |
catch (Throwable ex) |
1719 |
15 Dec 05 |
enell |
208 |
{ |
1719 |
15 Dec 05 |
enell |
209 |
write("--Import reporters from file FAILED ("+numWells+" wells)"); |
1719 |
15 Dec 05 |
enell |
210 |
ex.printStackTrace(); |
1719 |
15 Dec 05 |
enell |
211 |
ok = false; |
1719 |
15 Dec 05 |
enell |
212 |
} |
1719 |
15 Dec 05 |
enell |
213 |
finally |
1719 |
15 Dec 05 |
enell |
214 |
{ |
1719 |
15 Dec 05 |
enell |
215 |
if (dc != null) dc.close(); |
1719 |
15 Dec 05 |
enell |
216 |
} |
1719 |
15 Dec 05 |
enell |
217 |
int[] ids = new int[plates.size()]; |
1719 |
15 Dec 05 |
enell |
218 |
if (plates.size() > 0) |
1719 |
15 Dec 05 |
enell |
219 |
{ |
1719 |
15 Dec 05 |
enell |
220 |
Iterator<Plate> it = plates.values().iterator(); |
1719 |
15 Dec 05 |
enell |
221 |
for (int i = 0; it.hasNext(); i++) |
1719 |
15 Dec 05 |
enell |
222 |
{ |
1719 |
15 Dec 05 |
enell |
223 |
Plate p = it.next(); |
1719 |
15 Dec 05 |
enell |
224 |
ids[i] = p.getId(); |
1719 |
15 Dec 05 |
enell |
225 |
} |
1719 |
15 Dec 05 |
enell |
226 |
} |
1719 |
15 Dec 05 |
enell |
227 |
return ids; |
1719 |
15 Dec 05 |
enell |
228 |
} |
1719 |
15 Dec 05 |
enell |
229 |
|
881 |
06 Jul 05 |
nicklas |
230 |
static void test_list(int expectedResults) |
881 |
06 Jul 05 |
nicklas |
231 |
{ |
881 |
06 Jul 05 |
nicklas |
232 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
233 |
try |
881 |
06 Jul 05 |
nicklas |
234 |
{ |
881 |
06 Jul 05 |
nicklas |
235 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
236 |
ItemResultList<Plate> l = Plate.getQuery().list(dc); |
881 |
06 Jul 05 |
nicklas |
237 |
for (int i = 0; i<l.size(); i++) |
881 |
06 Jul 05 |
nicklas |
238 |
{ |
881 |
06 Jul 05 |
nicklas |
239 |
write_item(i, l.get(i)); |
881 |
06 Jul 05 |
nicklas |
240 |
} |
881 |
06 Jul 05 |
nicklas |
241 |
if (expectedResults >= 0 && expectedResults != l.size()) |
881 |
06 Jul 05 |
nicklas |
242 |
{ |
881 |
06 Jul 05 |
nicklas |
243 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
881 |
06 Jul 05 |
nicklas |
244 |
} |
881 |
06 Jul 05 |
nicklas |
245 |
write("--List plates OK ("+l.size()+")"); |
881 |
06 Jul 05 |
nicklas |
246 |
} |
881 |
06 Jul 05 |
nicklas |
247 |
catch (Throwable ex) |
881 |
06 Jul 05 |
nicklas |
248 |
{ |
881 |
06 Jul 05 |
nicklas |
249 |
write("--List plates FAILED"); |
881 |
06 Jul 05 |
nicklas |
250 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
251 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
252 |
} |
881 |
06 Jul 05 |
nicklas |
253 |
finally |
881 |
06 Jul 05 |
nicklas |
254 |
{ |
881 |
06 Jul 05 |
nicklas |
255 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
256 |
} |
881 |
06 Jul 05 |
nicklas |
257 |
} |
881 |
06 Jul 05 |
nicklas |
258 |
|
881 |
06 Jul 05 |
nicklas |
259 |
|
881 |
06 Jul 05 |
nicklas |
260 |
static void test_delete(int id) |
881 |
06 Jul 05 |
nicklas |
261 |
{ |
881 |
06 Jul 05 |
nicklas |
262 |
if (id == 0) return; |
881 |
06 Jul 05 |
nicklas |
263 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
264 |
try |
881 |
06 Jul 05 |
nicklas |
265 |
{ |
881 |
06 Jul 05 |
nicklas |
266 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
267 |
Plate p = Plate.getById(dc, id); |
881 |
06 Jul 05 |
nicklas |
268 |
dc.deleteItem(p); |
5340 |
10 May 10 |
nicklas |
269 |
Set<ItemProxy> using = p.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
270 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
271 |
{ |
5340 |
10 May 10 |
nicklas |
272 |
throw new BaseException(p + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
273 |
} |
881 |
06 Jul 05 |
nicklas |
274 |
dc.commit(); |
881 |
06 Jul 05 |
nicklas |
275 |
write("--Delete plate OK"); |
881 |
06 Jul 05 |
nicklas |
276 |
} |
881 |
06 Jul 05 |
nicklas |
277 |
catch (Throwable ex) |
881 |
06 Jul 05 |
nicklas |
278 |
{ |
881 |
06 Jul 05 |
nicklas |
279 |
write("--Delete plate FAILED"); |
881 |
06 Jul 05 |
nicklas |
280 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
281 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
282 |
} |
881 |
06 Jul 05 |
nicklas |
283 |
finally |
881 |
06 Jul 05 |
nicklas |
284 |
{ |
881 |
06 Jul 05 |
nicklas |
285 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
286 |
} |
881 |
06 Jul 05 |
nicklas |
287 |
} |
881 |
06 Jul 05 |
nicklas |
288 |
|
1568 |
04 Nov 05 |
enell |
289 |
public static void test_delete_all() |
1568 |
04 Nov 05 |
enell |
290 |
{ |
1568 |
04 Nov 05 |
enell |
291 |
DbControl dc = null; |
1568 |
04 Nov 05 |
enell |
292 |
try |
1568 |
04 Nov 05 |
enell |
293 |
{ |
1568 |
04 Nov 05 |
enell |
294 |
dc = TestUtil.getDbControl(); |
1568 |
04 Nov 05 |
enell |
295 |
for(Plate p : Plate.getQuery().list(dc)) |
1568 |
04 Nov 05 |
enell |
296 |
{ |
1568 |
04 Nov 05 |
enell |
297 |
dc.deleteItem(p); |
1568 |
04 Nov 05 |
enell |
298 |
} |
1568 |
04 Nov 05 |
enell |
299 |
dc.commit(); |
1568 |
04 Nov 05 |
enell |
300 |
write("--Delete all plates OK"); |
1568 |
04 Nov 05 |
enell |
301 |
} |
1568 |
04 Nov 05 |
enell |
302 |
catch (Throwable ex) |
1568 |
04 Nov 05 |
enell |
303 |
{ |
1568 |
04 Nov 05 |
enell |
304 |
write("--Delete all plates FAILED"); |
1568 |
04 Nov 05 |
enell |
305 |
ex.printStackTrace(); |
1568 |
04 Nov 05 |
enell |
306 |
ok = false; |
1568 |
04 Nov 05 |
enell |
307 |
} |
1568 |
04 Nov 05 |
enell |
308 |
} |
1568 |
04 Nov 05 |
enell |
309 |
|
881 |
06 Jul 05 |
nicklas |
310 |
static void write_header() |
881 |
06 Jul 05 |
nicklas |
311 |
{ |
881 |
06 Jul 05 |
nicklas |
312 |
if (!TestUtil.getSilent()) |
881 |
06 Jul 05 |
nicklas |
313 |
{ |
881 |
06 Jul 05 |
nicklas |
314 |
System.out.println(" \tID \tName \tDescription\tPlate type\tBarcode\tDestroyed"); |
881 |
06 Jul 05 |
nicklas |
315 |
System.out.println("-- \t-- \t--------- \t-----------\t----------\t-------\t---------"); |
881 |
06 Jul 05 |
nicklas |
316 |
} |
881 |
06 Jul 05 |
nicklas |
317 |
} |
881 |
06 Jul 05 |
nicklas |
318 |
static void write_item(int i, Plate p) |
881 |
06 Jul 05 |
nicklas |
319 |
throws BaseException |
881 |
06 Jul 05 |
nicklas |
320 |
{ |
881 |
06 Jul 05 |
nicklas |
321 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+p.getId()+"\t"+p.getName()+"\t"+p.getDescription()+ |
881 |
06 Jul 05 |
nicklas |
322 |
"\t"+p.getPlateType()+"\t"+p.getBarcode()+"\t"+p.isDestroyed()); |
881 |
06 Jul 05 |
nicklas |
323 |
} |
881 |
06 Jul 05 |
nicklas |
324 |
static void write_item(int i, PlateEvent pe) |
881 |
06 Jul 05 |
nicklas |
325 |
throws BaseException |
881 |
06 Jul 05 |
nicklas |
326 |
{ |
881 |
06 Jul 05 |
nicklas |
327 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+pe.getId()+"\t"+ |
881 |
06 Jul 05 |
nicklas |
328 |
"\t"+pe.getPlate()+"\t"+pe.getProtocol()+"\t"+pe.getComment()+"\t"+pe.getEntryDate()+"\t"+pe.getEventDate()); |
881 |
06 Jul 05 |
nicklas |
329 |
} |
881 |
06 Jul 05 |
nicklas |
330 |
static void write(String message) |
881 |
06 Jul 05 |
nicklas |
331 |
{ |
881 |
06 Jul 05 |
nicklas |
332 |
System.out.println(message); |
881 |
06 Jul 05 |
nicklas |
333 |
} |
881 |
06 Jul 05 |
nicklas |
334 |
|
881 |
06 Jul 05 |
nicklas |
335 |
static int test_create_event(int plateId, int eventTypeId, int protocolId) |
881 |
06 Jul 05 |
nicklas |
336 |
{ |
881 |
06 Jul 05 |
nicklas |
337 |
if (plateId == 0 || eventTypeId == 0) return 0; |
881 |
06 Jul 05 |
nicklas |
338 |
int id = 0; |
881 |
06 Jul 05 |
nicklas |
339 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
340 |
try |
881 |
06 Jul 05 |
nicklas |
341 |
{ |
881 |
06 Jul 05 |
nicklas |
342 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
343 |
Plate p = Plate.getById(dc, plateId); |
881 |
06 Jul 05 |
nicklas |
344 |
PlateEventType pet = PlateEventType.getById(dc, eventTypeId); |
881 |
06 Jul 05 |
nicklas |
345 |
PlateEvent pe = p.getEvent(pet); |
881 |
06 Jul 05 |
nicklas |
346 |
pe.setComment("Test plate event"); |
881 |
06 Jul 05 |
nicklas |
347 |
pe.setEventDate(new Date()); |
881 |
06 Jul 05 |
nicklas |
348 |
if (protocolId != 0) pe.setProtocol(Protocol.getById(dc, protocolId)); |
881 |
06 Jul 05 |
nicklas |
349 |
dc.saveItem(pe); |
881 |
06 Jul 05 |
nicklas |
350 |
dc.commit(); |
881 |
06 Jul 05 |
nicklas |
351 |
id = pe.getId(); |
881 |
06 Jul 05 |
nicklas |
352 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
353 |
dc.reattachItem(pe, false); |
881 |
06 Jul 05 |
nicklas |
354 |
write_item(0, pe); |
881 |
06 Jul 05 |
nicklas |
355 |
write("--Create event OK"); |
881 |
06 Jul 05 |
nicklas |
356 |
} |
881 |
06 Jul 05 |
nicklas |
357 |
catch (Exception ex) |
881 |
06 Jul 05 |
nicklas |
358 |
{ |
881 |
06 Jul 05 |
nicklas |
359 |
write("--Create event FAILED"); |
881 |
06 Jul 05 |
nicklas |
360 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
361 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
362 |
} |
881 |
06 Jul 05 |
nicklas |
363 |
finally |
881 |
06 Jul 05 |
nicklas |
364 |
{ |
881 |
06 Jul 05 |
nicklas |
365 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
366 |
} |
881 |
06 Jul 05 |
nicklas |
367 |
return id; |
881 |
06 Jul 05 |
nicklas |
368 |
} |
881 |
06 Jul 05 |
nicklas |
369 |
|
881 |
06 Jul 05 |
nicklas |
370 |
static void test_list_events(int plateId, int expectedResults) |
881 |
06 Jul 05 |
nicklas |
371 |
{ |
881 |
06 Jul 05 |
nicklas |
372 |
if (plateId == 0) return; |
881 |
06 Jul 05 |
nicklas |
373 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
374 |
try |
881 |
06 Jul 05 |
nicklas |
375 |
{ |
881 |
06 Jul 05 |
nicklas |
376 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
377 |
Plate p = Plate.getById(dc, plateId); |
881 |
06 Jul 05 |
nicklas |
378 |
|
1418 |
07 Oct 05 |
nicklas |
379 |
ItemResultList<PlateEvent> l = p.getEvents().list(dc); |
881 |
06 Jul 05 |
nicklas |
380 |
for (int i = 0; i<l.size(); i++) |
881 |
06 Jul 05 |
nicklas |
381 |
{ |
881 |
06 Jul 05 |
nicklas |
382 |
write_item(i, l.get(i)); |
881 |
06 Jul 05 |
nicklas |
383 |
} |
881 |
06 Jul 05 |
nicklas |
384 |
if (expectedResults >= 0 && expectedResults != l.size()) |
881 |
06 Jul 05 |
nicklas |
385 |
{ |
881 |
06 Jul 05 |
nicklas |
386 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
881 |
06 Jul 05 |
nicklas |
387 |
} |
881 |
06 Jul 05 |
nicklas |
388 |
write("--List events OK ("+l.size()+")"); |
881 |
06 Jul 05 |
nicklas |
389 |
} |
881 |
06 Jul 05 |
nicklas |
390 |
catch (Exception ex) |
881 |
06 Jul 05 |
nicklas |
391 |
{ |
881 |
06 Jul 05 |
nicklas |
392 |
write("--List events FAILED"); |
881 |
06 Jul 05 |
nicklas |
393 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
394 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
395 |
} |
881 |
06 Jul 05 |
nicklas |
396 |
finally |
881 |
06 Jul 05 |
nicklas |
397 |
{ |
881 |
06 Jul 05 |
nicklas |
398 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
399 |
} |
881 |
06 Jul 05 |
nicklas |
400 |
} |
881 |
06 Jul 05 |
nicklas |
401 |
|
881 |
06 Jul 05 |
nicklas |
402 |
static void test_delete_event(int eventId) |
881 |
06 Jul 05 |
nicklas |
403 |
{ |
881 |
06 Jul 05 |
nicklas |
404 |
if (eventId == 0) return; |
881 |
06 Jul 05 |
nicklas |
405 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
406 |
try |
881 |
06 Jul 05 |
nicklas |
407 |
{ |
881 |
06 Jul 05 |
nicklas |
408 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
409 |
PlateEvent pe = PlateEvent.getById(dc, eventId); |
881 |
06 Jul 05 |
nicklas |
410 |
dc.deleteItem(pe); |
881 |
06 Jul 05 |
nicklas |
411 |
dc.commit(); |
881 |
06 Jul 05 |
nicklas |
412 |
write("--Delete event OK"); |
881 |
06 Jul 05 |
nicklas |
413 |
} |
881 |
06 Jul 05 |
nicklas |
414 |
catch (Exception ex) |
881 |
06 Jul 05 |
nicklas |
415 |
{ |
881 |
06 Jul 05 |
nicklas |
416 |
write("--Delete event FAILED"); |
881 |
06 Jul 05 |
nicklas |
417 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
418 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
419 |
} |
881 |
06 Jul 05 |
nicklas |
420 |
finally |
881 |
06 Jul 05 |
nicklas |
421 |
{ |
881 |
06 Jul 05 |
nicklas |
422 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
423 |
} |
881 |
06 Jul 05 |
nicklas |
424 |
} |
881 |
06 Jul 05 |
nicklas |
425 |
|
881 |
06 Jul 05 |
nicklas |
426 |
} |