874 |
05 Jul 05 |
nicklas |
1 |
/* |
874 |
05 Jul 05 |
nicklas |
$Id$ |
874 |
05 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, Nicklas Nordborg |
874 |
05 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/ |
874 |
05 Jul 05 |
nicklas |
9 |
|
874 |
05 Jul 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
874 |
05 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 |
874 |
05 Jul 05 |
nicklas |
of the License, or (at your option) any later version. |
874 |
05 Jul 05 |
nicklas |
14 |
|
874 |
05 Jul 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
874 |
05 Jul 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
874 |
05 Jul 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
874 |
05 Jul 05 |
nicklas |
GNU General Public License for more details. |
874 |
05 Jul 05 |
nicklas |
19 |
|
874 |
05 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/>. |
874 |
05 Jul 05 |
nicklas |
22 |
*/ |
874 |
05 Jul 05 |
nicklas |
23 |
import net.sf.basedb.core.*; |
5338 |
07 May 10 |
nicklas |
24 |
import net.sf.basedb.core.query.Expressions; |
5338 |
07 May 10 |
nicklas |
25 |
import net.sf.basedb.core.query.Hql; |
5338 |
07 May 10 |
nicklas |
26 |
import net.sf.basedb.core.query.Restrictions; |
874 |
05 Jul 05 |
nicklas |
27 |
|
874 |
05 Jul 05 |
nicklas |
28 |
import java.util.Date; |
5338 |
07 May 10 |
nicklas |
29 |
import java.util.List; |
5340 |
10 May 10 |
nicklas |
30 |
import java.util.Set; |
874 |
05 Jul 05 |
nicklas |
31 |
|
874 |
05 Jul 05 |
nicklas |
32 |
public class TestPlateGeometry |
874 |
05 Jul 05 |
nicklas |
33 |
{ |
874 |
05 Jul 05 |
nicklas |
34 |
|
874 |
05 Jul 05 |
nicklas |
35 |
static boolean ok = true; |
874 |
05 Jul 05 |
nicklas |
36 |
public static void main(String[] args) |
874 |
05 Jul 05 |
nicklas |
37 |
{ |
874 |
05 Jul 05 |
nicklas |
38 |
TestUtil.checkArgs(args); |
874 |
05 Jul 05 |
nicklas |
39 |
TestUtil.begin(); |
874 |
05 Jul 05 |
nicklas |
40 |
ok = test_all(); |
874 |
05 Jul 05 |
nicklas |
41 |
TestUtil.stop(); |
874 |
05 Jul 05 |
nicklas |
42 |
} |
874 |
05 Jul 05 |
nicklas |
43 |
|
874 |
05 Jul 05 |
nicklas |
44 |
static boolean test_all() |
874 |
05 Jul 05 |
nicklas |
45 |
{ |
874 |
05 Jul 05 |
nicklas |
46 |
write("++Testing plate geometries"); |
874 |
05 Jul 05 |
nicklas |
47 |
write_header(); |
874 |
05 Jul 05 |
nicklas |
// Standard tests: create, load, list |
874 |
05 Jul 05 |
nicklas |
49 |
int id = test_create(5, 10, true); |
874 |
05 Jul 05 |
nicklas |
50 |
int id2 = test_create(6, 12, false); |
874 |
05 Jul 05 |
nicklas |
51 |
test_load(id); |
874 |
05 Jul 05 |
nicklas |
52 |
test_list(-1); |
874 |
05 Jul 05 |
nicklas |
53 |
|
874 |
05 Jul 05 |
nicklas |
// Standard test: Delete |
1529 |
27 Oct 05 |
nicklas |
55 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
874 |
05 Jul 05 |
nicklas |
56 |
test_delete(id); |
874 |
05 Jul 05 |
nicklas |
57 |
test_delete(id2); |
874 |
05 Jul 05 |
nicklas |
58 |
write("++Testing plate geometries "+(ok ? "OK" : "Failed")+"\n"); |
874 |
05 Jul 05 |
nicklas |
59 |
return ok; |
874 |
05 Jul 05 |
nicklas |
60 |
} |
874 |
05 Jul 05 |
nicklas |
61 |
|
874 |
05 Jul 05 |
nicklas |
62 |
static int test_create(int rows, int columns, boolean setAll) |
874 |
05 Jul 05 |
nicklas |
63 |
{ |
874 |
05 Jul 05 |
nicklas |
64 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.PLATEGEOMETRY)) return 0; |
874 |
05 Jul 05 |
nicklas |
65 |
int id = 0; |
874 |
05 Jul 05 |
nicklas |
66 |
DbControl dc = null; |
874 |
05 Jul 05 |
nicklas |
67 |
try |
874 |
05 Jul 05 |
nicklas |
68 |
{ |
874 |
05 Jul 05 |
nicklas |
69 |
dc = TestUtil.getDbControl(); |
874 |
05 Jul 05 |
nicklas |
70 |
PlateGeometry pg = PlateGeometry.getNew(dc, rows, columns); |
874 |
05 Jul 05 |
nicklas |
71 |
if (setAll) |
874 |
05 Jul 05 |
nicklas |
72 |
{ |
874 |
05 Jul 05 |
nicklas |
73 |
pg.setName("Test plate geometry"); |
874 |
05 Jul 05 |
nicklas |
74 |
pg.setDescription("Added at "+new Date()); |
874 |
05 Jul 05 |
nicklas |
75 |
} |
874 |
05 Jul 05 |
nicklas |
76 |
dc.saveItem(pg); |
874 |
05 Jul 05 |
nicklas |
77 |
dc.commit(); |
874 |
05 Jul 05 |
nicklas |
78 |
id = pg.getId(); |
874 |
05 Jul 05 |
nicklas |
79 |
write_item(0, pg); |
874 |
05 Jul 05 |
nicklas |
80 |
write("--Create plate geometry OK"); |
874 |
05 Jul 05 |
nicklas |
81 |
} |
874 |
05 Jul 05 |
nicklas |
82 |
catch (Throwable ex) |
874 |
05 Jul 05 |
nicklas |
83 |
{ |
874 |
05 Jul 05 |
nicklas |
84 |
write("--Create plate geometry FAILED"); |
874 |
05 Jul 05 |
nicklas |
85 |
ex.printStackTrace(); |
874 |
05 Jul 05 |
nicklas |
86 |
ok = false; |
874 |
05 Jul 05 |
nicklas |
87 |
} |
874 |
05 Jul 05 |
nicklas |
88 |
finally |
874 |
05 Jul 05 |
nicklas |
89 |
{ |
874 |
05 Jul 05 |
nicklas |
90 |
if (dc != null) dc.close(); |
874 |
05 Jul 05 |
nicklas |
91 |
} |
874 |
05 Jul 05 |
nicklas |
92 |
return id; |
874 |
05 Jul 05 |
nicklas |
93 |
} |
874 |
05 Jul 05 |
nicklas |
94 |
|
874 |
05 Jul 05 |
nicklas |
95 |
static void test_load(int id) |
874 |
05 Jul 05 |
nicklas |
96 |
{ |
874 |
05 Jul 05 |
nicklas |
97 |
if (id == 0) return; |
874 |
05 Jul 05 |
nicklas |
98 |
DbControl dc = null; |
874 |
05 Jul 05 |
nicklas |
99 |
try |
874 |
05 Jul 05 |
nicklas |
100 |
{ |
874 |
05 Jul 05 |
nicklas |
101 |
dc = TestUtil.getDbControl(); |
874 |
05 Jul 05 |
nicklas |
102 |
PlateGeometry pg = PlateGeometry.getById(dc, id); |
874 |
05 Jul 05 |
nicklas |
103 |
write_item(0, pg); |
874 |
05 Jul 05 |
nicklas |
104 |
write("--Load plate geometry OK"); |
874 |
05 Jul 05 |
nicklas |
105 |
} |
874 |
05 Jul 05 |
nicklas |
106 |
catch (Throwable ex) |
874 |
05 Jul 05 |
nicklas |
107 |
{ |
874 |
05 Jul 05 |
nicklas |
108 |
write("--Load plate geometry FAILED"); |
874 |
05 Jul 05 |
nicklas |
109 |
ex.printStackTrace(); |
874 |
05 Jul 05 |
nicklas |
110 |
ok = false; |
874 |
05 Jul 05 |
nicklas |
111 |
} |
874 |
05 Jul 05 |
nicklas |
112 |
finally |
874 |
05 Jul 05 |
nicklas |
113 |
{ |
874 |
05 Jul 05 |
nicklas |
114 |
if (dc != null) dc.close(); |
874 |
05 Jul 05 |
nicklas |
115 |
} |
874 |
05 Jul 05 |
nicklas |
116 |
} |
874 |
05 Jul 05 |
nicklas |
117 |
|
874 |
05 Jul 05 |
nicklas |
118 |
|
874 |
05 Jul 05 |
nicklas |
119 |
static void test_list(int expectedResults) |
874 |
05 Jul 05 |
nicklas |
120 |
{ |
874 |
05 Jul 05 |
nicklas |
121 |
DbControl dc = null; |
874 |
05 Jul 05 |
nicklas |
122 |
try |
874 |
05 Jul 05 |
nicklas |
123 |
{ |
874 |
05 Jul 05 |
nicklas |
124 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
125 |
ItemResultList<PlateGeometry> l = PlateGeometry.getQuery().list(dc); |
874 |
05 Jul 05 |
nicklas |
126 |
for (int i = 0; i<l.size(); i++) |
874 |
05 Jul 05 |
nicklas |
127 |
{ |
874 |
05 Jul 05 |
nicklas |
128 |
write_item(i, l.get(i)); |
874 |
05 Jul 05 |
nicklas |
129 |
} |
874 |
05 Jul 05 |
nicklas |
130 |
if (expectedResults >= 0 && expectedResults != l.size()) |
874 |
05 Jul 05 |
nicklas |
131 |
{ |
874 |
05 Jul 05 |
nicklas |
132 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
874 |
05 Jul 05 |
nicklas |
133 |
} |
874 |
05 Jul 05 |
nicklas |
134 |
write("--List plate geometries OK ("+l.size()+")"); |
874 |
05 Jul 05 |
nicklas |
135 |
} |
874 |
05 Jul 05 |
nicklas |
136 |
catch (Throwable ex) |
874 |
05 Jul 05 |
nicklas |
137 |
{ |
874 |
05 Jul 05 |
nicklas |
138 |
write("--List plate geometries FAILED"); |
874 |
05 Jul 05 |
nicklas |
139 |
ex.printStackTrace(); |
874 |
05 Jul 05 |
nicklas |
140 |
ok = false; |
874 |
05 Jul 05 |
nicklas |
141 |
} |
874 |
05 Jul 05 |
nicklas |
142 |
finally |
874 |
05 Jul 05 |
nicklas |
143 |
{ |
874 |
05 Jul 05 |
nicklas |
144 |
if (dc != null) dc.close(); |
874 |
05 Jul 05 |
nicklas |
145 |
} |
874 |
05 Jul 05 |
nicklas |
146 |
} |
874 |
05 Jul 05 |
nicklas |
147 |
|
874 |
05 Jul 05 |
nicklas |
148 |
|
874 |
05 Jul 05 |
nicklas |
149 |
static void test_delete(int id) |
874 |
05 Jul 05 |
nicklas |
150 |
{ |
874 |
05 Jul 05 |
nicklas |
151 |
if (id == 0) return; |
874 |
05 Jul 05 |
nicklas |
152 |
DbControl dc = null; |
874 |
05 Jul 05 |
nicklas |
153 |
try |
874 |
05 Jul 05 |
nicklas |
154 |
{ |
874 |
05 Jul 05 |
nicklas |
155 |
dc = TestUtil.getDbControl(); |
874 |
05 Jul 05 |
nicklas |
156 |
PlateGeometry pg = PlateGeometry.getById(dc, id); |
874 |
05 Jul 05 |
nicklas |
157 |
dc.deleteItem(pg); |
5340 |
10 May 10 |
nicklas |
158 |
Set<ItemProxy> using = pg.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
159 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
160 |
{ |
5340 |
10 May 10 |
nicklas |
161 |
throw new BaseException(pg + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
162 |
} |
874 |
05 Jul 05 |
nicklas |
163 |
dc.commit(); |
874 |
05 Jul 05 |
nicklas |
164 |
write("--Delete plate geometry OK"); |
874 |
05 Jul 05 |
nicklas |
165 |
} |
874 |
05 Jul 05 |
nicklas |
166 |
catch (Throwable ex) |
874 |
05 Jul 05 |
nicklas |
167 |
{ |
874 |
05 Jul 05 |
nicklas |
168 |
write("--Delete plate geometry FAILED"); |
874 |
05 Jul 05 |
nicklas |
169 |
ex.printStackTrace(); |
874 |
05 Jul 05 |
nicklas |
170 |
ok = false; |
874 |
05 Jul 05 |
nicklas |
171 |
} |
874 |
05 Jul 05 |
nicklas |
172 |
finally |
874 |
05 Jul 05 |
nicklas |
173 |
{ |
874 |
05 Jul 05 |
nicklas |
174 |
if (dc != null) dc.close(); |
874 |
05 Jul 05 |
nicklas |
175 |
} |
874 |
05 Jul 05 |
nicklas |
176 |
} |
874 |
05 Jul 05 |
nicklas |
177 |
|
874 |
05 Jul 05 |
nicklas |
178 |
static void write_header() |
874 |
05 Jul 05 |
nicklas |
179 |
{ |
874 |
05 Jul 05 |
nicklas |
180 |
if (!TestUtil.getSilent()) |
874 |
05 Jul 05 |
nicklas |
181 |
{ |
874 |
05 Jul 05 |
nicklas |
182 |
System.out.println(" \tID \tName \tDescription\tRows\tColumns"); |
874 |
05 Jul 05 |
nicklas |
183 |
System.out.println("-- \t-- \t--------- \t-----------\t----\t-------"); |
874 |
05 Jul 05 |
nicklas |
184 |
} |
874 |
05 Jul 05 |
nicklas |
185 |
} |
874 |
05 Jul 05 |
nicklas |
186 |
static void write_item(int i, PlateGeometry pg) |
874 |
05 Jul 05 |
nicklas |
187 |
throws BaseException |
874 |
05 Jul 05 |
nicklas |
188 |
{ |
874 |
05 Jul 05 |
nicklas |
189 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+pg.getId()+"\t"+pg.getName()+"\t"+pg.getDescription()+ |
874 |
05 Jul 05 |
nicklas |
190 |
"\t"+pg.getRows()+"\t"+pg.getColumns()); |
874 |
05 Jul 05 |
nicklas |
191 |
} |
874 |
05 Jul 05 |
nicklas |
192 |
static void write(String message) |
874 |
05 Jul 05 |
nicklas |
193 |
{ |
874 |
05 Jul 05 |
nicklas |
194 |
System.out.println(message); |
874 |
05 Jul 05 |
nicklas |
195 |
} |
874 |
05 Jul 05 |
nicklas |
196 |
|
5338 |
07 May 10 |
nicklas |
197 |
static int test_find_by_size(int rows, int cols) |
5338 |
07 May 10 |
nicklas |
198 |
{ |
5338 |
07 May 10 |
nicklas |
199 |
DbControl dc = null; |
5338 |
07 May 10 |
nicklas |
200 |
int id = 0; |
5338 |
07 May 10 |
nicklas |
201 |
try |
5338 |
07 May 10 |
nicklas |
202 |
{ |
5338 |
07 May 10 |
nicklas |
203 |
dc = TestUtil.getDbControl(); |
5338 |
07 May 10 |
nicklas |
204 |
ItemQuery<PlateGeometry> query = PlateGeometry.getQuery(); |
5338 |
07 May 10 |
nicklas |
205 |
query.restrict(Restrictions.eq(Hql.property("rows"), Expressions.integer(rows))); |
5338 |
07 May 10 |
nicklas |
206 |
query.restrict(Restrictions.eq(Hql.property("columns"), Expressions.integer(cols))); |
5338 |
07 May 10 |
nicklas |
207 |
List<PlateGeometry> list = query.list(dc); |
5338 |
07 May 10 |
nicklas |
208 |
if (list.size() == 0) |
5338 |
07 May 10 |
nicklas |
209 |
{ |
5338 |
07 May 10 |
nicklas |
210 |
throw new ItemNotFoundException("Plate geometry [rows=" + rows + "; cols=" + cols + "]"); |
5338 |
07 May 10 |
nicklas |
211 |
} |
5338 |
07 May 10 |
nicklas |
212 |
id = list.get(0).getId(); |
5338 |
07 May 10 |
nicklas |
213 |
write("--Get plate geometry [rows=" + rows + "; cols=" + cols + "] OK"); |
5338 |
07 May 10 |
nicklas |
214 |
} |
5338 |
07 May 10 |
nicklas |
215 |
catch (Throwable ex) |
5338 |
07 May 10 |
nicklas |
216 |
{ |
5338 |
07 May 10 |
nicklas |
217 |
write("--Get plate geometry [rows=" + rows + "; cols=" + cols + "] FAILED"); |
5338 |
07 May 10 |
nicklas |
218 |
ex.printStackTrace(); |
5338 |
07 May 10 |
nicklas |
219 |
ok = false; |
5338 |
07 May 10 |
nicklas |
220 |
} |
5338 |
07 May 10 |
nicklas |
221 |
finally |
5338 |
07 May 10 |
nicklas |
222 |
{ |
5338 |
07 May 10 |
nicklas |
223 |
if (dc != null) dc.close(); |
5338 |
07 May 10 |
nicklas |
224 |
} |
5338 |
07 May 10 |
nicklas |
225 |
return id; |
5338 |
07 May 10 |
nicklas |
226 |
} |
5338 |
07 May 10 |
nicklas |
227 |
|
5338 |
07 May 10 |
nicklas |
228 |
|
874 |
05 Jul 05 |
nicklas |
229 |
} |