3764 |
21 Sep 07 |
nicklas |
1 |
/* |
3764 |
21 Sep 07 |
nicklas |
$Id$ |
3764 |
21 Sep 07 |
nicklas |
3 |
|
3764 |
21 Sep 07 |
nicklas |
Copyright (C) 2007 Nicklas Nordborg |
3764 |
21 Sep 07 |
nicklas |
5 |
|
3764 |
21 Sep 07 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
3764 |
21 Sep 07 |
nicklas |
Available at http://base.thep.lu.se/ |
3764 |
21 Sep 07 |
nicklas |
8 |
|
3764 |
21 Sep 07 |
nicklas |
BASE is free software; you can redistribute it and/or |
3764 |
21 Sep 07 |
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 |
3764 |
21 Sep 07 |
nicklas |
of the License, or (at your option) any later version. |
3764 |
21 Sep 07 |
nicklas |
13 |
|
3764 |
21 Sep 07 |
nicklas |
BASE is distributed in the hope that it will be useful, |
3764 |
21 Sep 07 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3764 |
21 Sep 07 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3764 |
21 Sep 07 |
nicklas |
GNU General Public License for more details. |
3764 |
21 Sep 07 |
nicklas |
18 |
|
3764 |
21 Sep 07 |
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/>. |
3764 |
21 Sep 07 |
nicklas |
21 |
*/ |
3764 |
21 Sep 07 |
nicklas |
22 |
|
5340 |
10 May 10 |
nicklas |
23 |
import java.util.Set; |
5340 |
10 May 10 |
nicklas |
24 |
|
3764 |
21 Sep 07 |
nicklas |
25 |
import net.sf.basedb.core.BaseException; |
3764 |
21 Sep 07 |
nicklas |
26 |
import net.sf.basedb.core.DbControl; |
3793 |
27 Sep 07 |
nicklas |
27 |
import net.sf.basedb.core.DataFileType; |
5630 |
13 May 11 |
nicklas |
28 |
import net.sf.basedb.core.File; |
3764 |
21 Sep 07 |
nicklas |
29 |
import net.sf.basedb.core.Item; |
5340 |
10 May 10 |
nicklas |
30 |
import net.sf.basedb.core.ItemProxy; |
3764 |
21 Sep 07 |
nicklas |
31 |
import net.sf.basedb.core.ItemResultList; |
3764 |
21 Sep 07 |
nicklas |
32 |
import net.sf.basedb.core.Permission; |
3764 |
21 Sep 07 |
nicklas |
33 |
import net.sf.basedb.core.Platform; |
3783 |
25 Sep 07 |
nicklas |
34 |
import net.sf.basedb.core.PlatformFileType; |
3783 |
25 Sep 07 |
nicklas |
35 |
import net.sf.basedb.core.PlatformVariant; |
3764 |
21 Sep 07 |
nicklas |
36 |
import net.sf.basedb.core.RawDataTypes; |
3764 |
21 Sep 07 |
nicklas |
37 |
import net.sf.basedb.core.SystemItems; |
3764 |
21 Sep 07 |
nicklas |
38 |
|
3764 |
21 Sep 07 |
nicklas |
39 |
public class TestPlatform |
3764 |
21 Sep 07 |
nicklas |
40 |
{ |
3764 |
21 Sep 07 |
nicklas |
41 |
|
3764 |
21 Sep 07 |
nicklas |
42 |
static boolean ok = true; |
3764 |
21 Sep 07 |
nicklas |
43 |
|
3764 |
21 Sep 07 |
nicklas |
44 |
public static void main(String[] args) |
3764 |
21 Sep 07 |
nicklas |
45 |
{ |
3764 |
21 Sep 07 |
nicklas |
46 |
TestUtil.checkArgs(args); |
3764 |
21 Sep 07 |
nicklas |
47 |
TestUtil.begin(); |
3764 |
21 Sep 07 |
nicklas |
48 |
ok = test_all(); |
3764 |
21 Sep 07 |
nicklas |
49 |
TestUtil.stop(); |
3764 |
21 Sep 07 |
nicklas |
50 |
} |
3764 |
21 Sep 07 |
nicklas |
51 |
|
3764 |
21 Sep 07 |
nicklas |
52 |
static boolean test_all() |
3764 |
21 Sep 07 |
nicklas |
53 |
{ |
3764 |
21 Sep 07 |
nicklas |
54 |
write("++Testing platform"); |
3764 |
21 Sep 07 |
nicklas |
55 |
write_header(); |
3764 |
21 Sep 07 |
nicklas |
// Standard tests: create, load and list |
3797 |
28 Sep 07 |
nicklas |
57 |
|
3764 |
21 Sep 07 |
nicklas |
58 |
int id1 = test_create("Db and file", "test.db.and.file", false, 0, null); |
3764 |
21 Sep 07 |
nicklas |
59 |
int id2 = test_create("File-only", "test.file.only", true, 1, null); |
3764 |
21 Sep 07 |
nicklas |
60 |
int id3 = test_create("Locked to genepix", "test.locked.genepix", false, 0, "genepix"); |
3764 |
21 Sep 07 |
nicklas |
61 |
test_list(); |
3764 |
21 Sep 07 |
nicklas |
62 |
|
3783 |
25 Sep 07 |
nicklas |
// Variants |
3783 |
25 Sep 07 |
nicklas |
64 |
int idVariant1 = test_create_variant(id1, "Variant of db and file", "test.db.and.file.v1", null, 0, null); |
3793 |
27 Sep 07 |
nicklas |
65 |
int idVariant2 = test_create_variant(id2, "Variant #1 file-only", "test.file.only.v1", null, 0, null); |
3793 |
27 Sep 07 |
nicklas |
66 |
int idVariant2b = test_create_variant(id2, "Variant #2 file-only", "test.file.only.v2", null, 0, null); |
3783 |
25 Sep 07 |
nicklas |
67 |
int idVariant3 = test_create_variant(id3, "Locked to agilent", "test.locked.agilent", false, 0, "agilent"); |
3783 |
25 Sep 07 |
nicklas |
68 |
test_list_variants(id1, 1); |
3783 |
25 Sep 07 |
nicklas |
69 |
|
3783 |
25 Sep 07 |
nicklas |
// File types |
5630 |
13 May 11 |
nicklas |
71 |
int fileTypeId = TestDataFileType.test_create("test.datafile", "test.datafile", Item.RAWBIOASSAY, SystemItems.getId(File.RAW_DATA)); |
3797 |
28 Sep 07 |
nicklas |
72 |
int celId = TestDataFileType.get_id_for_external("affymetrix.cel"); |
3797 |
28 Sep 07 |
nicklas |
73 |
int cdfId = TestDataFileType.get_id_for_external("affymetrix.cdf"); |
5713 |
02 Sep 11 |
nicklas |
74 |
test_add_filetype(id2, 0, celId, true, false); |
5713 |
02 Sep 11 |
nicklas |
75 |
test_add_filetype(id2, idVariant2, cdfId, false, false); |
5713 |
02 Sep 11 |
nicklas |
76 |
test_add_filetype(id2, idVariant2b, fileTypeId, false, true); |
3793 |
27 Sep 07 |
nicklas |
77 |
test_list_filetypes(id2, 0, false, 3); |
3793 |
27 Sep 07 |
nicklas |
78 |
test_list_filetypes(id2, 0, true, 1); |
3793 |
27 Sep 07 |
nicklas |
79 |
test_list_filetypes(id2, idVariant2, false, 2); |
3793 |
27 Sep 07 |
nicklas |
80 |
test_list_filetypes(id2, idVariant2, true, 1); |
3783 |
25 Sep 07 |
nicklas |
81 |
|
3764 |
21 Sep 07 |
nicklas |
// Standard test: Delete |
3764 |
21 Sep 07 |
nicklas |
83 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
3783 |
25 Sep 07 |
nicklas |
84 |
test_delete_variant(idVariant1); |
3764 |
21 Sep 07 |
nicklas |
85 |
test_delete(id1); |
3764 |
21 Sep 07 |
nicklas |
86 |
test_delete(id2); |
3764 |
21 Sep 07 |
nicklas |
87 |
test_delete(id3); |
3793 |
27 Sep 07 |
nicklas |
88 |
TestDataFileType.test_delete(fileTypeId); |
3764 |
21 Sep 07 |
nicklas |
89 |
write("++Testing platform "+(ok ? "OK" : "Failed")+"\n"); |
3764 |
21 Sep 07 |
nicklas |
90 |
return ok; |
3764 |
21 Sep 07 |
nicklas |
91 |
} |
3764 |
21 Sep 07 |
nicklas |
92 |
|
3764 |
21 Sep 07 |
nicklas |
93 |
static int test_create(String name, String systemId, boolean fileOnly, int channels, String rawDataType) |
3764 |
21 Sep 07 |
nicklas |
94 |
{ |
3764 |
21 Sep 07 |
nicklas |
95 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.PLATFORM)) return 0; |
3764 |
21 Sep 07 |
nicklas |
96 |
int id = 0; |
3764 |
21 Sep 07 |
nicklas |
97 |
DbControl dc = null; |
3764 |
21 Sep 07 |
nicklas |
98 |
try |
3764 |
21 Sep 07 |
nicklas |
99 |
{ |
3764 |
21 Sep 07 |
nicklas |
100 |
dc = TestUtil.getDbControl(); |
3764 |
21 Sep 07 |
nicklas |
101 |
|
3764 |
21 Sep 07 |
nicklas |
102 |
Platform p = fileOnly ? |
3764 |
21 Sep 07 |
nicklas |
103 |
Platform.getNew(dc, systemId, channels) : |
3764 |
21 Sep 07 |
nicklas |
104 |
Platform.getNew(dc, systemId, RawDataTypes.getRawDataType(rawDataType)); |
3764 |
21 Sep 07 |
nicklas |
105 |
p.setName(name); |
3764 |
21 Sep 07 |
nicklas |
106 |
dc.saveItem(p); |
3764 |
21 Sep 07 |
nicklas |
107 |
dc.commit(); |
3764 |
21 Sep 07 |
nicklas |
108 |
id = p.getId(); |
3764 |
21 Sep 07 |
nicklas |
109 |
write_item(0, p); |
3764 |
21 Sep 07 |
nicklas |
110 |
write("--Create platform OK"); |
3764 |
21 Sep 07 |
nicklas |
111 |
} |
3764 |
21 Sep 07 |
nicklas |
112 |
catch (Throwable ex) |
3764 |
21 Sep 07 |
nicklas |
113 |
{ |
3764 |
21 Sep 07 |
nicklas |
114 |
write("--Create platform FAILED"); |
3764 |
21 Sep 07 |
nicklas |
115 |
ex.printStackTrace(); |
3764 |
21 Sep 07 |
nicklas |
116 |
ok = false; |
3764 |
21 Sep 07 |
nicklas |
117 |
} |
3764 |
21 Sep 07 |
nicklas |
118 |
finally |
3764 |
21 Sep 07 |
nicklas |
119 |
{ |
3764 |
21 Sep 07 |
nicklas |
120 |
if (dc != null) dc.close(); |
3764 |
21 Sep 07 |
nicklas |
121 |
} |
3764 |
21 Sep 07 |
nicklas |
122 |
return id; |
3764 |
21 Sep 07 |
nicklas |
123 |
} |
3764 |
21 Sep 07 |
nicklas |
124 |
|
3764 |
21 Sep 07 |
nicklas |
125 |
|
3764 |
21 Sep 07 |
nicklas |
126 |
static void test_load(int id) |
3764 |
21 Sep 07 |
nicklas |
127 |
{ |
3764 |
21 Sep 07 |
nicklas |
128 |
if (id == 0) return; |
3764 |
21 Sep 07 |
nicklas |
129 |
DbControl dc = null; |
3764 |
21 Sep 07 |
nicklas |
130 |
try |
3764 |
21 Sep 07 |
nicklas |
131 |
{ |
3764 |
21 Sep 07 |
nicklas |
132 |
dc = TestUtil.getDbControl(); |
3764 |
21 Sep 07 |
nicklas |
133 |
Platform p = Platform.getById(dc, id); |
3764 |
21 Sep 07 |
nicklas |
134 |
write_item(0, p); |
3764 |
21 Sep 07 |
nicklas |
135 |
write("--Load platform OK"); |
3764 |
21 Sep 07 |
nicklas |
136 |
} |
3764 |
21 Sep 07 |
nicklas |
137 |
catch (Throwable ex) |
3764 |
21 Sep 07 |
nicklas |
138 |
{ |
3764 |
21 Sep 07 |
nicklas |
139 |
write("--Load platform FAILED"); |
3764 |
21 Sep 07 |
nicklas |
140 |
ex.printStackTrace(); |
3764 |
21 Sep 07 |
nicklas |
141 |
ok = false; |
3764 |
21 Sep 07 |
nicklas |
142 |
} |
3764 |
21 Sep 07 |
nicklas |
143 |
finally |
3764 |
21 Sep 07 |
nicklas |
144 |
{ |
3764 |
21 Sep 07 |
nicklas |
145 |
if (dc != null) dc.close(); |
3764 |
21 Sep 07 |
nicklas |
146 |
} |
3764 |
21 Sep 07 |
nicklas |
147 |
} |
3764 |
21 Sep 07 |
nicklas |
148 |
|
3764 |
21 Sep 07 |
nicklas |
149 |
static void test_list() |
3764 |
21 Sep 07 |
nicklas |
150 |
{ |
3764 |
21 Sep 07 |
nicklas |
151 |
DbControl dc = null; |
3764 |
21 Sep 07 |
nicklas |
152 |
try |
3764 |
21 Sep 07 |
nicklas |
153 |
{ |
3764 |
21 Sep 07 |
nicklas |
154 |
dc = TestUtil.getDbControl(); |
3764 |
21 Sep 07 |
nicklas |
155 |
ItemResultList<Platform> l = Platform.getQuery().list(dc); |
3764 |
21 Sep 07 |
nicklas |
156 |
for (int i = 0; i<l.size(); i++) |
3764 |
21 Sep 07 |
nicklas |
157 |
{ |
3764 |
21 Sep 07 |
nicklas |
158 |
write_item(i, l.get(i)); |
3764 |
21 Sep 07 |
nicklas |
159 |
} |
3764 |
21 Sep 07 |
nicklas |
160 |
write("--List platforms OK ("+l.size()+")"); |
3764 |
21 Sep 07 |
nicklas |
161 |
} |
3764 |
21 Sep 07 |
nicklas |
162 |
catch (Throwable ex) |
3764 |
21 Sep 07 |
nicklas |
163 |
{ |
3764 |
21 Sep 07 |
nicklas |
164 |
write("--List platforms FAILED"); |
3764 |
21 Sep 07 |
nicklas |
165 |
ex.printStackTrace(); |
3764 |
21 Sep 07 |
nicklas |
166 |
ok = false; |
3764 |
21 Sep 07 |
nicklas |
167 |
} |
3764 |
21 Sep 07 |
nicklas |
168 |
finally |
3764 |
21 Sep 07 |
nicklas |
169 |
{ |
3764 |
21 Sep 07 |
nicklas |
170 |
if (dc != null) dc.close(); |
3764 |
21 Sep 07 |
nicklas |
171 |
} |
3764 |
21 Sep 07 |
nicklas |
172 |
} |
3764 |
21 Sep 07 |
nicklas |
173 |
|
3764 |
21 Sep 07 |
nicklas |
174 |
static void test_delete(int id) |
3764 |
21 Sep 07 |
nicklas |
175 |
{ |
3764 |
21 Sep 07 |
nicklas |
176 |
if (id == 0) return; |
3764 |
21 Sep 07 |
nicklas |
177 |
DbControl dc = null; |
3764 |
21 Sep 07 |
nicklas |
178 |
try |
3764 |
21 Sep 07 |
nicklas |
179 |
{ |
3764 |
21 Sep 07 |
nicklas |
180 |
dc = TestUtil.getDbControl(); |
3764 |
21 Sep 07 |
nicklas |
181 |
Platform l = Platform.getById(dc, id); |
3764 |
21 Sep 07 |
nicklas |
182 |
dc.deleteItem(l); |
5340 |
10 May 10 |
nicklas |
183 |
Set<ItemProxy> using = l.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
184 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
185 |
{ |
5340 |
10 May 10 |
nicklas |
186 |
throw new BaseException(l + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
187 |
} |
3764 |
21 Sep 07 |
nicklas |
188 |
dc.commit(); |
3764 |
21 Sep 07 |
nicklas |
189 |
write("--Delete platform OK"); |
3764 |
21 Sep 07 |
nicklas |
190 |
} |
3764 |
21 Sep 07 |
nicklas |
191 |
catch (Throwable ex) |
3764 |
21 Sep 07 |
nicklas |
192 |
{ |
3764 |
21 Sep 07 |
nicklas |
193 |
write("--Delete platform FAILED"); |
3764 |
21 Sep 07 |
nicklas |
194 |
ex.printStackTrace(); |
3764 |
21 Sep 07 |
nicklas |
195 |
ok = false; |
3764 |
21 Sep 07 |
nicklas |
196 |
} |
3764 |
21 Sep 07 |
nicklas |
197 |
finally |
3764 |
21 Sep 07 |
nicklas |
198 |
{ |
3764 |
21 Sep 07 |
nicklas |
199 |
if (dc != null) dc.close(); |
3764 |
21 Sep 07 |
nicklas |
200 |
} |
3764 |
21 Sep 07 |
nicklas |
201 |
} |
3764 |
21 Sep 07 |
nicklas |
202 |
|
4426 |
29 Aug 08 |
nicklas |
203 |
static int test_get(String externalId) |
4426 |
29 Aug 08 |
nicklas |
204 |
{ |
4426 |
29 Aug 08 |
nicklas |
205 |
DbControl dc = null; |
4426 |
29 Aug 08 |
nicklas |
206 |
int platformId = 0; |
4426 |
29 Aug 08 |
nicklas |
207 |
try |
4426 |
29 Aug 08 |
nicklas |
208 |
{ |
4426 |
29 Aug 08 |
nicklas |
209 |
dc = TestUtil.getDbControl(); |
4426 |
29 Aug 08 |
nicklas |
210 |
Platform p = Platform.getByExternalId(dc, externalId); |
4426 |
29 Aug 08 |
nicklas |
211 |
platformId = p.getId(); |
4426 |
29 Aug 08 |
nicklas |
212 |
write("--Get platform '"+externalId+"' OK"); |
4426 |
29 Aug 08 |
nicklas |
213 |
} |
4426 |
29 Aug 08 |
nicklas |
214 |
catch (Throwable ex) |
4426 |
29 Aug 08 |
nicklas |
215 |
{ |
4426 |
29 Aug 08 |
nicklas |
216 |
write("--Get platform '" + externalId + "' FAILED"); |
4426 |
29 Aug 08 |
nicklas |
217 |
ex.printStackTrace(); |
4426 |
29 Aug 08 |
nicklas |
218 |
ok = false; |
4426 |
29 Aug 08 |
nicklas |
219 |
} |
4426 |
29 Aug 08 |
nicklas |
220 |
finally |
4426 |
29 Aug 08 |
nicklas |
221 |
{ |
4426 |
29 Aug 08 |
nicklas |
222 |
if (dc != null) dc.close(); |
4426 |
29 Aug 08 |
nicklas |
223 |
} |
4426 |
29 Aug 08 |
nicklas |
224 |
return platformId; |
4426 |
29 Aug 08 |
nicklas |
225 |
} |
4426 |
29 Aug 08 |
nicklas |
226 |
|
4426 |
29 Aug 08 |
nicklas |
227 |
static int test_get_variant(String externalId) |
4426 |
29 Aug 08 |
nicklas |
228 |
{ |
4426 |
29 Aug 08 |
nicklas |
229 |
DbControl dc = null; |
4426 |
29 Aug 08 |
nicklas |
230 |
int variantId = 0; |
4426 |
29 Aug 08 |
nicklas |
231 |
try |
4426 |
29 Aug 08 |
nicklas |
232 |
{ |
4426 |
29 Aug 08 |
nicklas |
233 |
dc = TestUtil.getDbControl(); |
4426 |
29 Aug 08 |
nicklas |
234 |
PlatformVariant p = PlatformVariant.getByExternalId(dc, externalId); |
4426 |
29 Aug 08 |
nicklas |
235 |
variantId = p.getId(); |
4426 |
29 Aug 08 |
nicklas |
236 |
write("--Get platform variant '"+externalId+"' OK"); |
4426 |
29 Aug 08 |
nicklas |
237 |
} |
4426 |
29 Aug 08 |
nicklas |
238 |
catch (Throwable ex) |
4426 |
29 Aug 08 |
nicklas |
239 |
{ |
4426 |
29 Aug 08 |
nicklas |
240 |
write("--Get platform variant '" + externalId + "' FAILED"); |
4426 |
29 Aug 08 |
nicklas |
241 |
ex.printStackTrace(); |
4426 |
29 Aug 08 |
nicklas |
242 |
ok = false; |
4426 |
29 Aug 08 |
nicklas |
243 |
} |
4426 |
29 Aug 08 |
nicklas |
244 |
finally |
4426 |
29 Aug 08 |
nicklas |
245 |
{ |
4426 |
29 Aug 08 |
nicklas |
246 |
if (dc != null) dc.close(); |
4426 |
29 Aug 08 |
nicklas |
247 |
} |
4426 |
29 Aug 08 |
nicklas |
248 |
return variantId; |
4426 |
29 Aug 08 |
nicklas |
249 |
} |
4426 |
29 Aug 08 |
nicklas |
250 |
|
3764 |
21 Sep 07 |
nicklas |
251 |
|
3764 |
21 Sep 07 |
nicklas |
252 |
static void write_header() |
3764 |
21 Sep 07 |
nicklas |
253 |
{ |
3764 |
21 Sep 07 |
nicklas |
254 |
if (!TestUtil.getSilent()) |
3764 |
21 Sep 07 |
nicklas |
255 |
{ |
3797 |
28 Sep 07 |
nicklas |
256 |
write(" \tID \tName \tDescription\tExternal ID\tFile only\tRaw data type"); |
5713 |
02 Sep 11 |
nicklas |
257 |
write("-- \t-- \t--------- \t-----------\t-----------\t---------\t-------------"); |
3764 |
21 Sep 07 |
nicklas |
258 |
} |
3764 |
21 Sep 07 |
nicklas |
259 |
} |
3764 |
21 Sep 07 |
nicklas |
260 |
|
3764 |
21 Sep 07 |
nicklas |
261 |
static void write_item(int i, Platform p) |
3764 |
21 Sep 07 |
nicklas |
262 |
throws BaseException |
3764 |
21 Sep 07 |
nicklas |
263 |
{ |
3764 |
21 Sep 07 |
nicklas |
264 |
if (!TestUtil.getSilent()) |
3764 |
21 Sep 07 |
nicklas |
265 |
{ |
3764 |
21 Sep 07 |
nicklas |
266 |
System.out.println(i+":\t"+p.getId()+"\t"+p.getName()+"\t"+ |
3797 |
28 Sep 07 |
nicklas |
267 |
p.getDescription() + "\t" + p.getExternalId() + "\t" + p.isFileOnly() + "\t" + |
3764 |
21 Sep 07 |
nicklas |
268 |
p.getRawDataType()); |
3764 |
21 Sep 07 |
nicklas |
269 |
} |
3764 |
21 Sep 07 |
nicklas |
270 |
} |
3764 |
21 Sep 07 |
nicklas |
271 |
|
3783 |
25 Sep 07 |
nicklas |
272 |
static void write_item(int i, PlatformVariant v) |
3783 |
25 Sep 07 |
nicklas |
273 |
throws BaseException |
3783 |
25 Sep 07 |
nicklas |
274 |
{ |
3783 |
25 Sep 07 |
nicklas |
275 |
if (!TestUtil.getSilent()) |
3783 |
25 Sep 07 |
nicklas |
276 |
{ |
3783 |
25 Sep 07 |
nicklas |
277 |
System.out.println(i+":\t"+v.getId()+"\t"+v.getName()+"\t"+ |
3797 |
28 Sep 07 |
nicklas |
278 |
v.getDescription() + "\t" + v.getExternalId() + "\t" + v.isFileOnly() + "\t" + |
3783 |
25 Sep 07 |
nicklas |
279 |
v.getRawDataType() + "\t" + v.getPlatform()); |
3783 |
25 Sep 07 |
nicklas |
280 |
} |
3783 |
25 Sep 07 |
nicklas |
281 |
} |
3783 |
25 Sep 07 |
nicklas |
282 |
|
3793 |
27 Sep 07 |
nicklas |
283 |
static void write_item(int i, PlatformFileType ft) |
3793 |
27 Sep 07 |
nicklas |
284 |
throws BaseException |
3793 |
27 Sep 07 |
nicklas |
285 |
{ |
3793 |
27 Sep 07 |
nicklas |
286 |
if (!TestUtil.getSilent()) |
3793 |
27 Sep 07 |
nicklas |
287 |
{ |
3793 |
27 Sep 07 |
nicklas |
288 |
System.out.println(i+":\t"+ft.getId()+"\t"+ft.getPlatform()+"\t"+ |
5713 |
02 Sep 11 |
nicklas |
289 |
ft.getVariant() + "\t" + ft.getDataFileType() + "\t" + ft.isRequired() + "\t" + ft.getAllowMultiple()); |
3793 |
27 Sep 07 |
nicklas |
290 |
} |
3793 |
27 Sep 07 |
nicklas |
291 |
} |
3793 |
27 Sep 07 |
nicklas |
292 |
|
3764 |
21 Sep 07 |
nicklas |
293 |
static void write(String message) |
3764 |
21 Sep 07 |
nicklas |
294 |
{ |
3764 |
21 Sep 07 |
nicklas |
295 |
System.out.println(message); |
3764 |
21 Sep 07 |
nicklas |
296 |
} |
3783 |
25 Sep 07 |
nicklas |
297 |
|
3783 |
25 Sep 07 |
nicklas |
298 |
static int test_create_variant(int platformId, String name, String systemId, Boolean fileOnly, int channels, String rawDataType) |
3783 |
25 Sep 07 |
nicklas |
299 |
{ |
3783 |
25 Sep 07 |
nicklas |
300 |
if (platformId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.PLATFORMVARIANT)) return 0; |
3783 |
25 Sep 07 |
nicklas |
301 |
int id = 0; |
3783 |
25 Sep 07 |
nicklas |
302 |
DbControl dc = null; |
3783 |
25 Sep 07 |
nicklas |
303 |
try |
3783 |
25 Sep 07 |
nicklas |
304 |
{ |
3783 |
25 Sep 07 |
nicklas |
305 |
dc = TestUtil.getDbControl(); |
3783 |
25 Sep 07 |
nicklas |
306 |
|
3783 |
25 Sep 07 |
nicklas |
307 |
Platform p = Platform.getById(dc, platformId); |
3783 |
25 Sep 07 |
nicklas |
308 |
|
3783 |
25 Sep 07 |
nicklas |
309 |
PlatformVariant v = null; |
3783 |
25 Sep 07 |
nicklas |
310 |
if (fileOnly == null) |
3783 |
25 Sep 07 |
nicklas |
311 |
{ |
3783 |
25 Sep 07 |
nicklas |
312 |
v = PlatformVariant.getNew(dc, p, systemId); |
3783 |
25 Sep 07 |
nicklas |
313 |
} |
3783 |
25 Sep 07 |
nicklas |
314 |
else if (fileOnly == true) |
3783 |
25 Sep 07 |
nicklas |
315 |
{ |
3783 |
25 Sep 07 |
nicklas |
316 |
v = PlatformVariant.getNew(dc, p, systemId, channels); |
3783 |
25 Sep 07 |
nicklas |
317 |
} |
3783 |
25 Sep 07 |
nicklas |
318 |
else |
3783 |
25 Sep 07 |
nicklas |
319 |
{ |
3783 |
25 Sep 07 |
nicklas |
320 |
v = PlatformVariant.getNew(dc, p, systemId, RawDataTypes.getRawDataType(rawDataType)); |
3783 |
25 Sep 07 |
nicklas |
321 |
} |
3783 |
25 Sep 07 |
nicklas |
322 |
v.setName(name); |
3783 |
25 Sep 07 |
nicklas |
323 |
dc.saveItem(v); |
3783 |
25 Sep 07 |
nicklas |
324 |
dc.commit(); |
3783 |
25 Sep 07 |
nicklas |
325 |
id = v.getId(); |
3783 |
25 Sep 07 |
nicklas |
326 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
327 |
dc.reattachItem(v, false); |
3783 |
25 Sep 07 |
nicklas |
328 |
write_item(0, v); |
3783 |
25 Sep 07 |
nicklas |
329 |
write("--Create platform variant OK"); |
3783 |
25 Sep 07 |
nicklas |
330 |
} |
3783 |
25 Sep 07 |
nicklas |
331 |
catch (Throwable ex) |
3783 |
25 Sep 07 |
nicklas |
332 |
{ |
3783 |
25 Sep 07 |
nicklas |
333 |
write("--Create platform variant FAILED"); |
3783 |
25 Sep 07 |
nicklas |
334 |
ex.printStackTrace(); |
3783 |
25 Sep 07 |
nicklas |
335 |
ok = false; |
3783 |
25 Sep 07 |
nicklas |
336 |
} |
3783 |
25 Sep 07 |
nicklas |
337 |
finally |
3783 |
25 Sep 07 |
nicklas |
338 |
{ |
3783 |
25 Sep 07 |
nicklas |
339 |
if (dc != null) dc.close(); |
3783 |
25 Sep 07 |
nicklas |
340 |
} |
3783 |
25 Sep 07 |
nicklas |
341 |
return id; |
3783 |
25 Sep 07 |
nicklas |
342 |
} |
3783 |
25 Sep 07 |
nicklas |
343 |
|
3783 |
25 Sep 07 |
nicklas |
344 |
static void test_list_variants(int platformId, int expectedResults) |
3783 |
25 Sep 07 |
nicklas |
345 |
{ |
3783 |
25 Sep 07 |
nicklas |
346 |
if (platformId == 0) return; |
3783 |
25 Sep 07 |
nicklas |
347 |
DbControl dc = null; |
3783 |
25 Sep 07 |
nicklas |
348 |
try |
3783 |
25 Sep 07 |
nicklas |
349 |
{ |
3783 |
25 Sep 07 |
nicklas |
350 |
dc = TestUtil.getDbControl(); |
3783 |
25 Sep 07 |
nicklas |
351 |
Platform p = Platform.getById(dc, platformId); |
3783 |
25 Sep 07 |
nicklas |
352 |
ItemResultList<PlatformVariant> l = p.getVariants().list(dc); |
3783 |
25 Sep 07 |
nicklas |
353 |
for (int i = 0; i<l.size(); i++) |
3783 |
25 Sep 07 |
nicklas |
354 |
{ |
3783 |
25 Sep 07 |
nicklas |
355 |
write_item(i, l.get(i)); |
3783 |
25 Sep 07 |
nicklas |
356 |
} |
3783 |
25 Sep 07 |
nicklas |
357 |
if (expectedResults >= 0 && expectedResults != l.size()) |
3783 |
25 Sep 07 |
nicklas |
358 |
{ |
3783 |
25 Sep 07 |
nicklas |
359 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
3783 |
25 Sep 07 |
nicklas |
360 |
} |
3783 |
25 Sep 07 |
nicklas |
361 |
write("--List platform variants OK ("+l.size()+")"); |
3783 |
25 Sep 07 |
nicklas |
362 |
} |
3783 |
25 Sep 07 |
nicklas |
363 |
catch (Throwable ex) |
3783 |
25 Sep 07 |
nicklas |
364 |
{ |
3783 |
25 Sep 07 |
nicklas |
365 |
write("--List platform variants FAILED"); |
3783 |
25 Sep 07 |
nicklas |
366 |
ex.printStackTrace(); |
3783 |
25 Sep 07 |
nicklas |
367 |
ok = false; |
3783 |
25 Sep 07 |
nicklas |
368 |
} |
3783 |
25 Sep 07 |
nicklas |
369 |
finally |
3783 |
25 Sep 07 |
nicklas |
370 |
{ |
3783 |
25 Sep 07 |
nicklas |
371 |
if (dc != null) dc.close(); |
3783 |
25 Sep 07 |
nicklas |
372 |
} |
3783 |
25 Sep 07 |
nicklas |
373 |
} |
3783 |
25 Sep 07 |
nicklas |
374 |
|
3783 |
25 Sep 07 |
nicklas |
375 |
static void test_delete_variant(int variantId) |
3783 |
25 Sep 07 |
nicklas |
376 |
{ |
3783 |
25 Sep 07 |
nicklas |
377 |
if (variantId == 0) return; |
3783 |
25 Sep 07 |
nicklas |
378 |
DbControl dc = null; |
3783 |
25 Sep 07 |
nicklas |
379 |
try |
3783 |
25 Sep 07 |
nicklas |
380 |
{ |
3783 |
25 Sep 07 |
nicklas |
381 |
dc = TestUtil.getDbControl(); |
3783 |
25 Sep 07 |
nicklas |
382 |
PlatformVariant v = PlatformVariant.getById(dc, variantId); |
3783 |
25 Sep 07 |
nicklas |
383 |
dc.deleteItem(v); |
3783 |
25 Sep 07 |
nicklas |
384 |
dc.commit(); |
3783 |
25 Sep 07 |
nicklas |
385 |
write("--Delete platform variant OK"); |
3783 |
25 Sep 07 |
nicklas |
386 |
} |
3783 |
25 Sep 07 |
nicklas |
387 |
catch (Throwable ex) |
3783 |
25 Sep 07 |
nicklas |
388 |
{ |
3783 |
25 Sep 07 |
nicklas |
389 |
write("--Delete platform variant FAILED"); |
3783 |
25 Sep 07 |
nicklas |
390 |
ex.printStackTrace(); |
3783 |
25 Sep 07 |
nicklas |
391 |
ok = false; |
3783 |
25 Sep 07 |
nicklas |
392 |
} |
3783 |
25 Sep 07 |
nicklas |
393 |
finally |
3783 |
25 Sep 07 |
nicklas |
394 |
{ |
3783 |
25 Sep 07 |
nicklas |
395 |
if (dc != null) dc.close(); |
3783 |
25 Sep 07 |
nicklas |
396 |
} |
3783 |
25 Sep 07 |
nicklas |
397 |
} |
3783 |
25 Sep 07 |
nicklas |
398 |
|
5713 |
02 Sep 11 |
nicklas |
399 |
static void test_add_filetype(int platformId, int variantId, int fileTypeId, boolean required, boolean multiple) |
3783 |
25 Sep 07 |
nicklas |
400 |
{ |
3783 |
25 Sep 07 |
nicklas |
401 |
if (platformId == 0 || fileTypeId == 0) return; |
3783 |
25 Sep 07 |
nicklas |
402 |
DbControl dc = null; |
3783 |
25 Sep 07 |
nicklas |
403 |
try |
3783 |
25 Sep 07 |
nicklas |
404 |
{ |
3783 |
25 Sep 07 |
nicklas |
405 |
dc = TestUtil.getDbControl(); |
3783 |
25 Sep 07 |
nicklas |
406 |
|
3783 |
25 Sep 07 |
nicklas |
407 |
Platform p = Platform.getById(dc, platformId); |
3783 |
25 Sep 07 |
nicklas |
408 |
PlatformVariant v = variantId == 0 ? null : PlatformVariant.getById(dc, variantId); |
3793 |
27 Sep 07 |
nicklas |
409 |
DataFileType fileType = DataFileType.getById(dc, fileTypeId); |
3783 |
25 Sep 07 |
nicklas |
410 |
|
5713 |
02 Sep 11 |
nicklas |
411 |
PlatformFileType pf = p.getFileType(fileType, v, true); |
5713 |
02 Sep 11 |
nicklas |
412 |
pf.setRequired(required); |
5713 |
02 Sep 11 |
nicklas |
413 |
pf.setAllowMultiple(multiple); |
3783 |
25 Sep 07 |
nicklas |
414 |
|
3783 |
25 Sep 07 |
nicklas |
415 |
dc.commit(); |
3793 |
27 Sep 07 |
nicklas |
416 |
write("--Add file type to platform OK"); |
3783 |
25 Sep 07 |
nicklas |
417 |
} |
3783 |
25 Sep 07 |
nicklas |
418 |
catch (Throwable ex) |
3783 |
25 Sep 07 |
nicklas |
419 |
{ |
3793 |
27 Sep 07 |
nicklas |
420 |
write("--Add file type to platform FAILED"); |
3783 |
25 Sep 07 |
nicklas |
421 |
ex.printStackTrace(); |
3783 |
25 Sep 07 |
nicklas |
422 |
ok = false; |
3783 |
25 Sep 07 |
nicklas |
423 |
} |
3783 |
25 Sep 07 |
nicklas |
424 |
finally |
3783 |
25 Sep 07 |
nicklas |
425 |
{ |
3783 |
25 Sep 07 |
nicklas |
426 |
if (dc != null) dc.close(); |
3783 |
25 Sep 07 |
nicklas |
427 |
} |
3783 |
25 Sep 07 |
nicklas |
428 |
} |
3783 |
25 Sep 07 |
nicklas |
429 |
|
3793 |
27 Sep 07 |
nicklas |
430 |
static void test_list_filetypes(int platformId, int variantId, boolean restrict, int expectedResults) |
3783 |
25 Sep 07 |
nicklas |
431 |
{ |
3783 |
25 Sep 07 |
nicklas |
432 |
if (platformId == 0) return; |
3783 |
25 Sep 07 |
nicklas |
433 |
DbControl dc = null; |
3783 |
25 Sep 07 |
nicklas |
434 |
try |
3783 |
25 Sep 07 |
nicklas |
435 |
{ |
3783 |
25 Sep 07 |
nicklas |
436 |
dc = TestUtil.getDbControl(); |
3783 |
25 Sep 07 |
nicklas |
437 |
Platform p = Platform.getById(dc, platformId); |
3783 |
25 Sep 07 |
nicklas |
438 |
PlatformVariant v = variantId == 0 ? null : PlatformVariant.getById(dc, variantId); |
3793 |
27 Sep 07 |
nicklas |
439 |
ItemResultList<PlatformFileType> l = p.getFileTypes(v, restrict).list(dc); |
3783 |
25 Sep 07 |
nicklas |
440 |
for (int i = 0; i<l.size(); i++) |
3783 |
25 Sep 07 |
nicklas |
441 |
{ |
3783 |
25 Sep 07 |
nicklas |
442 |
write_item(i, l.get(i)); |
3783 |
25 Sep 07 |
nicklas |
443 |
} |
3783 |
25 Sep 07 |
nicklas |
444 |
if (expectedResults >= 0 && expectedResults != l.size()) |
3783 |
25 Sep 07 |
nicklas |
445 |
{ |
3783 |
25 Sep 07 |
nicklas |
446 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
3783 |
25 Sep 07 |
nicklas |
447 |
} |
3783 |
25 Sep 07 |
nicklas |
448 |
write("--List platform file types OK ("+l.size()+")"); |
3783 |
25 Sep 07 |
nicklas |
449 |
} |
3783 |
25 Sep 07 |
nicklas |
450 |
catch (Throwable ex) |
3783 |
25 Sep 07 |
nicklas |
451 |
{ |
3783 |
25 Sep 07 |
nicklas |
452 |
write("--List platform file types FAILED"); |
3783 |
25 Sep 07 |
nicklas |
453 |
ex.printStackTrace(); |
3783 |
25 Sep 07 |
nicklas |
454 |
ok = false; |
3783 |
25 Sep 07 |
nicklas |
455 |
} |
3783 |
25 Sep 07 |
nicklas |
456 |
finally |
3783 |
25 Sep 07 |
nicklas |
457 |
{ |
3783 |
25 Sep 07 |
nicklas |
458 |
if (dc != null) dc.close(); |
3783 |
25 Sep 07 |
nicklas |
459 |
} |
3783 |
25 Sep 07 |
nicklas |
460 |
} |
3783 |
25 Sep 07 |
nicklas |
461 |
|
3783 |
25 Sep 07 |
nicklas |
462 |
|
3764 |
21 Sep 07 |
nicklas |
463 |
} |