470 |
26 Apr 05 |
enell |
1 |
import java.util.Date; |
5340 |
10 May 10 |
nicklas |
2 |
import java.util.Set; |
470 |
26 Apr 05 |
enell |
3 |
|
470 |
26 Apr 05 |
enell |
4 |
import net.sf.basedb.core.BaseException; |
470 |
26 Apr 05 |
enell |
5 |
import net.sf.basedb.core.DbControl; |
470 |
26 Apr 05 |
enell |
6 |
import net.sf.basedb.core.Directory; |
2205 |
28 Apr 06 |
enell |
7 |
import net.sf.basedb.core.File; |
470 |
26 Apr 05 |
enell |
8 |
import net.sf.basedb.core.Item; |
5340 |
10 May 10 |
nicklas |
9 |
import net.sf.basedb.core.ItemProxy; |
474 |
27 Apr 05 |
enell |
10 |
import net.sf.basedb.core.Path; |
470 |
26 Apr 05 |
enell |
11 |
import net.sf.basedb.core.Permission; |
1418 |
07 Oct 05 |
nicklas |
12 |
import net.sf.basedb.core.ItemQuery; |
1418 |
07 Oct 05 |
nicklas |
13 |
import net.sf.basedb.core.ItemResultList; |
650 |
25 May 05 |
enell |
14 |
import net.sf.basedb.core.SystemItems; |
470 |
26 Apr 05 |
enell |
15 |
|
470 |
26 Apr 05 |
enell |
16 |
/* |
470 |
26 Apr 05 |
enell |
$Id$ |
470 |
26 Apr 05 |
enell |
18 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg |
470 |
26 Apr 05 |
enell |
21 |
|
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/ |
470 |
26 Apr 05 |
enell |
24 |
|
470 |
26 Apr 05 |
enell |
BASE is free software; you can redistribute it and/or |
470 |
26 Apr 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 |
470 |
26 Apr 05 |
enell |
of the License, or (at your option) any later version. |
470 |
26 Apr 05 |
enell |
29 |
|
470 |
26 Apr 05 |
enell |
BASE is distributed in the hope that it will be useful, |
470 |
26 Apr 05 |
enell |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
470 |
26 Apr 05 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
470 |
26 Apr 05 |
enell |
GNU General Public License for more details. |
470 |
26 Apr 05 |
enell |
34 |
|
470 |
26 Apr 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/>. |
470 |
26 Apr 05 |
enell |
37 |
*/ |
470 |
26 Apr 05 |
enell |
38 |
|
470 |
26 Apr 05 |
enell |
39 |
public class TestDirectory |
470 |
26 Apr 05 |
enell |
40 |
{ |
470 |
26 Apr 05 |
enell |
41 |
private static boolean ok = true; |
470 |
26 Apr 05 |
enell |
42 |
|
470 |
26 Apr 05 |
enell |
43 |
public static void main(String[] args) |
470 |
26 Apr 05 |
enell |
44 |
{ |
470 |
26 Apr 05 |
enell |
45 |
TestUtil.checkArgs(args); |
470 |
26 Apr 05 |
enell |
46 |
TestUtil.begin(); |
470 |
26 Apr 05 |
enell |
47 |
ok = test_all(); |
470 |
26 Apr 05 |
enell |
48 |
TestUtil.stop(); |
470 |
26 Apr 05 |
enell |
49 |
} |
470 |
26 Apr 05 |
enell |
50 |
|
470 |
26 Apr 05 |
enell |
51 |
static boolean test_all() |
470 |
26 Apr 05 |
enell |
52 |
{ |
470 |
26 Apr 05 |
enell |
53 |
write("++Testing directory"); |
470 |
26 Apr 05 |
enell |
54 |
write_header(); |
470 |
26 Apr 05 |
enell |
// Standard tests: create, load, list |
660 |
27 May 05 |
enell |
56 |
int id1 = test_create(true, "Test directory1"); |
660 |
27 May 05 |
enell |
57 |
int id2 = test_create(false, "Test directory2"); |
660 |
27 May 05 |
enell |
58 |
test_load(id1); |
470 |
26 Apr 05 |
enell |
59 |
test_list(); |
470 |
26 Apr 05 |
enell |
60 |
|
470 |
26 Apr 05 |
enell |
// Extra tests: create, list, load and delete subdirectory |
660 |
27 May 05 |
enell |
62 |
int id_sub = test_create(id1); |
473 |
27 Apr 05 |
enell |
63 |
int id_sub2 = test_create(id_sub); |
681 |
31 May 05 |
nicklas |
64 |
if (id_sub != 0) test_load("/Test directory1/Test subdirectory"); |
660 |
27 May 05 |
enell |
65 |
test_list(id1); |
1529 |
27 Oct 05 |
nicklas |
66 |
|
6520 |
18 Aug 14 |
nicklas |
67 |
int[] pid = test_create_multiple("/foo", "/foo/bar1", "/foo/bar2", "/foo/bar1/sub1", "/foo/bar2/sub1", "/foo/bar2/sub2"); |
6520 |
18 Aug 14 |
nicklas |
68 |
|
1529 |
27 Oct 05 |
nicklas |
69 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
6520 |
18 Aug 14 |
nicklas |
70 |
if (pid != null && pid.length > 0) test_delete(pid[0], true); |
2205 |
28 Apr 06 |
enell |
71 |
test_delete(id_sub2, false); |
470 |
26 Apr 05 |
enell |
72 |
|
473 |
27 Apr 05 |
enell |
// Standard test list, delete |
473 |
27 Apr 05 |
enell |
74 |
test_list(); |
2205 |
28 Apr 06 |
enell |
75 |
test_delete(id_sub, false); |
2205 |
28 Apr 06 |
enell |
76 |
test_delete(id1, false); |
2205 |
28 Apr 06 |
enell |
77 |
test_delete(id2, false); |
470 |
26 Apr 05 |
enell |
78 |
write("++Testing directory "+(ok ? "OK" : "Failed")+"\n"); |
470 |
26 Apr 05 |
enell |
79 |
return ok; |
470 |
26 Apr 05 |
enell |
80 |
} |
470 |
26 Apr 05 |
enell |
81 |
|
660 |
27 May 05 |
enell |
82 |
static int test_create(boolean testAll, String directoryName) |
470 |
26 Apr 05 |
enell |
83 |
{ |
470 |
26 Apr 05 |
enell |
84 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.DIRECTORY)) return 0; |
470 |
26 Apr 05 |
enell |
85 |
int id = 0; |
470 |
26 Apr 05 |
enell |
86 |
DbControl dc = null; |
470 |
26 Apr 05 |
enell |
87 |
try |
470 |
26 Apr 05 |
enell |
88 |
{ |
470 |
26 Apr 05 |
enell |
89 |
dc = TestUtil.getDbControl(); |
650 |
25 May 05 |
enell |
90 |
Directory root = Directory.getById(dc, SystemItems.getId(Directory.ROOT)); |
659 |
27 May 05 |
nicklas |
91 |
Directory d = Directory.getNew(dc, root); |
6520 |
18 Aug 14 |
nicklas |
92 |
d.setName(directoryName); |
660 |
27 May 05 |
enell |
93 |
if (testAll) |
660 |
27 May 05 |
enell |
94 |
{ |
660 |
27 May 05 |
enell |
95 |
d.setDescription("Added at "+new Date()); |
3719 |
12 Sep 07 |
nicklas |
96 |
d.setAutoCompress(true); |
660 |
27 May 05 |
enell |
97 |
} |
470 |
26 Apr 05 |
enell |
98 |
dc.saveItem(d); |
470 |
26 Apr 05 |
enell |
99 |
dc.commit(); |
470 |
26 Apr 05 |
enell |
100 |
id = d.getId(); |
806 |
22 Jun 05 |
nicklas |
101 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
102 |
dc.reattachItem(d, false); |
470 |
26 Apr 05 |
enell |
103 |
write_item(0, d); |
470 |
26 Apr 05 |
enell |
104 |
write("--Create directory OK"); |
470 |
26 Apr 05 |
enell |
105 |
} |
816 |
23 Jun 05 |
nicklas |
106 |
catch (Throwable ex) |
470 |
26 Apr 05 |
enell |
107 |
{ |
470 |
26 Apr 05 |
enell |
108 |
write("--Create directory FAILED"); |
470 |
26 Apr 05 |
enell |
109 |
ex.printStackTrace(); |
470 |
26 Apr 05 |
enell |
110 |
ok = false; |
470 |
26 Apr 05 |
enell |
111 |
} |
470 |
26 Apr 05 |
enell |
112 |
finally |
470 |
26 Apr 05 |
enell |
113 |
{ |
470 |
26 Apr 05 |
enell |
114 |
if (dc != null) dc.close(); |
470 |
26 Apr 05 |
enell |
115 |
} |
470 |
26 Apr 05 |
enell |
116 |
return id; |
470 |
26 Apr 05 |
enell |
117 |
} |
470 |
26 Apr 05 |
enell |
118 |
|
806 |
22 Jun 05 |
nicklas |
119 |
static int test_create(int parentId) |
470 |
26 Apr 05 |
enell |
120 |
{ |
806 |
22 Jun 05 |
nicklas |
121 |
if (parentId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.DIRECTORY)) return 0; |
470 |
26 Apr 05 |
enell |
122 |
int id = 0; |
470 |
26 Apr 05 |
enell |
123 |
DbControl dc = null; |
470 |
26 Apr 05 |
enell |
124 |
try |
470 |
26 Apr 05 |
enell |
125 |
{ |
470 |
26 Apr 05 |
enell |
126 |
dc = TestUtil.getDbControl(); |
806 |
22 Jun 05 |
nicklas |
127 |
Directory d = Directory.getById(dc, parentId); |
470 |
26 Apr 05 |
enell |
128 |
Directory sub = d.newSubDirectory(); |
470 |
26 Apr 05 |
enell |
129 |
sub.setName("Test subdirectory"); |
470 |
26 Apr 05 |
enell |
130 |
sub.setDescription("Added at "+new Date()); |
470 |
26 Apr 05 |
enell |
131 |
dc.saveItem(sub); |
470 |
26 Apr 05 |
enell |
132 |
dc.commit(); |
470 |
26 Apr 05 |
enell |
133 |
id = sub.getId(); |
806 |
22 Jun 05 |
nicklas |
134 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
135 |
dc.reattachItem(sub, false); |
470 |
26 Apr 05 |
enell |
136 |
write_item(0, sub); |
470 |
26 Apr 05 |
enell |
137 |
write("--Create subdirectory OK"); |
470 |
26 Apr 05 |
enell |
138 |
} |
816 |
23 Jun 05 |
nicklas |
139 |
catch (Throwable ex) |
470 |
26 Apr 05 |
enell |
140 |
{ |
470 |
26 Apr 05 |
enell |
141 |
write("--Create subdirectory FAILED"); |
470 |
26 Apr 05 |
enell |
142 |
ex.printStackTrace(); |
470 |
26 Apr 05 |
enell |
143 |
ok = false; |
470 |
26 Apr 05 |
enell |
144 |
} |
470 |
26 Apr 05 |
enell |
145 |
finally |
470 |
26 Apr 05 |
enell |
146 |
{ |
470 |
26 Apr 05 |
enell |
147 |
if (dc != null) dc.close(); |
470 |
26 Apr 05 |
enell |
148 |
} |
470 |
26 Apr 05 |
enell |
149 |
return id; |
470 |
26 Apr 05 |
enell |
150 |
} |
470 |
26 Apr 05 |
enell |
151 |
|
6520 |
18 Aug 14 |
nicklas |
152 |
static int[] test_create_multiple(String... path) |
6520 |
18 Aug 14 |
nicklas |
153 |
{ |
6520 |
18 Aug 14 |
nicklas |
154 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.DIRECTORY)) return null; |
6520 |
18 Aug 14 |
nicklas |
155 |
Directory d[] = new Directory[path.length]; |
6520 |
18 Aug 14 |
nicklas |
156 |
int id[] = new int[path.length]; |
6520 |
18 Aug 14 |
nicklas |
157 |
DbControl dc = null; |
6520 |
18 Aug 14 |
nicklas |
158 |
try |
6520 |
18 Aug 14 |
nicklas |
159 |
{ |
6520 |
18 Aug 14 |
nicklas |
160 |
dc = TestUtil.getDbControl(); |
6520 |
18 Aug 14 |
nicklas |
161 |
for (int i = 0; i < path.length; i++) |
6520 |
18 Aug 14 |
nicklas |
162 |
{ |
6520 |
18 Aug 14 |
nicklas |
163 |
Path p = new Path(path[i], Path.Type.DIRECTORY); |
6520 |
18 Aug 14 |
nicklas |
164 |
d[i] = Directory.getNew(dc, p); |
6520 |
18 Aug 14 |
nicklas |
165 |
} |
6520 |
18 Aug 14 |
nicklas |
166 |
dc.commit(); |
6520 |
18 Aug 14 |
nicklas |
167 |
|
6520 |
18 Aug 14 |
nicklas |
// Copy id values |
6520 |
18 Aug 14 |
nicklas |
169 |
dc = TestUtil.getDbControl(); |
6520 |
18 Aug 14 |
nicklas |
170 |
for (int i = 0; i < path.length; i++) |
6520 |
18 Aug 14 |
nicklas |
171 |
{ |
6520 |
18 Aug 14 |
nicklas |
172 |
id[i] = d[i].getId(); |
6520 |
18 Aug 14 |
nicklas |
173 |
dc.reattachItem(d[i], false); |
6520 |
18 Aug 14 |
nicklas |
174 |
write_item(i, d[i]); |
6520 |
18 Aug 14 |
nicklas |
175 |
} |
6520 |
18 Aug 14 |
nicklas |
176 |
|
6520 |
18 Aug 14 |
nicklas |
177 |
write("--Create multiple by path OK"); |
6520 |
18 Aug 14 |
nicklas |
178 |
} |
6520 |
18 Aug 14 |
nicklas |
179 |
catch (Throwable ex) |
6520 |
18 Aug 14 |
nicklas |
180 |
{ |
6520 |
18 Aug 14 |
nicklas |
181 |
write("--Create multiple by path FAILED"); |
6520 |
18 Aug 14 |
nicklas |
182 |
ex.printStackTrace(); |
6520 |
18 Aug 14 |
nicklas |
183 |
ok = false; |
6520 |
18 Aug 14 |
nicklas |
184 |
} |
6520 |
18 Aug 14 |
nicklas |
185 |
finally |
6520 |
18 Aug 14 |
nicklas |
186 |
{ |
6520 |
18 Aug 14 |
nicklas |
187 |
if (dc != null) dc.close(); |
6520 |
18 Aug 14 |
nicklas |
188 |
} |
6520 |
18 Aug 14 |
nicklas |
189 |
return id; |
6520 |
18 Aug 14 |
nicklas |
190 |
} |
6520 |
18 Aug 14 |
nicklas |
191 |
|
6520 |
18 Aug 14 |
nicklas |
192 |
|
470 |
26 Apr 05 |
enell |
193 |
static void test_load(int id) |
470 |
26 Apr 05 |
enell |
194 |
{ |
470 |
26 Apr 05 |
enell |
195 |
if (id == 0) return; |
470 |
26 Apr 05 |
enell |
196 |
DbControl dc = null; |
470 |
26 Apr 05 |
enell |
197 |
try |
470 |
26 Apr 05 |
enell |
198 |
{ |
470 |
26 Apr 05 |
enell |
199 |
dc = TestUtil.getDbControl(); |
470 |
26 Apr 05 |
enell |
200 |
Directory d = Directory.getById(dc, id); |
470 |
26 Apr 05 |
enell |
201 |
write_item(0, d); |
470 |
26 Apr 05 |
enell |
202 |
write("--Load directory OK"); |
470 |
26 Apr 05 |
enell |
203 |
} |
816 |
23 Jun 05 |
nicklas |
204 |
catch (Throwable ex) |
470 |
26 Apr 05 |
enell |
205 |
{ |
470 |
26 Apr 05 |
enell |
206 |
write("--Load directory FAILED"); |
470 |
26 Apr 05 |
enell |
207 |
ex.printStackTrace(); |
470 |
26 Apr 05 |
enell |
208 |
ok = false; |
470 |
26 Apr 05 |
enell |
209 |
} |
470 |
26 Apr 05 |
enell |
210 |
finally |
470 |
26 Apr 05 |
enell |
211 |
{ |
470 |
26 Apr 05 |
enell |
212 |
if (dc != null) dc.close(); |
470 |
26 Apr 05 |
enell |
213 |
} |
470 |
26 Apr 05 |
enell |
214 |
} |
474 |
27 Apr 05 |
enell |
215 |
|
474 |
27 Apr 05 |
enell |
216 |
static void test_load(String path) |
474 |
27 Apr 05 |
enell |
217 |
{ |
474 |
27 Apr 05 |
enell |
218 |
DbControl dc = null; |
474 |
27 Apr 05 |
enell |
219 |
try |
474 |
27 Apr 05 |
enell |
220 |
{ |
474 |
27 Apr 05 |
enell |
221 |
dc = TestUtil.getDbControl(); |
650 |
25 May 05 |
enell |
222 |
Directory d = Directory.getByPath(dc, new Path(path, Path.Type.DIRECTORY)); |
474 |
27 Apr 05 |
enell |
223 |
write_item(0, d); |
474 |
27 Apr 05 |
enell |
224 |
write("--Load directory by path OK"); |
474 |
27 Apr 05 |
enell |
225 |
} |
816 |
23 Jun 05 |
nicklas |
226 |
catch (Throwable ex) |
474 |
27 Apr 05 |
enell |
227 |
{ |
474 |
27 Apr 05 |
enell |
228 |
write("--Load directory by path FAILED"); |
474 |
27 Apr 05 |
enell |
229 |
ex.printStackTrace(); |
474 |
27 Apr 05 |
enell |
230 |
ok = false; |
474 |
27 Apr 05 |
enell |
231 |
} |
474 |
27 Apr 05 |
enell |
232 |
finally |
474 |
27 Apr 05 |
enell |
233 |
{ |
474 |
27 Apr 05 |
enell |
234 |
if (dc != null) dc.close(); |
474 |
27 Apr 05 |
enell |
235 |
} |
470 |
26 Apr 05 |
enell |
236 |
|
474 |
27 Apr 05 |
enell |
237 |
} |
474 |
27 Apr 05 |
enell |
238 |
|
470 |
26 Apr 05 |
enell |
239 |
static void test_list() |
470 |
26 Apr 05 |
enell |
240 |
{ |
470 |
26 Apr 05 |
enell |
241 |
DbControl dc = null; |
470 |
26 Apr 05 |
enell |
242 |
try |
470 |
26 Apr 05 |
enell |
243 |
{ |
470 |
26 Apr 05 |
enell |
244 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
245 |
ItemResultList<Directory> l = Directory.getQuery().list(dc); |
470 |
26 Apr 05 |
enell |
246 |
for (int i = 0; i<l.size(); i++) |
470 |
26 Apr 05 |
enell |
247 |
{ |
470 |
26 Apr 05 |
enell |
248 |
write_item(i, l.get(i)); |
470 |
26 Apr 05 |
enell |
249 |
} |
470 |
26 Apr 05 |
enell |
250 |
write("--List directories OK ("+l.size()+")"); |
470 |
26 Apr 05 |
enell |
251 |
} |
816 |
23 Jun 05 |
nicklas |
252 |
catch (Throwable ex) |
470 |
26 Apr 05 |
enell |
253 |
{ |
470 |
26 Apr 05 |
enell |
254 |
write("--List directories FAILED"); |
470 |
26 Apr 05 |
enell |
255 |
ex.printStackTrace(); |
470 |
26 Apr 05 |
enell |
256 |
ok = false; |
470 |
26 Apr 05 |
enell |
257 |
} |
470 |
26 Apr 05 |
enell |
258 |
finally |
470 |
26 Apr 05 |
enell |
259 |
{ |
470 |
26 Apr 05 |
enell |
260 |
if (dc != null) dc.close(); |
470 |
26 Apr 05 |
enell |
261 |
} |
470 |
26 Apr 05 |
enell |
262 |
} |
470 |
26 Apr 05 |
enell |
263 |
|
470 |
26 Apr 05 |
enell |
264 |
static void test_list(int parentId) |
470 |
26 Apr 05 |
enell |
265 |
{ |
470 |
26 Apr 05 |
enell |
266 |
if (parentId == 0) return; |
470 |
26 Apr 05 |
enell |
267 |
DbControl dc = null; |
470 |
26 Apr 05 |
enell |
268 |
try |
470 |
26 Apr 05 |
enell |
269 |
{ |
470 |
26 Apr 05 |
enell |
270 |
dc = TestUtil.getDbControl(); |
470 |
26 Apr 05 |
enell |
271 |
Directory d = Directory.getById(dc, parentId); |
1418 |
07 Oct 05 |
nicklas |
272 |
ItemQuery<Directory> q = d.getSubDirectories(); |
470 |
26 Apr 05 |
enell |
273 |
|
470 |
26 Apr 05 |
enell |
274 |
int i = 0; |
1418 |
07 Oct 05 |
nicklas |
275 |
for (Directory sub : q.list(dc)) |
470 |
26 Apr 05 |
enell |
276 |
{ |
470 |
26 Apr 05 |
enell |
277 |
write_item(i++, sub); |
470 |
26 Apr 05 |
enell |
278 |
} |
470 |
26 Apr 05 |
enell |
279 |
write("--List subdirectories OK ("+i+")"); |
470 |
26 Apr 05 |
enell |
280 |
} |
816 |
23 Jun 05 |
nicklas |
281 |
catch (Throwable ex) |
470 |
26 Apr 05 |
enell |
282 |
{ |
470 |
26 Apr 05 |
enell |
283 |
write("--List subdirectories FAILED"); |
470 |
26 Apr 05 |
enell |
284 |
ex.printStackTrace(); |
470 |
26 Apr 05 |
enell |
285 |
ok = false; |
470 |
26 Apr 05 |
enell |
286 |
} |
470 |
26 Apr 05 |
enell |
287 |
finally |
470 |
26 Apr 05 |
enell |
288 |
{ |
470 |
26 Apr 05 |
enell |
289 |
if (dc != null) dc.close(); |
470 |
26 Apr 05 |
enell |
290 |
} |
470 |
26 Apr 05 |
enell |
291 |
} |
470 |
26 Apr 05 |
enell |
292 |
|
6520 |
18 Aug 14 |
nicklas |
293 |
static boolean test_list(String path, int expectedResults) |
6520 |
18 Aug 14 |
nicklas |
294 |
{ |
6520 |
18 Aug 14 |
nicklas |
295 |
DbControl dc = null; |
6520 |
18 Aug 14 |
nicklas |
296 |
try |
6520 |
18 Aug 14 |
nicklas |
297 |
{ |
6520 |
18 Aug 14 |
nicklas |
298 |
dc = TestUtil.getDbControl(); |
6520 |
18 Aug 14 |
nicklas |
299 |
Path p = new Path(path, Path.Type.DIRECTORY); |
6520 |
18 Aug 14 |
nicklas |
300 |
Directory d = Directory.getByPath(dc, p); |
6520 |
18 Aug 14 |
nicklas |
301 |
ItemResultList<Directory> subdirs = d.getSubDirectories().list(dc); |
6520 |
18 Aug 14 |
nicklas |
302 |
|
6520 |
18 Aug 14 |
nicklas |
303 |
for (int i = 0; i<subdirs.size(); i++) |
6520 |
18 Aug 14 |
nicklas |
304 |
{ |
6520 |
18 Aug 14 |
nicklas |
305 |
write_item(i, subdirs.get(i)); |
6520 |
18 Aug 14 |
nicklas |
306 |
} |
6520 |
18 Aug 14 |
nicklas |
307 |
if (expectedResults >=0 && expectedResults != subdirs.size()) |
6520 |
18 Aug 14 |
nicklas |
308 |
{ |
6520 |
18 Aug 14 |
nicklas |
309 |
throw new BaseException("Expected " + expectedResults + " results, " + |
6520 |
18 Aug 14 |
nicklas |
310 |
"not " + subdirs.size()); |
6520 |
18 Aug 14 |
nicklas |
311 |
} |
6520 |
18 Aug 14 |
nicklas |
312 |
write("--List subdirectories OK ("+subdirs.size()+")"); |
6520 |
18 Aug 14 |
nicklas |
313 |
} |
6520 |
18 Aug 14 |
nicklas |
314 |
catch (Throwable ex) |
6520 |
18 Aug 14 |
nicklas |
315 |
{ |
6520 |
18 Aug 14 |
nicklas |
316 |
write("--List subdirectories FAILED"); |
6520 |
18 Aug 14 |
nicklas |
317 |
ex.printStackTrace(); |
6520 |
18 Aug 14 |
nicklas |
318 |
ok = false; |
6520 |
18 Aug 14 |
nicklas |
319 |
return false; |
6520 |
18 Aug 14 |
nicklas |
320 |
} |
6520 |
18 Aug 14 |
nicklas |
321 |
finally |
6520 |
18 Aug 14 |
nicklas |
322 |
{ |
6520 |
18 Aug 14 |
nicklas |
323 |
if (dc != null) dc.close(); |
6520 |
18 Aug 14 |
nicklas |
324 |
} |
6520 |
18 Aug 14 |
nicklas |
325 |
return true; |
6520 |
18 Aug 14 |
nicklas |
326 |
} |
6520 |
18 Aug 14 |
nicklas |
327 |
|
6520 |
18 Aug 14 |
nicklas |
328 |
|
2205 |
28 Apr 06 |
enell |
329 |
static void test_delete(int id, boolean deleteAll) |
470 |
26 Apr 05 |
enell |
330 |
{ |
470 |
26 Apr 05 |
enell |
331 |
if (id == 0) return; |
470 |
26 Apr 05 |
enell |
332 |
DbControl dc = null; |
2205 |
28 Apr 06 |
enell |
333 |
Directory d = null; |
470 |
26 Apr 05 |
enell |
334 |
try |
470 |
26 Apr 05 |
enell |
335 |
{ |
470 |
26 Apr 05 |
enell |
336 |
dc = TestUtil.getDbControl(); |
2205 |
28 Apr 06 |
enell |
337 |
d = Directory.getById(dc, id); |
2205 |
28 Apr 06 |
enell |
338 |
if (deleteAll) |
2205 |
28 Apr 06 |
enell |
339 |
{ |
2251 |
12 May 06 |
enell |
340 |
test_deleteAll(id, dc); |
2205 |
28 Apr 06 |
enell |
341 |
} |
2251 |
12 May 06 |
enell |
342 |
else |
2251 |
12 May 06 |
enell |
343 |
{ |
2251 |
12 May 06 |
enell |
344 |
dc.deleteItem(d); |
5340 |
10 May 10 |
nicklas |
345 |
Set<ItemProxy> using = d.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
346 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
347 |
{ |
5340 |
10 May 10 |
nicklas |
348 |
throw new BaseException(d + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
349 |
} |
2251 |
12 May 06 |
enell |
350 |
} |
2205 |
28 Apr 06 |
enell |
351 |
|
470 |
26 Apr 05 |
enell |
352 |
dc.commit(); |
2205 |
28 Apr 06 |
enell |
353 |
write("--Delete directory "+d+" OK"); |
470 |
26 Apr 05 |
enell |
354 |
} |
816 |
23 Jun 05 |
nicklas |
355 |
catch (Throwable ex) |
470 |
26 Apr 05 |
enell |
356 |
{ |
2205 |
28 Apr 06 |
enell |
357 |
write("--Delete directory "+d+" FAILED"); |
470 |
26 Apr 05 |
enell |
358 |
ex.printStackTrace(); |
470 |
26 Apr 05 |
enell |
359 |
ok = false; |
470 |
26 Apr 05 |
enell |
360 |
} |
470 |
26 Apr 05 |
enell |
361 |
finally |
470 |
26 Apr 05 |
enell |
362 |
{ |
470 |
26 Apr 05 |
enell |
363 |
if (dc != null) dc.close(); |
470 |
26 Apr 05 |
enell |
364 |
} |
470 |
26 Apr 05 |
enell |
365 |
} |
470 |
26 Apr 05 |
enell |
366 |
|
2251 |
12 May 06 |
enell |
367 |
private static void test_deleteAll(int id, DbControl dc) |
2251 |
12 May 06 |
enell |
368 |
{ |
2251 |
12 May 06 |
enell |
369 |
Directory d = Directory.getById(dc, id); |
2251 |
12 May 06 |
enell |
370 |
|
2251 |
12 May 06 |
enell |
371 |
ItemQuery<Directory> directories = d.getSubDirectories(); |
2251 |
12 May 06 |
enell |
372 |
for (Directory subd : directories.list(dc)) |
2251 |
12 May 06 |
enell |
373 |
{ |
2251 |
12 May 06 |
enell |
374 |
test_deleteAll(subd.getId(), dc); |
2251 |
12 May 06 |
enell |
375 |
} |
2251 |
12 May 06 |
enell |
376 |
|
2251 |
12 May 06 |
enell |
377 |
ItemQuery<File> files = d.getFiles(); |
2251 |
12 May 06 |
enell |
378 |
for (File f : files.list(dc)) |
2251 |
12 May 06 |
enell |
379 |
{ |
2251 |
12 May 06 |
enell |
380 |
dc.deleteItem(f); |
2681 |
29 Sep 06 |
nicklas |
381 |
write("--Delete file "+f+" OK"); |
2251 |
12 May 06 |
enell |
382 |
} |
2251 |
12 May 06 |
enell |
383 |
|
2251 |
12 May 06 |
enell |
384 |
dc.deleteItem(d); |
2681 |
29 Sep 06 |
nicklas |
385 |
write("--Delete directory "+d+" OK"); |
2251 |
12 May 06 |
enell |
386 |
} |
2251 |
12 May 06 |
enell |
387 |
|
470 |
26 Apr 05 |
enell |
388 |
static void write_header() |
470 |
26 Apr 05 |
enell |
389 |
{ |
470 |
26 Apr 05 |
enell |
390 |
if (!TestUtil.getSilent()) |
470 |
26 Apr 05 |
enell |
391 |
{ |
3719 |
12 Sep 07 |
nicklas |
392 |
write(" \tID \tName \tDescription\tAuto compress\tParent\tPath"); |
3719 |
12 Sep 07 |
nicklas |
393 |
write("-- \t-- \t--------- \t-----------\t-------------\t------\t----"); |
470 |
26 Apr 05 |
enell |
394 |
} |
470 |
26 Apr 05 |
enell |
395 |
} |
470 |
26 Apr 05 |
enell |
396 |
static void write_item(int i, Directory d) |
470 |
26 Apr 05 |
enell |
397 |
throws BaseException |
470 |
26 Apr 05 |
enell |
398 |
{ |
3719 |
12 Sep 07 |
nicklas |
399 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+d.getId()+"\t"+d.getName()+"\t"+ |
3719 |
12 Sep 07 |
nicklas |
400 |
d.getDescription()+"\t"+d.getAutoCompress()+"\t"+d.getParent()+"\t"+d.getPath()); |
470 |
26 Apr 05 |
enell |
401 |
} |
470 |
26 Apr 05 |
enell |
402 |
|
470 |
26 Apr 05 |
enell |
403 |
static void write(String message) |
470 |
26 Apr 05 |
enell |
404 |
{ |
470 |
26 Apr 05 |
enell |
405 |
System.out.println(message); |
470 |
26 Apr 05 |
enell |
406 |
} |
3675 |
16 Aug 07 |
jari |
407 |
} |