1439 |
11 Oct 05 |
nicklas |
1 |
/* |
1439 |
11 Oct 05 |
nicklas |
$Id$ |
1439 |
11 Oct 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
1439 |
11 Oct 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/ |
1439 |
11 Oct 05 |
nicklas |
9 |
|
1439 |
11 Oct 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
1439 |
11 Oct 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 |
1439 |
11 Oct 05 |
nicklas |
of the License, or (at your option) any later version. |
1439 |
11 Oct 05 |
nicklas |
14 |
|
1439 |
11 Oct 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
1439 |
11 Oct 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1439 |
11 Oct 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1439 |
11 Oct 05 |
nicklas |
GNU General Public License for more details. |
1439 |
11 Oct 05 |
nicklas |
19 |
|
1439 |
11 Oct 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/>. |
1439 |
11 Oct 05 |
nicklas |
22 |
*/ |
1439 |
11 Oct 05 |
nicklas |
23 |
|
991 |
22 Jul 05 |
enell |
24 |
import net.sf.basedb.core.ArrayDesign; |
991 |
22 Jul 05 |
enell |
25 |
import net.sf.basedb.core.ArrayDesignBlock; |
991 |
22 Jul 05 |
enell |
26 |
import net.sf.basedb.core.BaseException; |
991 |
22 Jul 05 |
enell |
27 |
import net.sf.basedb.core.BlockInfo; |
991 |
22 Jul 05 |
enell |
28 |
import net.sf.basedb.core.DbControl; |
1418 |
07 Oct 05 |
nicklas |
29 |
import net.sf.basedb.core.ItemResultList; |
3820 |
12 Oct 07 |
nicklas |
30 |
import net.sf.basedb.core.Platform; |
991 |
22 Jul 05 |
enell |
31 |
|
991 |
22 Jul 05 |
enell |
32 |
|
991 |
22 Jul 05 |
enell |
33 |
/** |
991 |
22 Jul 05 |
enell |
34 |
|
991 |
22 Jul 05 |
enell |
@base.modified $Date$ |
991 |
22 Jul 05 |
enell |
@author Enell |
991 |
22 Jul 05 |
enell |
@version 2.0 |
991 |
22 Jul 05 |
enell |
38 |
*/ |
991 |
22 Jul 05 |
enell |
39 |
public class TestArrayDesignBlock |
991 |
22 Jul 05 |
enell |
40 |
{ |
991 |
22 Jul 05 |
enell |
41 |
|
991 |
22 Jul 05 |
enell |
42 |
static boolean ok = true; |
991 |
22 Jul 05 |
enell |
43 |
|
991 |
22 Jul 05 |
enell |
44 |
public static void main(String[] args) |
991 |
22 Jul 05 |
enell |
45 |
{ |
991 |
22 Jul 05 |
enell |
46 |
TestUtil.checkArgs(args); |
991 |
22 Jul 05 |
enell |
47 |
TestUtil.begin(); |
991 |
22 Jul 05 |
enell |
48 |
ok = test_all(); |
991 |
22 Jul 05 |
enell |
49 |
TestUtil.stop(); |
991 |
22 Jul 05 |
enell |
50 |
} |
991 |
22 Jul 05 |
enell |
51 |
|
991 |
22 Jul 05 |
enell |
52 |
static boolean test_all() |
991 |
22 Jul 05 |
enell |
53 |
{ |
991 |
22 Jul 05 |
enell |
54 |
write("++Testing array design block"); |
991 |
22 Jul 05 |
enell |
55 |
write_header(); |
3820 |
12 Oct 07 |
nicklas |
56 |
int arrayDesignId = TestArrayDesign.test_create(Platform.GENERIC, false); |
991 |
22 Jul 05 |
enell |
// Standard tests: create, load, list |
1060 |
05 Aug 05 |
enell |
58 |
int nbr = 10; |
1439 |
11 Oct 05 |
nicklas |
59 |
int[] id = test_create(arrayDesignId, true, nbr); |
1060 |
05 Aug 05 |
enell |
60 |
test_load(id[(int) (Math.random()*id.length)]); |
1439 |
11 Oct 05 |
nicklas |
61 |
test_list(arrayDesignId, nbr); |
991 |
22 Jul 05 |
enell |
62 |
|
1529 |
27 Oct 05 |
nicklas |
63 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
1529 |
27 Oct 05 |
nicklas |
64 |
|
1439 |
11 Oct 05 |
nicklas |
65 |
TestArrayDesign.test_delete(arrayDesignId); |
991 |
22 Jul 05 |
enell |
66 |
write("++Testing array design block "+(ok ? "OK" : "Failed")+"\n"); |
991 |
22 Jul 05 |
enell |
67 |
return ok; |
991 |
22 Jul 05 |
enell |
68 |
} |
991 |
22 Jul 05 |
enell |
69 |
|
1093 |
19 Aug 05 |
enell |
70 |
static int[] test_create(int arraydesign_id, boolean setAll, int blocks) |
991 |
22 Jul 05 |
enell |
71 |
{ |
991 |
22 Jul 05 |
enell |
72 |
int[] id = new int[blocks]; |
991 |
22 Jul 05 |
enell |
73 |
DbControl dc = null; |
991 |
22 Jul 05 |
enell |
74 |
try |
991 |
22 Jul 05 |
enell |
75 |
{ |
991 |
22 Jul 05 |
enell |
76 |
dc = TestUtil.getDbControl(); |
991 |
22 Jul 05 |
enell |
77 |
ArrayDesign ad = ArrayDesign.getById(dc, arraydesign_id); |
1299 |
08 Sep 05 |
nicklas |
78 |
ad.setName("Array design with blocks"); |
1060 |
05 Aug 05 |
enell |
79 |
|
991 |
22 Jul 05 |
enell |
80 |
for (int i = 0; i < blocks; i++) |
991 |
22 Jul 05 |
enell |
81 |
{ |
1060 |
05 Aug 05 |
enell |
82 |
int block = i+1; |
1401 |
04 Oct 05 |
enell |
83 |
BlockInfo bi = new BlockInfo(block, (int)Math.ceil(block/4F), ((block-1)%4)+1); |
1060 |
05 Aug 05 |
enell |
84 |
ArrayDesignBlock adb = ad.addArrayDesignBlock(bi); |
1093 |
19 Aug 05 |
enell |
85 |
if(setAll) |
1093 |
19 Aug 05 |
enell |
86 |
{ |
1093 |
19 Aug 05 |
enell |
87 |
adb.setBlockSizeX(10); |
1093 |
19 Aug 05 |
enell |
88 |
adb.setBlockSizeY(10); |
1093 |
19 Aug 05 |
enell |
89 |
} |
991 |
22 Jul 05 |
enell |
90 |
id[i] = adb.getId(); |
991 |
22 Jul 05 |
enell |
91 |
write_item(0, adb); |
991 |
22 Jul 05 |
enell |
92 |
} |
991 |
22 Jul 05 |
enell |
93 |
dc.commit(); |
991 |
22 Jul 05 |
enell |
94 |
write("--Create array design block OK"); |
991 |
22 Jul 05 |
enell |
95 |
} |
991 |
22 Jul 05 |
enell |
96 |
catch (Throwable ex) |
991 |
22 Jul 05 |
enell |
97 |
{ |
991 |
22 Jul 05 |
enell |
98 |
write("--Create array design block FAILED"); |
991 |
22 Jul 05 |
enell |
99 |
ex.printStackTrace(); |
991 |
22 Jul 05 |
enell |
100 |
ok = false; |
991 |
22 Jul 05 |
enell |
101 |
} |
991 |
22 Jul 05 |
enell |
102 |
finally |
991 |
22 Jul 05 |
enell |
103 |
{ |
991 |
22 Jul 05 |
enell |
104 |
if (dc != null) dc.close(); |
991 |
22 Jul 05 |
enell |
105 |
} |
991 |
22 Jul 05 |
enell |
106 |
return id; |
991 |
22 Jul 05 |
enell |
107 |
} |
991 |
22 Jul 05 |
enell |
108 |
|
991 |
22 Jul 05 |
enell |
109 |
static void test_load(int id) |
991 |
22 Jul 05 |
enell |
110 |
{ |
991 |
22 Jul 05 |
enell |
111 |
if (id == 0) return; |
991 |
22 Jul 05 |
enell |
112 |
DbControl dc = null; |
991 |
22 Jul 05 |
enell |
113 |
try |
991 |
22 Jul 05 |
enell |
114 |
{ |
991 |
22 Jul 05 |
enell |
115 |
dc = TestUtil.getDbControl(); |
991 |
22 Jul 05 |
enell |
116 |
ArrayDesignBlock adb = ArrayDesignBlock.getById(dc, id); |
991 |
22 Jul 05 |
enell |
117 |
write_item(0, adb); |
991 |
22 Jul 05 |
enell |
118 |
write("--Load array design block OK"); |
991 |
22 Jul 05 |
enell |
119 |
} |
991 |
22 Jul 05 |
enell |
120 |
catch (Throwable ex) |
991 |
22 Jul 05 |
enell |
121 |
{ |
991 |
22 Jul 05 |
enell |
122 |
write("--Load array design block FAILED"); |
991 |
22 Jul 05 |
enell |
123 |
ex.printStackTrace(); |
991 |
22 Jul 05 |
enell |
124 |
ok = false; |
991 |
22 Jul 05 |
enell |
125 |
} |
991 |
22 Jul 05 |
enell |
126 |
finally |
991 |
22 Jul 05 |
enell |
127 |
{ |
991 |
22 Jul 05 |
enell |
128 |
if (dc != null) dc.close(); |
991 |
22 Jul 05 |
enell |
129 |
} |
991 |
22 Jul 05 |
enell |
130 |
|
991 |
22 Jul 05 |
enell |
131 |
} |
991 |
22 Jul 05 |
enell |
132 |
|
1439 |
11 Oct 05 |
nicklas |
133 |
static void test_list(int arrayDesignId, int expectedResults) |
991 |
22 Jul 05 |
enell |
134 |
{ |
1439 |
11 Oct 05 |
nicklas |
135 |
if (arrayDesignId == 0) return; |
991 |
22 Jul 05 |
enell |
136 |
DbControl dc = null; |
991 |
22 Jul 05 |
enell |
137 |
try |
991 |
22 Jul 05 |
enell |
138 |
{ |
991 |
22 Jul 05 |
enell |
139 |
dc = TestUtil.getDbControl(); |
1439 |
11 Oct 05 |
nicklas |
140 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
1439 |
11 Oct 05 |
nicklas |
141 |
ItemResultList<ArrayDesignBlock> l = ad.getArrayDesignBlocks().list(dc); |
991 |
22 Jul 05 |
enell |
142 |
for (int i = 0; i<l.size(); i++) |
991 |
22 Jul 05 |
enell |
143 |
{ |
991 |
22 Jul 05 |
enell |
144 |
write_item(i, l.get(i)); |
991 |
22 Jul 05 |
enell |
145 |
} |
991 |
22 Jul 05 |
enell |
146 |
if (expectedResults >= 0 && expectedResults != l.size()) |
991 |
22 Jul 05 |
enell |
147 |
{ |
991 |
22 Jul 05 |
enell |
148 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
991 |
22 Jul 05 |
enell |
149 |
} |
991 |
22 Jul 05 |
enell |
150 |
write("--List array design blocks OK ("+l.size()+")"); |
991 |
22 Jul 05 |
enell |
151 |
} |
991 |
22 Jul 05 |
enell |
152 |
catch (Throwable ex) |
991 |
22 Jul 05 |
enell |
153 |
{ |
991 |
22 Jul 05 |
enell |
154 |
write("--List array design blocks FAILED"); |
991 |
22 Jul 05 |
enell |
155 |
ex.printStackTrace(); |
991 |
22 Jul 05 |
enell |
156 |
ok = false; |
991 |
22 Jul 05 |
enell |
157 |
} |
991 |
22 Jul 05 |
enell |
158 |
finally |
991 |
22 Jul 05 |
enell |
159 |
{ |
991 |
22 Jul 05 |
enell |
160 |
if (dc != null) dc.close(); |
991 |
22 Jul 05 |
enell |
161 |
} |
991 |
22 Jul 05 |
enell |
162 |
} |
991 |
22 Jul 05 |
enell |
163 |
|
991 |
22 Jul 05 |
enell |
164 |
static void write_header() |
991 |
22 Jul 05 |
enell |
165 |
{ |
991 |
22 Jul 05 |
enell |
166 |
if (!TestUtil.getSilent()) |
991 |
22 Jul 05 |
enell |
167 |
{ |
1060 |
05 Aug 05 |
enell |
168 |
write(" \tID\tBlock\tMetaGridX\tMetaGridY\tBlockSizeX\tBlockSizeY\tArrayDesign"); |
1060 |
05 Aug 05 |
enell |
169 |
write("--\t--\t-----\t---------\t---------\t----------\t----------\t-----------"); |
991 |
22 Jul 05 |
enell |
170 |
} |
991 |
22 Jul 05 |
enell |
171 |
} |
991 |
22 Jul 05 |
enell |
172 |
|
991 |
22 Jul 05 |
enell |
173 |
static void write_item(int i, ArrayDesignBlock adb) |
991 |
22 Jul 05 |
enell |
174 |
throws BaseException |
991 |
22 Jul 05 |
enell |
175 |
{ |
991 |
22 Jul 05 |
enell |
176 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+adb.getId()+"\t"+adb.getBlockNumber() |
1060 |
05 Aug 05 |
enell |
177 |
+"\t"+adb.getMetaGridX()+"\t"+adb.getMetaGridY()+"\t"+adb.getBlockSizeX()+"\t"+adb.getBlockSizeY()+"\t"+adb.getArrayDesign().getId()); |
991 |
22 Jul 05 |
enell |
178 |
} |
991 |
22 Jul 05 |
enell |
179 |
|
991 |
22 Jul 05 |
enell |
180 |
static void write(String message) |
991 |
22 Jul 05 |
enell |
181 |
{ |
991 |
22 Jul 05 |
enell |
182 |
System.out.println(message); |
991 |
22 Jul 05 |
enell |
183 |
} |
991 |
22 Jul 05 |
enell |
184 |
} |