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 Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen |
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.*; |
881 |
06 Jul 05 |
nicklas |
24 |
import net.sf.basedb.core.data.MappingCoordinate; |
5343 |
11 May 10 |
nicklas |
25 |
import net.sf.basedb.core.query.Expressions; |
5343 |
11 May 10 |
nicklas |
26 |
import net.sf.basedb.core.query.Hql; |
5343 |
11 May 10 |
nicklas |
27 |
import net.sf.basedb.core.query.Restrictions; |
5343 |
11 May 10 |
nicklas |
28 |
|
881 |
06 Jul 05 |
nicklas |
29 |
import java.util.Date; |
881 |
06 Jul 05 |
nicklas |
30 |
import java.util.List; |
881 |
06 Jul 05 |
nicklas |
31 |
import java.util.ArrayList; |
5340 |
10 May 10 |
nicklas |
32 |
import java.util.Set; |
881 |
06 Jul 05 |
nicklas |
33 |
|
881 |
06 Jul 05 |
nicklas |
34 |
public class TestPlateMapping |
881 |
06 Jul 05 |
nicklas |
35 |
{ |
881 |
06 Jul 05 |
nicklas |
36 |
|
881 |
06 Jul 05 |
nicklas |
37 |
static boolean ok = true; |
881 |
06 Jul 05 |
nicklas |
38 |
public static void main(String[] args) |
881 |
06 Jul 05 |
nicklas |
39 |
{ |
881 |
06 Jul 05 |
nicklas |
40 |
TestUtil.checkArgs(args); |
881 |
06 Jul 05 |
nicklas |
41 |
TestUtil.begin(); |
881 |
06 Jul 05 |
nicklas |
42 |
ok = test_all(); |
881 |
06 Jul 05 |
nicklas |
43 |
TestUtil.stop(); |
881 |
06 Jul 05 |
nicklas |
44 |
} |
881 |
06 Jul 05 |
nicklas |
45 |
|
881 |
06 Jul 05 |
nicklas |
46 |
static boolean test_all() |
881 |
06 Jul 05 |
nicklas |
47 |
{ |
881 |
06 Jul 05 |
nicklas |
48 |
write("++Testing plate mapping"); |
881 |
06 Jul 05 |
nicklas |
49 |
write_header(); |
881 |
06 Jul 05 |
nicklas |
// Standard tests: create, load, list |
881 |
06 Jul 05 |
nicklas |
51 |
int sourceGeometryId = TestPlateGeometry.test_create(5, 5, false); |
881 |
06 Jul 05 |
nicklas |
52 |
int destinationGeometryId = TestPlateGeometry.test_create(10, 10, false); |
881 |
06 Jul 05 |
nicklas |
53 |
|
881 |
06 Jul 05 |
nicklas |
54 |
int id = test_create(sourceGeometryId, destinationGeometryId); |
881 |
06 Jul 05 |
nicklas |
55 |
test_load(id); |
881 |
06 Jul 05 |
nicklas |
56 |
test_list(-1); |
881 |
06 Jul 05 |
nicklas |
57 |
|
881 |
06 Jul 05 |
nicklas |
// Extra tests: apply mapping to plates |
881 |
06 Jul 05 |
nicklas |
59 |
int sourcePlateTypeId = TestPlateType.test_create(sourceGeometryId, false); |
881 |
06 Jul 05 |
nicklas |
60 |
int destinationPlateTypeId = TestPlateType.test_create(destinationGeometryId, false); |
881 |
06 Jul 05 |
nicklas |
61 |
int[] sourcePlateIds = new int[4]; |
881 |
06 Jul 05 |
nicklas |
62 |
for (int i = 0; i < 4; i++) |
881 |
06 Jul 05 |
nicklas |
63 |
{ |
881 |
06 Jul 05 |
nicklas |
64 |
sourcePlateIds[i] = TestPlate.test_create(sourcePlateTypeId, false); |
881 |
06 Jul 05 |
nicklas |
65 |
} |
881 |
06 Jul 05 |
nicklas |
66 |
int mappedId = test_apply_mapping(id, sourcePlateIds, destinationPlateTypeId); |
881 |
06 Jul 05 |
nicklas |
67 |
TestPlate.test_list(-1); |
881 |
06 Jul 05 |
nicklas |
68 |
|
1148 |
30 Aug 05 |
nicklas |
// Extra test: list parents and children to plates |
1148 |
30 Aug 05 |
nicklas |
70 |
test_list_parents(mappedId, 4); |
1148 |
30 Aug 05 |
nicklas |
71 |
test_list_children(sourcePlateIds[0], 1); |
1148 |
30 Aug 05 |
nicklas |
72 |
|
1529 |
27 Oct 05 |
nicklas |
73 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
881 |
06 Jul 05 |
nicklas |
74 |
TestPlate.test_delete(mappedId); |
881 |
06 Jul 05 |
nicklas |
75 |
for (int i = 0; i < 4; i++) |
881 |
06 Jul 05 |
nicklas |
76 |
{ |
881 |
06 Jul 05 |
nicklas |
77 |
TestPlate.test_delete(sourcePlateIds[i]); |
881 |
06 Jul 05 |
nicklas |
78 |
} |
881 |
06 Jul 05 |
nicklas |
79 |
TestPlateType.test_delete(destinationPlateTypeId); |
881 |
06 Jul 05 |
nicklas |
80 |
TestPlateType.test_delete(sourcePlateTypeId); |
881 |
06 Jul 05 |
nicklas |
81 |
|
881 |
06 Jul 05 |
nicklas |
// Standard test: Delete |
881 |
06 Jul 05 |
nicklas |
83 |
test_delete(id); |
881 |
06 Jul 05 |
nicklas |
84 |
TestPlateGeometry.test_delete(sourceGeometryId); |
881 |
06 Jul 05 |
nicklas |
85 |
TestPlateGeometry.test_delete(destinationGeometryId); |
881 |
06 Jul 05 |
nicklas |
86 |
|
881 |
06 Jul 05 |
nicklas |
87 |
write("++Testing plate mapping "+(ok ? "OK" : "Failed")+"\n"); |
881 |
06 Jul 05 |
nicklas |
88 |
return ok; |
881 |
06 Jul 05 |
nicklas |
89 |
} |
881 |
06 Jul 05 |
nicklas |
90 |
|
881 |
06 Jul 05 |
nicklas |
91 |
static int test_create(int sourceGeometryId, int destinationGeometryId) |
881 |
06 Jul 05 |
nicklas |
92 |
{ |
881 |
06 Jul 05 |
nicklas |
93 |
if (sourceGeometryId == 0 || destinationGeometryId == 0 || |
881 |
06 Jul 05 |
nicklas |
94 |
!TestUtil.hasPermission(Permission.CREATE, Item.PLATEMAPPING)) return 0; |
881 |
06 Jul 05 |
nicklas |
95 |
int id = 0; |
881 |
06 Jul 05 |
nicklas |
96 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
97 |
try |
881 |
06 Jul 05 |
nicklas |
98 |
{ |
881 |
06 Jul 05 |
nicklas |
99 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
100 |
PlateGeometry source = PlateGeometry.getById(dc, sourceGeometryId); |
881 |
06 Jul 05 |
nicklas |
101 |
PlateGeometry destination = PlateGeometry.getById(dc, destinationGeometryId); |
881 |
06 Jul 05 |
nicklas |
102 |
PlateMapping pm = PlateMapping.getNew(dc, source, 4, destination, 1); |
881 |
06 Jul 05 |
nicklas |
103 |
pm.setName("Test plate mapping"); |
881 |
06 Jul 05 |
nicklas |
104 |
pm.setDescription("Maps 4 5x5 plates to 1 10x10 plate"); |
881 |
06 Jul 05 |
nicklas |
105 |
|
881 |
06 Jul 05 |
nicklas |
106 |
for (int plate = 0; plate < 4; plate++) |
881 |
06 Jul 05 |
nicklas |
107 |
{ |
881 |
06 Jul 05 |
nicklas |
108 |
int rowOffset = (plate == 0 || plate == 1) ? 0 : 5; |
881 |
06 Jul 05 |
nicklas |
109 |
int columnOffset = (plate == 0 || plate == 2) ? 0 : 5; |
881 |
06 Jul 05 |
nicklas |
110 |
for (int row = 0; row < 5; row++) |
881 |
06 Jul 05 |
nicklas |
111 |
{ |
881 |
06 Jul 05 |
nicklas |
112 |
for (int column = 0; column < 5; column++) |
881 |
06 Jul 05 |
nicklas |
113 |
{ |
881 |
06 Jul 05 |
nicklas |
114 |
MappingCoordinate from = new MappingCoordinate(plate, row, column); |
881 |
06 Jul 05 |
nicklas |
115 |
MappingCoordinate to = new MappingCoordinate( |
881 |
06 Jul 05 |
nicklas |
116 |
0, row + rowOffset, column + columnOffset); |
881 |
06 Jul 05 |
nicklas |
117 |
pm.setSourceCoordinate(to, from); |
881 |
06 Jul 05 |
nicklas |
118 |
} |
881 |
06 Jul 05 |
nicklas |
119 |
} |
881 |
06 Jul 05 |
nicklas |
120 |
} |
881 |
06 Jul 05 |
nicklas |
121 |
dc.saveItem(pm); |
881 |
06 Jul 05 |
nicklas |
122 |
dc.commit(); |
881 |
06 Jul 05 |
nicklas |
123 |
id = pm.getId(); |
881 |
06 Jul 05 |
nicklas |
124 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
125 |
dc.reattachItem(pm, false); |
881 |
06 Jul 05 |
nicklas |
126 |
write_item(0, pm); |
881 |
06 Jul 05 |
nicklas |
127 |
write("--Create plate mapping OK"); |
881 |
06 Jul 05 |
nicklas |
128 |
} |
881 |
06 Jul 05 |
nicklas |
129 |
catch (Exception ex) |
881 |
06 Jul 05 |
nicklas |
130 |
{ |
881 |
06 Jul 05 |
nicklas |
131 |
write("--Create plate mapping FAILED"); |
881 |
06 Jul 05 |
nicklas |
132 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
133 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
134 |
} |
881 |
06 Jul 05 |
nicklas |
135 |
finally |
881 |
06 Jul 05 |
nicklas |
136 |
{ |
881 |
06 Jul 05 |
nicklas |
137 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
138 |
} |
881 |
06 Jul 05 |
nicklas |
139 |
return id; |
881 |
06 Jul 05 |
nicklas |
140 |
} |
881 |
06 Jul 05 |
nicklas |
141 |
|
881 |
06 Jul 05 |
nicklas |
142 |
static void test_load(int id) |
881 |
06 Jul 05 |
nicklas |
143 |
{ |
881 |
06 Jul 05 |
nicklas |
144 |
if (id == 0) return; |
881 |
06 Jul 05 |
nicklas |
145 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
146 |
try |
881 |
06 Jul 05 |
nicklas |
147 |
{ |
881 |
06 Jul 05 |
nicklas |
148 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
149 |
PlateMapping pm = PlateMapping.getById(dc, id); |
881 |
06 Jul 05 |
nicklas |
150 |
write_item(0, pm); |
881 |
06 Jul 05 |
nicklas |
151 |
write("--Load plate mapping OK"); |
881 |
06 Jul 05 |
nicklas |
152 |
} |
881 |
06 Jul 05 |
nicklas |
153 |
catch (Throwable ex) |
881 |
06 Jul 05 |
nicklas |
154 |
{ |
881 |
06 Jul 05 |
nicklas |
155 |
write("--Load plate mapping FAILED"); |
881 |
06 Jul 05 |
nicklas |
156 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
157 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
158 |
} |
881 |
06 Jul 05 |
nicklas |
159 |
finally |
881 |
06 Jul 05 |
nicklas |
160 |
{ |
881 |
06 Jul 05 |
nicklas |
161 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
162 |
} |
881 |
06 Jul 05 |
nicklas |
163 |
} |
881 |
06 Jul 05 |
nicklas |
164 |
|
881 |
06 Jul 05 |
nicklas |
165 |
static void test_list(int expectedResults) |
881 |
06 Jul 05 |
nicklas |
166 |
{ |
881 |
06 Jul 05 |
nicklas |
167 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
168 |
try |
881 |
06 Jul 05 |
nicklas |
169 |
{ |
881 |
06 Jul 05 |
nicklas |
170 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
171 |
ItemResultList<PlateMapping> l = PlateMapping.getQuery().list(dc); |
881 |
06 Jul 05 |
nicklas |
172 |
for (int i = 0; i<l.size(); i++) |
881 |
06 Jul 05 |
nicklas |
173 |
{ |
881 |
06 Jul 05 |
nicklas |
174 |
write_item(i, l.get(i)); |
881 |
06 Jul 05 |
nicklas |
175 |
} |
881 |
06 Jul 05 |
nicklas |
176 |
if (expectedResults >= 0 && expectedResults != l.size()) |
881 |
06 Jul 05 |
nicklas |
177 |
{ |
881 |
06 Jul 05 |
nicklas |
178 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
881 |
06 Jul 05 |
nicklas |
179 |
} |
881 |
06 Jul 05 |
nicklas |
180 |
write("--List plate mappings OK ("+l.size()+")"); |
881 |
06 Jul 05 |
nicklas |
181 |
} |
881 |
06 Jul 05 |
nicklas |
182 |
catch (Throwable ex) |
881 |
06 Jul 05 |
nicklas |
183 |
{ |
881 |
06 Jul 05 |
nicklas |
184 |
write("--List plate mappings FAILED"); |
881 |
06 Jul 05 |
nicklas |
185 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
186 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
187 |
} |
881 |
06 Jul 05 |
nicklas |
188 |
finally |
881 |
06 Jul 05 |
nicklas |
189 |
{ |
881 |
06 Jul 05 |
nicklas |
190 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
191 |
} |
881 |
06 Jul 05 |
nicklas |
192 |
} |
881 |
06 Jul 05 |
nicklas |
193 |
|
881 |
06 Jul 05 |
nicklas |
194 |
static void test_delete(int id) |
881 |
06 Jul 05 |
nicklas |
195 |
{ |
881 |
06 Jul 05 |
nicklas |
196 |
if (id == 0) return; |
881 |
06 Jul 05 |
nicklas |
197 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
198 |
try |
881 |
06 Jul 05 |
nicklas |
199 |
{ |
881 |
06 Jul 05 |
nicklas |
200 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
201 |
PlateMapping pm = PlateMapping.getById(dc, id); |
881 |
06 Jul 05 |
nicklas |
202 |
dc.deleteItem(pm); |
5340 |
10 May 10 |
nicklas |
203 |
Set<ItemProxy> using = pm.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
204 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
205 |
{ |
5340 |
10 May 10 |
nicklas |
206 |
throw new BaseException(pm + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
207 |
} |
881 |
06 Jul 05 |
nicklas |
208 |
dc.commit(); |
881 |
06 Jul 05 |
nicklas |
209 |
write("--Delete plate mapping OK"); |
881 |
06 Jul 05 |
nicklas |
210 |
} |
881 |
06 Jul 05 |
nicklas |
211 |
catch (Throwable ex) |
881 |
06 Jul 05 |
nicklas |
212 |
{ |
881 |
06 Jul 05 |
nicklas |
213 |
write("--Delete plate mapping FAILED"); |
881 |
06 Jul 05 |
nicklas |
214 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
215 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
216 |
} |
881 |
06 Jul 05 |
nicklas |
217 |
finally |
881 |
06 Jul 05 |
nicklas |
218 |
{ |
881 |
06 Jul 05 |
nicklas |
219 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
220 |
} |
881 |
06 Jul 05 |
nicklas |
221 |
} |
881 |
06 Jul 05 |
nicklas |
222 |
|
881 |
06 Jul 05 |
nicklas |
223 |
static void write_header() |
881 |
06 Jul 05 |
nicklas |
224 |
{ |
881 |
06 Jul 05 |
nicklas |
225 |
if (!TestUtil.getSilent()) |
881 |
06 Jul 05 |
nicklas |
226 |
{ |
881 |
06 Jul 05 |
nicklas |
227 |
write(" \tID \tName \tDescription\tSource\tDestination"); |
881 |
06 Jul 05 |
nicklas |
228 |
write("-- \t-- \t--------- \t-----------\t------\t-----------"); |
881 |
06 Jul 05 |
nicklas |
229 |
} |
881 |
06 Jul 05 |
nicklas |
230 |
} |
881 |
06 Jul 05 |
nicklas |
231 |
static void write_item(int i, PlateMapping pm) |
881 |
06 Jul 05 |
nicklas |
232 |
throws BaseException |
881 |
06 Jul 05 |
nicklas |
233 |
{ |
881 |
06 Jul 05 |
nicklas |
234 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+pm.getId()+"\t"+pm.getName()+"\t"+ |
881 |
06 Jul 05 |
nicklas |
235 |
pm.getDescription()+"\t"+pm.getSourceGeometry()+"["+pm.getSourceCount()+"]\t"+ |
881 |
06 Jul 05 |
nicklas |
236 |
pm.getDestinationGeometry()+"["+pm.getDestinationCount()+"]\t"); |
881 |
06 Jul 05 |
nicklas |
237 |
} |
1148 |
30 Aug 05 |
nicklas |
238 |
static void write_item(int i, Plate p, int sourceIndex) |
1148 |
30 Aug 05 |
nicklas |
239 |
throws BaseException |
1148 |
30 Aug 05 |
nicklas |
240 |
{ |
1148 |
30 Aug 05 |
nicklas |
241 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+p.getId()+"\t"+p.getName()+"\t"+sourceIndex); |
1148 |
30 Aug 05 |
nicklas |
242 |
} |
881 |
06 Jul 05 |
nicklas |
243 |
static void write(String message) |
881 |
06 Jul 05 |
nicklas |
244 |
{ |
881 |
06 Jul 05 |
nicklas |
245 |
System.out.println(message); |
881 |
06 Jul 05 |
nicklas |
246 |
} |
881 |
06 Jul 05 |
nicklas |
247 |
|
881 |
06 Jul 05 |
nicklas |
248 |
static int test_apply_mapping(int plateMappingId, int[] sourcePlateIds, int destinationPlateTypeId) |
881 |
06 Jul 05 |
nicklas |
249 |
{ |
881 |
06 Jul 05 |
nicklas |
250 |
if (plateMappingId == 0 || destinationPlateTypeId == 0) return 0; |
881 |
06 Jul 05 |
nicklas |
251 |
DbControl dc = null; |
881 |
06 Jul 05 |
nicklas |
252 |
int id = 0; |
881 |
06 Jul 05 |
nicklas |
253 |
try |
881 |
06 Jul 05 |
nicklas |
254 |
{ |
881 |
06 Jul 05 |
nicklas |
255 |
dc = TestUtil.getDbControl(); |
881 |
06 Jul 05 |
nicklas |
256 |
PlateMapping pm = PlateMapping.getById(dc, plateMappingId); |
881 |
06 Jul 05 |
nicklas |
257 |
PlateType destinationType = PlateType.getById(dc, destinationPlateTypeId); |
881 |
06 Jul 05 |
nicklas |
258 |
List<Plate> sourcePlates = new ArrayList<Plate>(sourcePlateIds.length); |
881 |
06 Jul 05 |
nicklas |
259 |
for (int i = 0; i < sourcePlateIds.length; i++) |
881 |
06 Jul 05 |
nicklas |
260 |
{ |
881 |
06 Jul 05 |
nicklas |
261 |
if (sourcePlateIds[i] != 0) |
881 |
06 Jul 05 |
nicklas |
262 |
{ |
881 |
06 Jul 05 |
nicklas |
263 |
sourcePlates.add(Plate.getById(dc, sourcePlateIds[i])); |
881 |
06 Jul 05 |
nicklas |
264 |
} |
881 |
06 Jul 05 |
nicklas |
265 |
} |
881 |
06 Jul 05 |
nicklas |
266 |
List<Plate> destinationPlates = pm.apply(sourcePlates, destinationType); |
881 |
06 Jul 05 |
nicklas |
267 |
Plate p = destinationPlates.get(0); |
881 |
06 Jul 05 |
nicklas |
268 |
p.setName("Test apply mapping"); |
881 |
06 Jul 05 |
nicklas |
269 |
p.setDescription("Added at "+new Date()); |
881 |
06 Jul 05 |
nicklas |
270 |
dc.saveItem(p); |
881 |
06 Jul 05 |
nicklas |
271 |
dc.commit(); |
881 |
06 Jul 05 |
nicklas |
272 |
id = p.getId(); |
881 |
06 Jul 05 |
nicklas |
273 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
274 |
dc.reattachItem(p, false); |
881 |
06 Jul 05 |
nicklas |
275 |
TestPlate.write_item(0, p); |
881 |
06 Jul 05 |
nicklas |
276 |
write("--Apply plate mapping OK"); |
881 |
06 Jul 05 |
nicklas |
277 |
} |
881 |
06 Jul 05 |
nicklas |
278 |
catch (Exception ex) |
881 |
06 Jul 05 |
nicklas |
279 |
{ |
881 |
06 Jul 05 |
nicklas |
280 |
write("--Apply plate mapping FAILED"); |
881 |
06 Jul 05 |
nicklas |
281 |
ex.printStackTrace(); |
881 |
06 Jul 05 |
nicklas |
282 |
ok = false; |
881 |
06 Jul 05 |
nicklas |
283 |
} |
881 |
06 Jul 05 |
nicklas |
284 |
finally |
881 |
06 Jul 05 |
nicklas |
285 |
{ |
881 |
06 Jul 05 |
nicklas |
286 |
if (dc != null) dc.close(); |
881 |
06 Jul 05 |
nicklas |
287 |
} |
881 |
06 Jul 05 |
nicklas |
288 |
return id; |
881 |
06 Jul 05 |
nicklas |
289 |
} |
881 |
06 Jul 05 |
nicklas |
290 |
|
1148 |
30 Aug 05 |
nicklas |
291 |
static void test_list_parents(int plateId, int expectedResults) |
1148 |
30 Aug 05 |
nicklas |
292 |
{ |
1148 |
30 Aug 05 |
nicklas |
293 |
if (plateId == 0) return; |
1148 |
30 Aug 05 |
nicklas |
294 |
DbControl dc = null; |
1148 |
30 Aug 05 |
nicklas |
295 |
try |
1148 |
30 Aug 05 |
nicklas |
296 |
{ |
1148 |
30 Aug 05 |
nicklas |
297 |
dc = TestUtil.getDbControl(); |
1148 |
30 Aug 05 |
nicklas |
298 |
Plate p = Plate.getById(dc, plateId); |
1418 |
07 Oct 05 |
nicklas |
299 |
ItemResultList<Plate> l = p.getParentPlates().list(dc); |
1148 |
30 Aug 05 |
nicklas |
300 |
for (int i = 0; i<l.size(); i++) |
1148 |
30 Aug 05 |
nicklas |
301 |
{ |
1148 |
30 Aug 05 |
nicklas |
302 |
Plate parent = l.get(i); |
1148 |
30 Aug 05 |
nicklas |
303 |
write_item(i, parent, p.getSourceIndex(parent)); |
1148 |
30 Aug 05 |
nicklas |
304 |
} |
1148 |
30 Aug 05 |
nicklas |
305 |
if (expectedResults >= 0 && expectedResults != l.size()) |
1148 |
30 Aug 05 |
nicklas |
306 |
{ |
1148 |
30 Aug 05 |
nicklas |
307 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
1148 |
30 Aug 05 |
nicklas |
308 |
} |
1148 |
30 Aug 05 |
nicklas |
309 |
write("--List parent plates OK ("+l.size()+")"); |
1148 |
30 Aug 05 |
nicklas |
310 |
} |
1148 |
30 Aug 05 |
nicklas |
311 |
catch (Throwable ex) |
1148 |
30 Aug 05 |
nicklas |
312 |
{ |
1148 |
30 Aug 05 |
nicklas |
313 |
write("--List parents plates FAILED"); |
1148 |
30 Aug 05 |
nicklas |
314 |
ex.printStackTrace(); |
1148 |
30 Aug 05 |
nicklas |
315 |
ok = false; |
1148 |
30 Aug 05 |
nicklas |
316 |
} |
1148 |
30 Aug 05 |
nicklas |
317 |
finally |
1148 |
30 Aug 05 |
nicklas |
318 |
{ |
1148 |
30 Aug 05 |
nicklas |
319 |
if (dc != null) dc.close(); |
1148 |
30 Aug 05 |
nicklas |
320 |
} |
1148 |
30 Aug 05 |
nicklas |
321 |
} |
881 |
06 Jul 05 |
nicklas |
322 |
|
1148 |
30 Aug 05 |
nicklas |
323 |
static void test_list_children(int plateId, int expectedResults) |
1148 |
30 Aug 05 |
nicklas |
324 |
{ |
1148 |
30 Aug 05 |
nicklas |
325 |
if (plateId == 0) return; |
1148 |
30 Aug 05 |
nicklas |
326 |
DbControl dc = null; |
1148 |
30 Aug 05 |
nicklas |
327 |
try |
1148 |
30 Aug 05 |
nicklas |
328 |
{ |
1148 |
30 Aug 05 |
nicklas |
329 |
dc = TestUtil.getDbControl(); |
1148 |
30 Aug 05 |
nicklas |
330 |
Plate p = Plate.getById(dc, plateId); |
1418 |
07 Oct 05 |
nicklas |
331 |
ItemResultList<Plate> l = p.getChildPlates().list(dc); |
1148 |
30 Aug 05 |
nicklas |
332 |
for (int i = 0; i<l.size(); i++) |
1148 |
30 Aug 05 |
nicklas |
333 |
{ |
1148 |
30 Aug 05 |
nicklas |
334 |
Plate child = l.get(i); |
1148 |
30 Aug 05 |
nicklas |
335 |
write_item(i, child, child.getDestinationIndex()); |
1148 |
30 Aug 05 |
nicklas |
336 |
} |
1148 |
30 Aug 05 |
nicklas |
337 |
if (expectedResults >= 0 && expectedResults != l.size()) |
1148 |
30 Aug 05 |
nicklas |
338 |
{ |
1148 |
30 Aug 05 |
nicklas |
339 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
1148 |
30 Aug 05 |
nicklas |
340 |
} |
1148 |
30 Aug 05 |
nicklas |
341 |
write("--List child plates OK ("+l.size()+")"); |
1148 |
30 Aug 05 |
nicklas |
342 |
} |
1148 |
30 Aug 05 |
nicklas |
343 |
catch (Throwable ex) |
1148 |
30 Aug 05 |
nicklas |
344 |
{ |
1148 |
30 Aug 05 |
nicklas |
345 |
write("--List child plates FAILED"); |
1148 |
30 Aug 05 |
nicklas |
346 |
ex.printStackTrace(); |
1148 |
30 Aug 05 |
nicklas |
347 |
ok = false; |
1148 |
30 Aug 05 |
nicklas |
348 |
} |
1148 |
30 Aug 05 |
nicklas |
349 |
finally |
1148 |
30 Aug 05 |
nicklas |
350 |
{ |
1148 |
30 Aug 05 |
nicklas |
351 |
if (dc != null) dc.close(); |
1148 |
30 Aug 05 |
nicklas |
352 |
} |
1148 |
30 Aug 05 |
nicklas |
353 |
} |
881 |
06 Jul 05 |
nicklas |
354 |
|
5343 |
11 May 10 |
nicklas |
355 |
static int test_find_by_geometry(int source, int destination) |
5343 |
11 May 10 |
nicklas |
356 |
{ |
5343 |
11 May 10 |
nicklas |
357 |
DbControl dc = null; |
5343 |
11 May 10 |
nicklas |
358 |
int id = 0; |
5343 |
11 May 10 |
nicklas |
359 |
try |
5343 |
11 May 10 |
nicklas |
360 |
{ |
5343 |
11 May 10 |
nicklas |
361 |
dc = TestUtil.getDbControl(); |
5343 |
11 May 10 |
nicklas |
362 |
ItemQuery<PlateMapping> query = PlateMapping.getQuery(); |
5343 |
11 May 10 |
nicklas |
363 |
query.restrict(Restrictions.eq(Hql.property("sourceGeometry"), Expressions.integer(source))); |
5343 |
11 May 10 |
nicklas |
364 |
query.restrict(Restrictions.eq(Hql.property("destinationGeometry"), Expressions.integer(destination))); |
5343 |
11 May 10 |
nicklas |
365 |
List<PlateMapping> list = query.list(dc); |
5343 |
11 May 10 |
nicklas |
366 |
if (list.size() == 0) |
5343 |
11 May 10 |
nicklas |
367 |
{ |
5343 |
11 May 10 |
nicklas |
368 |
throw new ItemNotFoundException("Plate mapping [source id=" + source + "; dest id="+destination +"]"); |
5343 |
11 May 10 |
nicklas |
369 |
} |
5343 |
11 May 10 |
nicklas |
370 |
id = list.get(0).getId(); |
5343 |
11 May 10 |
nicklas |
371 |
write("--Get plate mapping OK"); |
5343 |
11 May 10 |
nicklas |
372 |
} |
5343 |
11 May 10 |
nicklas |
373 |
catch (Throwable ex) |
5343 |
11 May 10 |
nicklas |
374 |
{ |
5343 |
11 May 10 |
nicklas |
375 |
write("--Get plate mapping FAILED"); |
5343 |
11 May 10 |
nicklas |
376 |
ex.printStackTrace(); |
5343 |
11 May 10 |
nicklas |
377 |
ok = false; |
5343 |
11 May 10 |
nicklas |
378 |
} |
5343 |
11 May 10 |
nicklas |
379 |
finally |
5343 |
11 May 10 |
nicklas |
380 |
{ |
5343 |
11 May 10 |
nicklas |
381 |
if (dc != null) dc.close(); |
5343 |
11 May 10 |
nicklas |
382 |
} |
5343 |
11 May 10 |
nicklas |
383 |
return id; |
5343 |
11 May 10 |
nicklas |
384 |
} |
881 |
06 Jul 05 |
nicklas |
385 |
|
881 |
06 Jul 05 |
nicklas |
386 |
} |
881 |
06 Jul 05 |
nicklas |
387 |
|