982 |
21 Jul 05 |
enell |
1 |
import java.util.Date; |
5340 |
10 May 10 |
nicklas |
2 |
import java.util.Set; |
982 |
21 Jul 05 |
enell |
3 |
|
982 |
21 Jul 05 |
enell |
4 |
import net.sf.basedb.core.ArrayBatch; |
982 |
21 Jul 05 |
enell |
5 |
import net.sf.basedb.core.ArraySlide; |
982 |
21 Jul 05 |
enell |
6 |
import net.sf.basedb.core.BaseException; |
982 |
21 Jul 05 |
enell |
7 |
import net.sf.basedb.core.DbControl; |
982 |
21 Jul 05 |
enell |
8 |
import net.sf.basedb.core.Item; |
5340 |
10 May 10 |
nicklas |
9 |
import net.sf.basedb.core.ItemProxy; |
982 |
21 Jul 05 |
enell |
10 |
import net.sf.basedb.core.Permission; |
1418 |
07 Oct 05 |
nicklas |
11 |
import net.sf.basedb.core.ItemResultList; |
3820 |
12 Oct 07 |
nicklas |
12 |
import net.sf.basedb.core.Platform; |
4434 |
02 Sep 08 |
nicklas |
13 |
import net.sf.basedb.core.Trashcan; |
982 |
21 Jul 05 |
enell |
14 |
|
982 |
21 Jul 05 |
enell |
15 |
/* |
982 |
21 Jul 05 |
enell |
$Id$ |
982 |
21 Jul 05 |
enell |
17 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen |
982 |
21 Jul 05 |
enell |
20 |
|
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/ |
982 |
21 Jul 05 |
enell |
23 |
|
982 |
21 Jul 05 |
enell |
BASE is free software; you can redistribute it and/or |
982 |
21 Jul 05 |
enell |
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 |
982 |
21 Jul 05 |
enell |
of the License, or (at your option) any later version. |
982 |
21 Jul 05 |
enell |
28 |
|
982 |
21 Jul 05 |
enell |
BASE is distributed in the hope that it will be useful, |
982 |
21 Jul 05 |
enell |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
982 |
21 Jul 05 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
982 |
21 Jul 05 |
enell |
GNU General Public License for more details. |
982 |
21 Jul 05 |
enell |
33 |
|
982 |
21 Jul 05 |
enell |
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/>. |
982 |
21 Jul 05 |
enell |
36 |
*/ |
982 |
21 Jul 05 |
enell |
37 |
public class TestArraySlide |
982 |
21 Jul 05 |
enell |
38 |
{ |
982 |
21 Jul 05 |
enell |
39 |
static boolean ok = true; |
982 |
21 Jul 05 |
enell |
40 |
public static void main(String[] args) |
982 |
21 Jul 05 |
enell |
41 |
{ |
982 |
21 Jul 05 |
enell |
42 |
TestUtil.checkArgs(args); |
982 |
21 Jul 05 |
enell |
43 |
TestUtil.begin(); |
982 |
21 Jul 05 |
enell |
44 |
ok = test_all(); |
982 |
21 Jul 05 |
enell |
45 |
TestUtil.stop(); |
982 |
21 Jul 05 |
enell |
46 |
} |
982 |
21 Jul 05 |
enell |
47 |
|
982 |
21 Jul 05 |
enell |
48 |
static boolean test_all() |
982 |
21 Jul 05 |
enell |
49 |
{ |
982 |
21 Jul 05 |
enell |
50 |
write("++Testing array slide"); |
982 |
21 Jul 05 |
enell |
51 |
write_header(); |
982 |
21 Jul 05 |
enell |
// Standard tests: create, load, list |
3820 |
12 Oct 07 |
nicklas |
53 |
int arraydesign_id = TestArrayDesign.test_create(Platform.GENERIC, true); |
1116 |
23 Aug 05 |
nicklas |
54 |
int arraybatch_id = TestArrayBatch.test_create(arraydesign_id, false); |
1116 |
23 Aug 05 |
nicklas |
55 |
int id = test_create(arraybatch_id, true); |
1116 |
23 Aug 05 |
nicklas |
56 |
int id2 = test_create(arraybatch_id, false); |
982 |
21 Jul 05 |
enell |
57 |
test_load(id); |
4434 |
02 Sep 08 |
nicklas |
58 |
test_list(-1); |
982 |
21 Jul 05 |
enell |
59 |
|
982 |
21 Jul 05 |
enell |
// Extra tests: |
982 |
21 Jul 05 |
enell |
61 |
|
1529 |
27 Oct 05 |
nicklas |
62 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
982 |
21 Jul 05 |
enell |
// Standard test: Delete |
982 |
21 Jul 05 |
enell |
64 |
test_delete(id); |
1116 |
23 Aug 05 |
nicklas |
65 |
test_delete(id2); |
982 |
21 Jul 05 |
enell |
66 |
TestArrayBatch.test_delete(arraybatch_id); |
982 |
21 Jul 05 |
enell |
67 |
TestArrayDesign.test_delete(arraydesign_id); |
982 |
21 Jul 05 |
enell |
68 |
write("++Testing array slide "+(ok ? "OK" : "Failed")+"\n"); |
982 |
21 Jul 05 |
enell |
69 |
return ok; |
982 |
21 Jul 05 |
enell |
70 |
} |
982 |
21 Jul 05 |
enell |
71 |
|
1116 |
23 Aug 05 |
nicklas |
72 |
static int test_create(int arraybatch_id, boolean setAll) |
982 |
21 Jul 05 |
enell |
73 |
{ |
982 |
21 Jul 05 |
enell |
74 |
if (arraybatch_id == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.ARRAYSLIDE)) return 0; |
982 |
21 Jul 05 |
enell |
75 |
int id = 0; |
982 |
21 Jul 05 |
enell |
76 |
DbControl dc = null; |
982 |
21 Jul 05 |
enell |
77 |
try |
982 |
21 Jul 05 |
enell |
78 |
{ |
982 |
21 Jul 05 |
enell |
79 |
dc = TestUtil.getDbControl(); |
982 |
21 Jul 05 |
enell |
80 |
ArrayBatch ab = ArrayBatch.getById(dc, arraybatch_id); |
982 |
21 Jul 05 |
enell |
81 |
ArraySlide as = ab.newArraySlide(); |
1116 |
23 Aug 05 |
nicklas |
82 |
if (setAll) |
1116 |
23 Aug 05 |
nicklas |
83 |
{ |
1116 |
23 Aug 05 |
nicklas |
84 |
as.setName("Test array slide"); |
1116 |
23 Aug 05 |
nicklas |
85 |
as.setDescription("Added at "+new Date()); |
1116 |
23 Aug 05 |
nicklas |
86 |
as.setBatchIndex(1); |
1116 |
23 Aug 05 |
nicklas |
87 |
as.setBarcode("ABCDEFG"); |
1116 |
23 Aug 05 |
nicklas |
88 |
} |
982 |
21 Jul 05 |
enell |
89 |
dc.saveItem(as); |
982 |
21 Jul 05 |
enell |
90 |
dc.commit(); |
982 |
21 Jul 05 |
enell |
91 |
id = as.getId(); |
982 |
21 Jul 05 |
enell |
92 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
93 |
dc.reattachItem(as, false); |
982 |
21 Jul 05 |
enell |
94 |
write_item(0, as); |
982 |
21 Jul 05 |
enell |
95 |
write("--Create array slide OK"); |
982 |
21 Jul 05 |
enell |
96 |
} |
982 |
21 Jul 05 |
enell |
97 |
catch (Exception ex) |
982 |
21 Jul 05 |
enell |
98 |
{ |
982 |
21 Jul 05 |
enell |
99 |
write("--Create array slide FAILED"); |
982 |
21 Jul 05 |
enell |
100 |
ex.printStackTrace(); |
982 |
21 Jul 05 |
enell |
101 |
ok = false; |
982 |
21 Jul 05 |
enell |
102 |
} |
982 |
21 Jul 05 |
enell |
103 |
finally |
982 |
21 Jul 05 |
enell |
104 |
{ |
982 |
21 Jul 05 |
enell |
105 |
if (dc != null) dc.close(); |
982 |
21 Jul 05 |
enell |
106 |
} |
982 |
21 Jul 05 |
enell |
107 |
return id; |
982 |
21 Jul 05 |
enell |
108 |
} |
982 |
21 Jul 05 |
enell |
109 |
|
982 |
21 Jul 05 |
enell |
110 |
static void test_load(int id) |
982 |
21 Jul 05 |
enell |
111 |
{ |
982 |
21 Jul 05 |
enell |
112 |
if (id == 0) return; |
982 |
21 Jul 05 |
enell |
113 |
DbControl dc = null; |
982 |
21 Jul 05 |
enell |
114 |
try |
982 |
21 Jul 05 |
enell |
115 |
{ |
982 |
21 Jul 05 |
enell |
116 |
dc = TestUtil.getDbControl(); |
982 |
21 Jul 05 |
enell |
117 |
ArraySlide as = ArraySlide.getById(dc, id); |
982 |
21 Jul 05 |
enell |
118 |
write_item(0, as); |
982 |
21 Jul 05 |
enell |
119 |
write("--Load array slide OK"); |
982 |
21 Jul 05 |
enell |
120 |
} |
982 |
21 Jul 05 |
enell |
121 |
catch (Exception ex) |
982 |
21 Jul 05 |
enell |
122 |
{ |
982 |
21 Jul 05 |
enell |
123 |
write("--Load array slide FAILED"); |
982 |
21 Jul 05 |
enell |
124 |
ex.printStackTrace(); |
982 |
21 Jul 05 |
enell |
125 |
ok = false; |
982 |
21 Jul 05 |
enell |
126 |
} |
982 |
21 Jul 05 |
enell |
127 |
finally |
982 |
21 Jul 05 |
enell |
128 |
{ |
982 |
21 Jul 05 |
enell |
129 |
if (dc != null) dc.close(); |
982 |
21 Jul 05 |
enell |
130 |
} |
982 |
21 Jul 05 |
enell |
131 |
} |
982 |
21 Jul 05 |
enell |
132 |
|
5696 |
12 Aug 11 |
nicklas |
133 |
static boolean test_list(int expectedResults) |
982 |
21 Jul 05 |
enell |
134 |
{ |
982 |
21 Jul 05 |
enell |
135 |
DbControl dc = null; |
982 |
21 Jul 05 |
enell |
136 |
try |
982 |
21 Jul 05 |
enell |
137 |
{ |
982 |
21 Jul 05 |
enell |
138 |
dc = TestUtil.getDbControl(); |
4434 |
02 Sep 08 |
nicklas |
139 |
ItemResultList<ArraySlide> l = ArraySlide.getQuery().list(dc); |
982 |
21 Jul 05 |
enell |
140 |
for (int i = 0; i<l.size(); i++) |
982 |
21 Jul 05 |
enell |
141 |
{ |
4434 |
02 Sep 08 |
nicklas |
142 |
write_item(i, l.get(i)); |
982 |
21 Jul 05 |
enell |
143 |
} |
4434 |
02 Sep 08 |
nicklas |
144 |
if (expectedResults >= 0 && expectedResults != l.size()) |
4434 |
02 Sep 08 |
nicklas |
145 |
{ |
4434 |
02 Sep 08 |
nicklas |
146 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
4434 |
02 Sep 08 |
nicklas |
147 |
} |
982 |
21 Jul 05 |
enell |
148 |
write("--List array slides OK ("+l.size()+")"); |
982 |
21 Jul 05 |
enell |
149 |
} |
4434 |
02 Sep 08 |
nicklas |
150 |
catch (Throwable ex) |
982 |
21 Jul 05 |
enell |
151 |
{ |
982 |
21 Jul 05 |
enell |
152 |
write("--List array slides FAILED"); |
982 |
21 Jul 05 |
enell |
153 |
ex.printStackTrace(); |
982 |
21 Jul 05 |
enell |
154 |
ok = false; |
5696 |
12 Aug 11 |
nicklas |
155 |
return false; |
982 |
21 Jul 05 |
enell |
156 |
} |
982 |
21 Jul 05 |
enell |
157 |
finally |
982 |
21 Jul 05 |
enell |
158 |
{ |
982 |
21 Jul 05 |
enell |
159 |
if (dc != null) dc.close(); |
982 |
21 Jul 05 |
enell |
160 |
} |
5696 |
12 Aug 11 |
nicklas |
161 |
return true; |
982 |
21 Jul 05 |
enell |
162 |
} |
982 |
21 Jul 05 |
enell |
163 |
|
4434 |
02 Sep 08 |
nicklas |
164 |
|
982 |
21 Jul 05 |
enell |
165 |
static void test_delete(int id) |
982 |
21 Jul 05 |
enell |
166 |
{ |
982 |
21 Jul 05 |
enell |
167 |
if (id == 0) return; |
982 |
21 Jul 05 |
enell |
168 |
DbControl dc = null; |
982 |
21 Jul 05 |
enell |
169 |
try |
982 |
21 Jul 05 |
enell |
170 |
{ |
982 |
21 Jul 05 |
enell |
171 |
dc = TestUtil.getDbControl(); |
982 |
21 Jul 05 |
enell |
172 |
ArraySlide as = ArraySlide.getById(dc, id); |
982 |
21 Jul 05 |
enell |
173 |
dc.deleteItem(as); |
5340 |
10 May 10 |
nicklas |
174 |
Set<ItemProxy> using = as.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
175 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
176 |
{ |
5340 |
10 May 10 |
nicklas |
177 |
throw new BaseException(as + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
178 |
} |
982 |
21 Jul 05 |
enell |
179 |
dc.commit(); |
982 |
21 Jul 05 |
enell |
180 |
write("--Delete array slide OK"); |
982 |
21 Jul 05 |
enell |
181 |
} |
982 |
21 Jul 05 |
enell |
182 |
catch (Exception ex) |
982 |
21 Jul 05 |
enell |
183 |
{ |
982 |
21 Jul 05 |
enell |
184 |
write("--Delete array slide FAILED"); |
982 |
21 Jul 05 |
enell |
185 |
ex.printStackTrace(); |
982 |
21 Jul 05 |
enell |
186 |
ok = false; |
982 |
21 Jul 05 |
enell |
187 |
} |
982 |
21 Jul 05 |
enell |
188 |
finally |
982 |
21 Jul 05 |
enell |
189 |
{ |
982 |
21 Jul 05 |
enell |
190 |
if (dc != null) dc.close(); |
982 |
21 Jul 05 |
enell |
191 |
} |
982 |
21 Jul 05 |
enell |
192 |
} |
982 |
21 Jul 05 |
enell |
193 |
|
4434 |
02 Sep 08 |
nicklas |
194 |
static void test_delete_all() |
4434 |
02 Sep 08 |
nicklas |
195 |
{ |
4434 |
02 Sep 08 |
nicklas |
196 |
DbControl dc = null; |
4434 |
02 Sep 08 |
nicklas |
197 |
try |
4434 |
02 Sep 08 |
nicklas |
198 |
{ |
4434 |
02 Sep 08 |
nicklas |
199 |
dc = TestUtil.getDbControl(); |
4434 |
02 Sep 08 |
nicklas |
200 |
ItemResultList<ArraySlide> l = ArraySlide.getQuery().list(dc); |
5688 |
10 Aug 11 |
nicklas |
201 |
int numDeleted = Trashcan.delete(dc.getSessionControl(), l, true, null); |
5688 |
10 Aug 11 |
nicklas |
202 |
if (numDeleted != l.size()) throw new BaseException("Could not delete all items: " + numDeleted + " of " + l.size()); |
4434 |
02 Sep 08 |
nicklas |
203 |
dc.commit(); |
4434 |
02 Sep 08 |
nicklas |
204 |
write("--Delete all array slides OK ("+l.size()+")"); |
4434 |
02 Sep 08 |
nicklas |
205 |
} |
4434 |
02 Sep 08 |
nicklas |
206 |
catch (Throwable ex) |
4434 |
02 Sep 08 |
nicklas |
207 |
{ |
4434 |
02 Sep 08 |
nicklas |
208 |
write("--Delete all array slides FAILED"); |
4434 |
02 Sep 08 |
nicklas |
209 |
ex.printStackTrace(); |
4434 |
02 Sep 08 |
nicklas |
210 |
ok = false; |
4434 |
02 Sep 08 |
nicklas |
211 |
} |
4434 |
02 Sep 08 |
nicklas |
212 |
finally |
4434 |
02 Sep 08 |
nicklas |
213 |
{ |
4434 |
02 Sep 08 |
nicklas |
214 |
if (dc != null) dc.close(); |
4434 |
02 Sep 08 |
nicklas |
215 |
} |
4434 |
02 Sep 08 |
nicklas |
216 |
} |
4434 |
02 Sep 08 |
nicklas |
217 |
|
4434 |
02 Sep 08 |
nicklas |
218 |
|
982 |
21 Jul 05 |
enell |
219 |
static void write_header() |
982 |
21 Jul 05 |
enell |
220 |
{ |
982 |
21 Jul 05 |
enell |
221 |
if (!TestUtil.getSilent()) |
982 |
21 Jul 05 |
enell |
222 |
{ |
982 |
21 Jul 05 |
enell |
223 |
write(" \tID \tName \tDescription\tIndex\tBarcode\tArray batch"); |
982 |
21 Jul 05 |
enell |
224 |
write("-- \t-- \t--------- \t-----------\t-----\t-------\t-----------"); |
982 |
21 Jul 05 |
enell |
225 |
} |
982 |
21 Jul 05 |
enell |
226 |
} |
982 |
21 Jul 05 |
enell |
227 |
static void write_item(int i, ArraySlide as) |
982 |
21 Jul 05 |
enell |
228 |
throws BaseException |
982 |
21 Jul 05 |
enell |
229 |
{ |
982 |
21 Jul 05 |
enell |
230 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+as.getId()+"\t"+as.getName()+"\t"+ |
982 |
21 Jul 05 |
enell |
231 |
as.getDescription()+"\t"+as.getBatchIndex()+"\t"+as.getBarcode()+"\t"+ |
982 |
21 Jul 05 |
enell |
232 |
as.getArrayBatch()); |
982 |
21 Jul 05 |
enell |
233 |
} |
982 |
21 Jul 05 |
enell |
234 |
static void write(String message) |
982 |
21 Jul 05 |
enell |
235 |
{ |
982 |
21 Jul 05 |
enell |
236 |
System.out.println(message); |
982 |
21 Jul 05 |
enell |
237 |
} |
982 |
21 Jul 05 |
enell |
238 |
} |