1682 |
02 Dec 05 |
nicklas |
1 |
/* |
1682 |
02 Dec 05 |
nicklas |
$Id$ |
1682 |
02 Dec 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 |
1682 |
02 Dec 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/ |
1682 |
02 Dec 05 |
nicklas |
10 |
|
1682 |
02 Dec 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
1682 |
02 Dec 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 |
1682 |
02 Dec 05 |
nicklas |
of the License, or (at your option) any later version. |
1682 |
02 Dec 05 |
nicklas |
15 |
|
1682 |
02 Dec 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
1682 |
02 Dec 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1682 |
02 Dec 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1682 |
02 Dec 05 |
nicklas |
GNU General Public License for more details. |
1682 |
02 Dec 05 |
nicklas |
20 |
|
1682 |
02 Dec 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/>. |
1682 |
02 Dec 05 |
nicklas |
23 |
*/ |
1682 |
02 Dec 05 |
nicklas |
24 |
import net.sf.basedb.core.*; |
1682 |
02 Dec 05 |
nicklas |
25 |
import net.sf.basedb.core.data.ReporterData; |
4301 |
16 May 08 |
nicklas |
26 |
import net.sf.basedb.core.query.Hql; |
4301 |
16 May 08 |
nicklas |
27 |
import net.sf.basedb.core.query.Orders; |
1682 |
02 Dec 05 |
nicklas |
28 |
|
4301 |
16 May 08 |
nicklas |
29 |
import java.util.ArrayList; |
1682 |
02 Dec 05 |
nicklas |
30 |
import java.util.Date; |
4301 |
16 May 08 |
nicklas |
31 |
import java.util.List; |
5340 |
10 May 10 |
nicklas |
32 |
import java.util.Set; |
1682 |
02 Dec 05 |
nicklas |
33 |
|
1682 |
02 Dec 05 |
nicklas |
34 |
public class TestReporterList |
1682 |
02 Dec 05 |
nicklas |
35 |
{ |
1682 |
02 Dec 05 |
nicklas |
36 |
|
1682 |
02 Dec 05 |
nicklas |
37 |
static boolean ok = true; |
1682 |
02 Dec 05 |
nicklas |
38 |
public static void main(String[] args) |
1682 |
02 Dec 05 |
nicklas |
39 |
{ |
1682 |
02 Dec 05 |
nicklas |
40 |
TestUtil.checkArgs(args); |
1682 |
02 Dec 05 |
nicklas |
41 |
TestUtil.begin(); |
1682 |
02 Dec 05 |
nicklas |
42 |
ok = test_all(); |
1682 |
02 Dec 05 |
nicklas |
43 |
TestUtil.stop(); |
1682 |
02 Dec 05 |
nicklas |
44 |
} |
1682 |
02 Dec 05 |
nicklas |
45 |
|
1682 |
02 Dec 05 |
nicklas |
46 |
static boolean test_all() |
1682 |
02 Dec 05 |
nicklas |
47 |
{ |
1682 |
02 Dec 05 |
nicklas |
48 |
write("++Testing reporter lists"); |
1682 |
02 Dec 05 |
nicklas |
49 |
write_header(); |
1682 |
02 Dec 05 |
nicklas |
// Standard tests: create, load, list |
4301 |
16 May 08 |
nicklas |
51 |
int id1 = test_create("net.sf.basedb.clients.test.reporterlist1", true); |
1682 |
02 Dec 05 |
nicklas |
52 |
int id2 = test_create("net.sf.basedb.clients.test.reporterlist2", false); |
4301 |
16 May 08 |
nicklas |
53 |
int id3 = test_create("net.sf.basedb.clients.test.reporterlist3", false); |
4301 |
16 May 08 |
nicklas |
54 |
int id4 = test_create("net.sf.basedb.clients.test.reporterlist4", false); |
4301 |
16 May 08 |
nicklas |
55 |
int id5 = test_create("net.sf.basedb.clients.test.reporterlist5", false); |
4301 |
16 May 08 |
nicklas |
56 |
int id6 = test_create("net.sf.basedb.clients.test.reporterlist6", false); |
4301 |
16 May 08 |
nicklas |
57 |
test_load(id1); |
1682 |
02 Dec 05 |
nicklas |
58 |
test_list(-1); |
1682 |
02 Dec 05 |
nicklas |
59 |
|
3626 |
03 Aug 07 |
nicklas |
60 |
TestReporter.test_import_from_file("data/test.rawdata.import.txt", "\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", "\\t", 4, 3); |
1682 |
02 Dec 05 |
nicklas |
61 |
|
4301 |
16 May 08 |
nicklas |
62 |
test_add_reporters(id1, 20, 0); |
4301 |
16 May 08 |
nicklas |
63 |
test_list_reporters(id1, 20); |
4301 |
16 May 08 |
nicklas |
64 |
test_add_reporters(id2, 20, 15); // 5 reporters in common with 'id1', 15 new |
1682 |
02 Dec 05 |
nicklas |
65 |
|
4301 |
16 May 08 |
nicklas |
66 |
test_union(id3, 35, id1, id2); // 'id3' is now the union of 'id1' and 'id2' |
4301 |
16 May 08 |
nicklas |
67 |
test_intersect(id4, 5, id1, id2); // 'id4' is now the intersection of 'id1' and 'id2' |
4301 |
16 May 08 |
nicklas |
68 |
test_remove(id5, id3, 30, id4); // 'id5' is now the complement of 'id3' to 'id4' |
4301 |
16 May 08 |
nicklas |
69 |
test_retain(id6, id2, 5, id1); // 'id6' is now the intersection on 'id1' and 'id2' |
4301 |
16 May 08 |
nicklas |
70 |
|
1682 |
02 Dec 05 |
nicklas |
71 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
1682 |
02 Dec 05 |
nicklas |
// Standard test: Delete |
4301 |
16 May 08 |
nicklas |
73 |
test_delete(id1); |
1682 |
02 Dec 05 |
nicklas |
74 |
test_delete(id2); |
4301 |
16 May 08 |
nicklas |
75 |
test_delete(id3); |
4301 |
16 May 08 |
nicklas |
76 |
test_delete(id4); |
4301 |
16 May 08 |
nicklas |
77 |
test_delete(id5); |
4301 |
16 May 08 |
nicklas |
78 |
test_delete(id6); |
4301 |
16 May 08 |
nicklas |
79 |
TestReporter.test_delete(); |
1682 |
02 Dec 05 |
nicklas |
80 |
write("++Testing reporter lists "+(ok ? "OK" : "Failed")+"\n"); |
1682 |
02 Dec 05 |
nicklas |
81 |
return ok; |
1682 |
02 Dec 05 |
nicklas |
82 |
} |
1682 |
02 Dec 05 |
nicklas |
83 |
|
1682 |
02 Dec 05 |
nicklas |
84 |
static int test_create(String externalId, boolean setAll) |
1682 |
02 Dec 05 |
nicklas |
85 |
{ |
1682 |
02 Dec 05 |
nicklas |
86 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.REPORTERLIST)) return 0; |
1682 |
02 Dec 05 |
nicklas |
87 |
int id = 0; |
1682 |
02 Dec 05 |
nicklas |
88 |
DbControl dc = null; |
1682 |
02 Dec 05 |
nicklas |
89 |
try |
1682 |
02 Dec 05 |
nicklas |
90 |
{ |
1682 |
02 Dec 05 |
nicklas |
91 |
dc = TestUtil.getDbControl(); |
1682 |
02 Dec 05 |
nicklas |
92 |
ReporterList rl = ReporterList.getNew(dc); |
1682 |
02 Dec 05 |
nicklas |
93 |
rl.setExternalId(externalId); |
1682 |
02 Dec 05 |
nicklas |
94 |
if (setAll) |
1682 |
02 Dec 05 |
nicklas |
95 |
{ |
1682 |
02 Dec 05 |
nicklas |
96 |
rl.setName("Test reporter list"); |
1682 |
02 Dec 05 |
nicklas |
97 |
rl.setDescription("Added at "+new Date()); |
1682 |
02 Dec 05 |
nicklas |
98 |
} |
1682 |
02 Dec 05 |
nicklas |
99 |
dc.saveItem(rl); |
1682 |
02 Dec 05 |
nicklas |
100 |
dc.commit(); |
1682 |
02 Dec 05 |
nicklas |
101 |
id = rl.getId(); |
1682 |
02 Dec 05 |
nicklas |
102 |
write_item(0, rl); |
1682 |
02 Dec 05 |
nicklas |
103 |
write("--Create reporter list OK"); |
1682 |
02 Dec 05 |
nicklas |
104 |
} |
1682 |
02 Dec 05 |
nicklas |
105 |
catch (Throwable ex) |
1682 |
02 Dec 05 |
nicklas |
106 |
{ |
1682 |
02 Dec 05 |
nicklas |
107 |
write("--Create reporter list FAILED"); |
1682 |
02 Dec 05 |
nicklas |
108 |
ex.printStackTrace(); |
1682 |
02 Dec 05 |
nicklas |
109 |
ok = false; |
1682 |
02 Dec 05 |
nicklas |
110 |
} |
1682 |
02 Dec 05 |
nicklas |
111 |
finally |
1682 |
02 Dec 05 |
nicklas |
112 |
{ |
1682 |
02 Dec 05 |
nicklas |
113 |
if (dc != null) dc.close(); |
1682 |
02 Dec 05 |
nicklas |
114 |
} |
1682 |
02 Dec 05 |
nicklas |
115 |
return id; |
1682 |
02 Dec 05 |
nicklas |
116 |
} |
1682 |
02 Dec 05 |
nicklas |
117 |
|
1682 |
02 Dec 05 |
nicklas |
118 |
static void test_load(int id) |
1682 |
02 Dec 05 |
nicklas |
119 |
{ |
1682 |
02 Dec 05 |
nicklas |
120 |
if (id == 0) return; |
1682 |
02 Dec 05 |
nicklas |
121 |
DbControl dc = null; |
1682 |
02 Dec 05 |
nicklas |
122 |
try |
1682 |
02 Dec 05 |
nicklas |
123 |
{ |
1682 |
02 Dec 05 |
nicklas |
124 |
dc = TestUtil.getDbControl(); |
1682 |
02 Dec 05 |
nicklas |
125 |
ReporterList rl = ReporterList.getById(dc, id); |
1682 |
02 Dec 05 |
nicklas |
126 |
write_item(0, rl); |
1682 |
02 Dec 05 |
nicklas |
127 |
write("--Load reporter list OK"); |
1682 |
02 Dec 05 |
nicklas |
128 |
} |
1682 |
02 Dec 05 |
nicklas |
129 |
catch (Throwable ex) |
1682 |
02 Dec 05 |
nicklas |
130 |
{ |
1682 |
02 Dec 05 |
nicklas |
131 |
write("--Load reporter list FAILED"); |
1682 |
02 Dec 05 |
nicklas |
132 |
ex.printStackTrace(); |
1682 |
02 Dec 05 |
nicklas |
133 |
ok = false; |
1682 |
02 Dec 05 |
nicklas |
134 |
} |
1682 |
02 Dec 05 |
nicklas |
135 |
finally |
1682 |
02 Dec 05 |
nicklas |
136 |
{ |
1682 |
02 Dec 05 |
nicklas |
137 |
if (dc != null) dc.close(); |
1682 |
02 Dec 05 |
nicklas |
138 |
} |
1682 |
02 Dec 05 |
nicklas |
139 |
} |
1682 |
02 Dec 05 |
nicklas |
140 |
|
1682 |
02 Dec 05 |
nicklas |
141 |
|
1682 |
02 Dec 05 |
nicklas |
142 |
static void test_list(int expectedResults) |
1682 |
02 Dec 05 |
nicklas |
143 |
{ |
1682 |
02 Dec 05 |
nicklas |
144 |
DbControl dc = null; |
1682 |
02 Dec 05 |
nicklas |
145 |
try |
1682 |
02 Dec 05 |
nicklas |
146 |
{ |
1682 |
02 Dec 05 |
nicklas |
147 |
dc = TestUtil.getDbControl(); |
1682 |
02 Dec 05 |
nicklas |
148 |
ItemQuery<ReporterList> q = ReporterList.getQuery(); |
1682 |
02 Dec 05 |
nicklas |
149 |
ItemResultList<ReporterList> l = q.list(dc); |
1682 |
02 Dec 05 |
nicklas |
150 |
for (int i = 0; i<l.size(); i++) |
1682 |
02 Dec 05 |
nicklas |
151 |
{ |
1682 |
02 Dec 05 |
nicklas |
152 |
write_item(i, l.get(i)); |
1682 |
02 Dec 05 |
nicklas |
153 |
} |
1682 |
02 Dec 05 |
nicklas |
154 |
if (expectedResults >= 0 && expectedResults != l.size()) |
1682 |
02 Dec 05 |
nicklas |
155 |
{ |
1682 |
02 Dec 05 |
nicklas |
156 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
1682 |
02 Dec 05 |
nicklas |
157 |
} |
1682 |
02 Dec 05 |
nicklas |
158 |
write("--List reporter lists OK ("+l.size()+")"); |
1682 |
02 Dec 05 |
nicklas |
159 |
} |
1682 |
02 Dec 05 |
nicklas |
160 |
catch (Throwable ex) |
1682 |
02 Dec 05 |
nicklas |
161 |
{ |
1682 |
02 Dec 05 |
nicklas |
162 |
write("--List reporter lists FAILED"); |
1682 |
02 Dec 05 |
nicklas |
163 |
ex.printStackTrace(); |
1682 |
02 Dec 05 |
nicklas |
164 |
ok = false; |
1682 |
02 Dec 05 |
nicklas |
165 |
} |
1682 |
02 Dec 05 |
nicklas |
166 |
finally |
1682 |
02 Dec 05 |
nicklas |
167 |
{ |
1682 |
02 Dec 05 |
nicklas |
168 |
if (dc != null) dc.close(); |
1682 |
02 Dec 05 |
nicklas |
169 |
} |
1682 |
02 Dec 05 |
nicklas |
170 |
} |
1682 |
02 Dec 05 |
nicklas |
171 |
|
1682 |
02 Dec 05 |
nicklas |
172 |
|
1682 |
02 Dec 05 |
nicklas |
173 |
static void test_delete(int id) |
1682 |
02 Dec 05 |
nicklas |
174 |
{ |
1682 |
02 Dec 05 |
nicklas |
175 |
if (id == 0) return; |
1682 |
02 Dec 05 |
nicklas |
176 |
DbControl dc = null; |
1682 |
02 Dec 05 |
nicklas |
177 |
try |
1682 |
02 Dec 05 |
nicklas |
178 |
{ |
1682 |
02 Dec 05 |
nicklas |
179 |
dc = TestUtil.getDbControl(); |
1682 |
02 Dec 05 |
nicklas |
180 |
ReporterList rl = ReporterList.getById(dc, id); |
1682 |
02 Dec 05 |
nicklas |
181 |
dc.deleteItem(rl); |
5340 |
10 May 10 |
nicklas |
182 |
Set<ItemProxy> using = rl.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
183 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
184 |
{ |
5340 |
10 May 10 |
nicklas |
185 |
throw new BaseException(rl + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
186 |
} |
1682 |
02 Dec 05 |
nicklas |
187 |
dc.commit(); |
2149 |
04 Apr 06 |
nicklas |
188 |
write("--Delete reporter list OK"); |
1682 |
02 Dec 05 |
nicklas |
189 |
} |
1682 |
02 Dec 05 |
nicklas |
190 |
catch (Throwable ex) |
1682 |
02 Dec 05 |
nicklas |
191 |
{ |
2149 |
04 Apr 06 |
nicklas |
192 |
write("--Delete reporter list FAILED"); |
1682 |
02 Dec 05 |
nicklas |
193 |
ex.printStackTrace(); |
1682 |
02 Dec 05 |
nicklas |
194 |
ok = false; |
1682 |
02 Dec 05 |
nicklas |
195 |
} |
1682 |
02 Dec 05 |
nicklas |
196 |
finally |
1682 |
02 Dec 05 |
nicklas |
197 |
{ |
1682 |
02 Dec 05 |
nicklas |
198 |
if (dc != null) dc.close(); |
1682 |
02 Dec 05 |
nicklas |
199 |
} |
1682 |
02 Dec 05 |
nicklas |
200 |
} |
1682 |
02 Dec 05 |
nicklas |
201 |
|
1682 |
02 Dec 05 |
nicklas |
202 |
static void write_header() |
1682 |
02 Dec 05 |
nicklas |
203 |
{ |
1682 |
02 Dec 05 |
nicklas |
204 |
if (!TestUtil.getSilent()) |
1682 |
02 Dec 05 |
nicklas |
205 |
{ |
1682 |
02 Dec 05 |
nicklas |
206 |
write(" \tID \tName \tDescription\tExternal ID"); |
1682 |
02 Dec 05 |
nicklas |
207 |
write("-- \t-- \t--------- \t-----------\t-----------"); |
1682 |
02 Dec 05 |
nicklas |
208 |
} |
1682 |
02 Dec 05 |
nicklas |
209 |
} |
1682 |
02 Dec 05 |
nicklas |
210 |
static void write_item(int i, ReporterList rl) |
1682 |
02 Dec 05 |
nicklas |
211 |
throws BaseException |
1682 |
02 Dec 05 |
nicklas |
212 |
{ |
1682 |
02 Dec 05 |
nicklas |
213 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+rl.getId()+"\t"+rl.getName()+"\t"+ |
1682 |
02 Dec 05 |
nicklas |
214 |
rl.getDescription()+"\t"+rl.getExternalId()); |
1682 |
02 Dec 05 |
nicklas |
215 |
} |
1682 |
02 Dec 05 |
nicklas |
216 |
static void write_item(int i, ReporterData r, Float score) |
1682 |
02 Dec 05 |
nicklas |
217 |
{ |
1682 |
02 Dec 05 |
nicklas |
218 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+r.getExternalId()+"\t"+score); |
1682 |
02 Dec 05 |
nicklas |
219 |
} |
1682 |
02 Dec 05 |
nicklas |
220 |
static void write(String message) |
1682 |
02 Dec 05 |
nicklas |
221 |
{ |
1682 |
02 Dec 05 |
nicklas |
222 |
System.out.println(message); |
1682 |
02 Dec 05 |
nicklas |
223 |
} |
1682 |
02 Dec 05 |
nicklas |
224 |
|
4301 |
16 May 08 |
nicklas |
225 |
static void test_add_reporters(int id, int maxNumber, int first) |
1682 |
02 Dec 05 |
nicklas |
226 |
{ |
1682 |
02 Dec 05 |
nicklas |
227 |
if (id == 0) return; |
1682 |
02 Dec 05 |
nicklas |
228 |
DbControl dc = null; |
1682 |
02 Dec 05 |
nicklas |
229 |
try |
1682 |
02 Dec 05 |
nicklas |
230 |
{ |
1682 |
02 Dec 05 |
nicklas |
231 |
dc = TestUtil.getDbControl(); |
1682 |
02 Dec 05 |
nicklas |
232 |
ReporterList rl = ReporterList.getById(dc, id); |
1682 |
02 Dec 05 |
nicklas |
233 |
|
1682 |
02 Dec 05 |
nicklas |
234 |
write_item(0, rl); |
1682 |
02 Dec 05 |
nicklas |
235 |
DataQuery<ReporterData> query = Reporter.getQuery(); |
4301 |
16 May 08 |
nicklas |
236 |
query.order(Orders.asc(Hql.property("externalId"))); |
2149 |
04 Apr 06 |
nicklas |
237 |
query.setMaxResults(maxNumber); |
4301 |
16 May 08 |
nicklas |
238 |
query.setFirstResult(first); |
1682 |
02 Dec 05 |
nicklas |
239 |
DataResultIterator<ReporterData> reporters = query.iterate(dc); |
1682 |
02 Dec 05 |
nicklas |
240 |
int i = 0; |
1682 |
02 Dec 05 |
nicklas |
241 |
while (reporters.hasNext() && i < maxNumber) |
1682 |
02 Dec 05 |
nicklas |
242 |
{ |
1682 |
02 Dec 05 |
nicklas |
243 |
ReporterData r = reporters.next(); |
1682 |
02 Dec 05 |
nicklas |
244 |
Float score = (float)Math.random() * 50000; |
1682 |
02 Dec 05 |
nicklas |
245 |
rl.addReporter(r, score); |
1682 |
02 Dec 05 |
nicklas |
246 |
write_item(i, r, score); |
1682 |
02 Dec 05 |
nicklas |
247 |
i++; |
1682 |
02 Dec 05 |
nicklas |
248 |
} |
1682 |
02 Dec 05 |
nicklas |
249 |
reporters.close(); |
1682 |
02 Dec 05 |
nicklas |
250 |
dc.commit(); |
1682 |
02 Dec 05 |
nicklas |
251 |
|
1682 |
02 Dec 05 |
nicklas |
252 |
write("--Add reporters to list OK (" + i + ")"); |
1682 |
02 Dec 05 |
nicklas |
253 |
} |
1682 |
02 Dec 05 |
nicklas |
254 |
catch (Throwable ex) |
1682 |
02 Dec 05 |
nicklas |
255 |
{ |
2149 |
04 Apr 06 |
nicklas |
256 |
write("--Add reporters to list FAILED"); |
1682 |
02 Dec 05 |
nicklas |
257 |
ex.printStackTrace(); |
1682 |
02 Dec 05 |
nicklas |
258 |
ok = false; |
1682 |
02 Dec 05 |
nicklas |
259 |
} |
1682 |
02 Dec 05 |
nicklas |
260 |
finally |
1682 |
02 Dec 05 |
nicklas |
261 |
{ |
1682 |
02 Dec 05 |
nicklas |
262 |
if (dc != null) dc.close(); |
1682 |
02 Dec 05 |
nicklas |
263 |
} |
1682 |
02 Dec 05 |
nicklas |
264 |
} |
1682 |
02 Dec 05 |
nicklas |
265 |
|
1682 |
02 Dec 05 |
nicklas |
266 |
static void test_list_reporters(int id, int expectedResults) |
1682 |
02 Dec 05 |
nicklas |
267 |
{ |
1682 |
02 Dec 05 |
nicklas |
268 |
if (id == 0) return; |
1682 |
02 Dec 05 |
nicklas |
269 |
DbControl dc = null; |
1682 |
02 Dec 05 |
nicklas |
270 |
try |
1682 |
02 Dec 05 |
nicklas |
271 |
{ |
1682 |
02 Dec 05 |
nicklas |
272 |
dc = TestUtil.getDbControl(); |
1682 |
02 Dec 05 |
nicklas |
273 |
ReporterList rl = ReporterList.getById(dc, id); |
1682 |
02 Dec 05 |
nicklas |
274 |
|
2150 |
05 Apr 06 |
nicklas |
275 |
ReporterScoreQuery query = rl.getReporterScores(); |
2150 |
05 Apr 06 |
nicklas |
276 |
ReporterScoreResultIterator reporters = query.iterate(dc); |
1682 |
02 Dec 05 |
nicklas |
277 |
|
1682 |
02 Dec 05 |
nicklas |
278 |
int i = 0; |
1682 |
02 Dec 05 |
nicklas |
279 |
while (reporters.hasNext()) |
1682 |
02 Dec 05 |
nicklas |
280 |
{ |
2150 |
05 Apr 06 |
nicklas |
281 |
ReporterScore r = reporters.next(); |
2150 |
05 Apr 06 |
nicklas |
282 |
write_item(i, r.getReporter(), r.getScore()); |
1682 |
02 Dec 05 |
nicklas |
283 |
i++; |
1682 |
02 Dec 05 |
nicklas |
284 |
} |
1682 |
02 Dec 05 |
nicklas |
285 |
if (expectedResults >= 0 && expectedResults != i) |
1682 |
02 Dec 05 |
nicklas |
286 |
{ |
1682 |
02 Dec 05 |
nicklas |
287 |
throw new BaseException("Expected "+expectedResults+" results, not "+i); |
1682 |
02 Dec 05 |
nicklas |
288 |
} |
1682 |
02 Dec 05 |
nicklas |
289 |
write("--List reporters in list OK (" + i + ")"); |
1682 |
02 Dec 05 |
nicklas |
290 |
} |
1682 |
02 Dec 05 |
nicklas |
291 |
catch (Throwable ex) |
1682 |
02 Dec 05 |
nicklas |
292 |
{ |
1682 |
02 Dec 05 |
nicklas |
293 |
write("--List reporters in list FAILED"); |
1682 |
02 Dec 05 |
nicklas |
294 |
ex.printStackTrace(); |
1682 |
02 Dec 05 |
nicklas |
295 |
ok = false; |
1682 |
02 Dec 05 |
nicklas |
296 |
} |
1682 |
02 Dec 05 |
nicklas |
297 |
finally |
1682 |
02 Dec 05 |
nicklas |
298 |
{ |
1682 |
02 Dec 05 |
nicklas |
299 |
if (dc != null) dc.close(); |
1682 |
02 Dec 05 |
nicklas |
300 |
} |
1682 |
02 Dec 05 |
nicklas |
301 |
} |
1682 |
02 Dec 05 |
nicklas |
302 |
|
3976 |
16 Nov 07 |
martin |
303 |
static void test_setExperiment(int id, int experimentId) |
3976 |
16 Nov 07 |
martin |
304 |
{ |
3976 |
16 Nov 07 |
martin |
305 |
if (id == 0 || experimentId == 0)return; |
3976 |
16 Nov 07 |
martin |
306 |
DbControl dc = null; |
3976 |
16 Nov 07 |
martin |
307 |
try |
3976 |
16 Nov 07 |
martin |
308 |
{ |
3976 |
16 Nov 07 |
martin |
309 |
dc = TestUtil.getDbControl(); |
3976 |
16 Nov 07 |
martin |
310 |
ReporterList rl = ReporterList.getById(dc, id); |
3976 |
16 Nov 07 |
martin |
311 |
Experiment exp = Experiment.getById(dc, experimentId); |
3976 |
16 Nov 07 |
martin |
312 |
|
3976 |
16 Nov 07 |
martin |
313 |
rl.setExperiment(exp); |
3976 |
16 Nov 07 |
martin |
314 |
dc.commit(); |
3976 |
16 Nov 07 |
martin |
315 |
} |
3976 |
16 Nov 07 |
martin |
316 |
catch (Throwable ex) |
3976 |
16 Nov 07 |
martin |
317 |
{ |
3976 |
16 Nov 07 |
martin |
318 |
write ("--Set experiment to list FAILED"); |
3976 |
16 Nov 07 |
martin |
319 |
ex.printStackTrace(); |
3976 |
16 Nov 07 |
martin |
320 |
ok = false; |
3976 |
16 Nov 07 |
martin |
321 |
} |
3976 |
16 Nov 07 |
martin |
322 |
finally |
3976 |
16 Nov 07 |
martin |
323 |
{ |
3976 |
16 Nov 07 |
martin |
324 |
if (dc != null) dc.close(); |
3976 |
16 Nov 07 |
martin |
325 |
} |
3976 |
16 Nov 07 |
martin |
326 |
} |
4301 |
16 May 08 |
nicklas |
327 |
|
4301 |
16 May 08 |
nicklas |
328 |
static void test_union(int toId, int expectedSize, int... fromId) |
4301 |
16 May 08 |
nicklas |
329 |
{ |
4301 |
16 May 08 |
nicklas |
330 |
if (toId == 0) return; |
4301 |
16 May 08 |
nicklas |
331 |
DbControl dc = null; |
4301 |
16 May 08 |
nicklas |
332 |
try |
4301 |
16 May 08 |
nicklas |
333 |
{ |
4301 |
16 May 08 |
nicklas |
334 |
dc = TestUtil.getDbControl(); |
4301 |
16 May 08 |
nicklas |
335 |
ReporterList to = ReporterList.getById(dc, toId); |
4301 |
16 May 08 |
nicklas |
336 |
List<ReporterList> from = new ArrayList<ReporterList>(fromId.length); |
4301 |
16 May 08 |
nicklas |
337 |
for (int rlId : fromId) |
4301 |
16 May 08 |
nicklas |
338 |
{ |
4301 |
16 May 08 |
nicklas |
339 |
from.add(ReporterList.getById(dc, rlId)); |
4301 |
16 May 08 |
nicklas |
340 |
} |
4301 |
16 May 08 |
nicklas |
341 |
to.addUnion(from); |
4301 |
16 May 08 |
nicklas |
342 |
dc.commit(); |
4301 |
16 May 08 |
nicklas |
343 |
if (expectedSize != to.getSize()) |
4301 |
16 May 08 |
nicklas |
344 |
{ |
4301 |
16 May 08 |
nicklas |
345 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + to.getSize()); |
4301 |
16 May 08 |
nicklas |
346 |
} |
4301 |
16 May 08 |
nicklas |
347 |
write("--Create union OK (size=" + expectedSize + ")"); |
4301 |
16 May 08 |
nicklas |
348 |
} |
4301 |
16 May 08 |
nicklas |
349 |
catch (Throwable ex) |
4301 |
16 May 08 |
nicklas |
350 |
{ |
4301 |
16 May 08 |
nicklas |
351 |
write ("--Create union FAILED"); |
4301 |
16 May 08 |
nicklas |
352 |
ex.printStackTrace(); |
4301 |
16 May 08 |
nicklas |
353 |
ok = false; |
4301 |
16 May 08 |
nicklas |
354 |
} |
4301 |
16 May 08 |
nicklas |
355 |
finally |
4301 |
16 May 08 |
nicklas |
356 |
{ |
4301 |
16 May 08 |
nicklas |
357 |
if (dc != null) dc.close(); |
4301 |
16 May 08 |
nicklas |
358 |
} |
4301 |
16 May 08 |
nicklas |
359 |
} |
1682 |
02 Dec 05 |
nicklas |
360 |
|
4301 |
16 May 08 |
nicklas |
361 |
static void test_intersect(int toId, int expectedSize, int... fromId) |
4301 |
16 May 08 |
nicklas |
362 |
{ |
4301 |
16 May 08 |
nicklas |
363 |
if (toId == 0) return; |
4301 |
16 May 08 |
nicklas |
364 |
DbControl dc = null; |
4301 |
16 May 08 |
nicklas |
365 |
try |
4301 |
16 May 08 |
nicklas |
366 |
{ |
4301 |
16 May 08 |
nicklas |
367 |
dc = TestUtil.getDbControl(); |
4301 |
16 May 08 |
nicklas |
368 |
ReporterList to = ReporterList.getById(dc, toId); |
4301 |
16 May 08 |
nicklas |
369 |
List<ReporterList> from = new ArrayList<ReporterList>(fromId.length); |
4301 |
16 May 08 |
nicklas |
370 |
for (int rlId : fromId) |
4301 |
16 May 08 |
nicklas |
371 |
{ |
4301 |
16 May 08 |
nicklas |
372 |
from.add(ReporterList.getById(dc, rlId)); |
4301 |
16 May 08 |
nicklas |
373 |
} |
4301 |
16 May 08 |
nicklas |
374 |
to.addIntersection(from); |
4301 |
16 May 08 |
nicklas |
375 |
dc.commit(); |
4301 |
16 May 08 |
nicklas |
376 |
if (expectedSize != to.getSize()) |
4301 |
16 May 08 |
nicklas |
377 |
{ |
4301 |
16 May 08 |
nicklas |
378 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + to.getSize()); |
4301 |
16 May 08 |
nicklas |
379 |
} |
4301 |
16 May 08 |
nicklas |
380 |
write("--Create intersection OK (size=" + expectedSize + ")"); |
4301 |
16 May 08 |
nicklas |
381 |
} |
4301 |
16 May 08 |
nicklas |
382 |
catch (Throwable ex) |
4301 |
16 May 08 |
nicklas |
383 |
{ |
4301 |
16 May 08 |
nicklas |
384 |
write ("--Create intersection FAILED"); |
4301 |
16 May 08 |
nicklas |
385 |
ex.printStackTrace(); |
4301 |
16 May 08 |
nicklas |
386 |
ok = false; |
4301 |
16 May 08 |
nicklas |
387 |
} |
4301 |
16 May 08 |
nicklas |
388 |
finally |
4301 |
16 May 08 |
nicklas |
389 |
{ |
4301 |
16 May 08 |
nicklas |
390 |
if (dc != null) dc.close(); |
4301 |
16 May 08 |
nicklas |
391 |
} |
4301 |
16 May 08 |
nicklas |
392 |
} |
4301 |
16 May 08 |
nicklas |
393 |
|
4301 |
16 May 08 |
nicklas |
394 |
static void test_remove(int toId, int baseId, int expectedSize, int... complementId) |
4301 |
16 May 08 |
nicklas |
395 |
{ |
4301 |
16 May 08 |
nicklas |
396 |
if (toId == 0) return; |
4301 |
16 May 08 |
nicklas |
397 |
DbControl dc = null; |
4301 |
16 May 08 |
nicklas |
398 |
try |
4301 |
16 May 08 |
nicklas |
399 |
{ |
4301 |
16 May 08 |
nicklas |
400 |
dc = TestUtil.getDbControl(); |
4301 |
16 May 08 |
nicklas |
401 |
ReporterList to = ReporterList.getById(dc, toId); |
4301 |
16 May 08 |
nicklas |
402 |
to.addAll(ReporterList.getById(dc, baseId)); |
4301 |
16 May 08 |
nicklas |
403 |
List<ReporterList> from = new ArrayList<ReporterList>(complementId.length); |
4301 |
16 May 08 |
nicklas |
404 |
for (int rlId : complementId) |
4301 |
16 May 08 |
nicklas |
405 |
{ |
4301 |
16 May 08 |
nicklas |
406 |
from.add(ReporterList.getById(dc, rlId)); |
4301 |
16 May 08 |
nicklas |
407 |
} |
4301 |
16 May 08 |
nicklas |
408 |
to.removeUnion(from); |
4301 |
16 May 08 |
nicklas |
409 |
dc.commit(); |
4301 |
16 May 08 |
nicklas |
410 |
if (expectedSize != to.getSize()) |
4301 |
16 May 08 |
nicklas |
411 |
{ |
4301 |
16 May 08 |
nicklas |
412 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + to.getSize()); |
4301 |
16 May 08 |
nicklas |
413 |
} |
4301 |
16 May 08 |
nicklas |
414 |
write("--Remove reporters OK (size=" + expectedSize + ")"); |
4301 |
16 May 08 |
nicklas |
415 |
} |
4301 |
16 May 08 |
nicklas |
416 |
catch (Throwable ex) |
4301 |
16 May 08 |
nicklas |
417 |
{ |
4301 |
16 May 08 |
nicklas |
418 |
write ("--Remove reporters FAILED"); |
4301 |
16 May 08 |
nicklas |
419 |
ex.printStackTrace(); |
4301 |
16 May 08 |
nicklas |
420 |
ok = false; |
4301 |
16 May 08 |
nicklas |
421 |
} |
4301 |
16 May 08 |
nicklas |
422 |
finally |
4301 |
16 May 08 |
nicklas |
423 |
{ |
4301 |
16 May 08 |
nicklas |
424 |
if (dc != null) dc.close(); |
4301 |
16 May 08 |
nicklas |
425 |
} |
4301 |
16 May 08 |
nicklas |
426 |
} |
4301 |
16 May 08 |
nicklas |
427 |
|
4301 |
16 May 08 |
nicklas |
428 |
static void test_retain(int toId, int baseId, int expectedSize, int... complementId) |
4301 |
16 May 08 |
nicklas |
429 |
{ |
4301 |
16 May 08 |
nicklas |
430 |
if (toId == 0) return; |
4301 |
16 May 08 |
nicklas |
431 |
DbControl dc = null; |
4301 |
16 May 08 |
nicklas |
432 |
try |
4301 |
16 May 08 |
nicklas |
433 |
{ |
4301 |
16 May 08 |
nicklas |
434 |
dc = TestUtil.getDbControl(); |
4301 |
16 May 08 |
nicklas |
435 |
ReporterList to = ReporterList.getById(dc, toId); |
4301 |
16 May 08 |
nicklas |
436 |
to.addAll(ReporterList.getById(dc, baseId)); |
4301 |
16 May 08 |
nicklas |
437 |
List<ReporterList> from = new ArrayList<ReporterList>(complementId.length); |
4301 |
16 May 08 |
nicklas |
438 |
for (int rlId : complementId) |
4301 |
16 May 08 |
nicklas |
439 |
{ |
4301 |
16 May 08 |
nicklas |
440 |
from.add(ReporterList.getById(dc, rlId)); |
4301 |
16 May 08 |
nicklas |
441 |
} |
4301 |
16 May 08 |
nicklas |
442 |
to.retainUnion(from); |
4301 |
16 May 08 |
nicklas |
443 |
dc.commit(); |
4301 |
16 May 08 |
nicklas |
444 |
if (expectedSize != to.getSize()) |
4301 |
16 May 08 |
nicklas |
445 |
{ |
4301 |
16 May 08 |
nicklas |
446 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + to.getSize()); |
4301 |
16 May 08 |
nicklas |
447 |
} |
4301 |
16 May 08 |
nicklas |
448 |
write("--Retain reporters OK (size=" + expectedSize + ")"); |
4301 |
16 May 08 |
nicklas |
449 |
} |
4301 |
16 May 08 |
nicklas |
450 |
catch (Throwable ex) |
4301 |
16 May 08 |
nicklas |
451 |
{ |
4301 |
16 May 08 |
nicklas |
452 |
write ("--Retain reporters FAILED"); |
4301 |
16 May 08 |
nicklas |
453 |
ex.printStackTrace(); |
4301 |
16 May 08 |
nicklas |
454 |
ok = false; |
4301 |
16 May 08 |
nicklas |
455 |
} |
4301 |
16 May 08 |
nicklas |
456 |
finally |
4301 |
16 May 08 |
nicklas |
457 |
{ |
4301 |
16 May 08 |
nicklas |
458 |
if (dc != null) dc.close(); |
4301 |
16 May 08 |
nicklas |
459 |
} |
4301 |
16 May 08 |
nicklas |
460 |
} |
4301 |
16 May 08 |
nicklas |
461 |
|
1682 |
02 Dec 05 |
nicklas |
462 |
} |
1682 |
02 Dec 05 |
nicklas |
463 |
|