642 |
24 May 05 |
enell |
1 |
/* |
642 |
24 May 05 |
enell |
$Id$ |
642 |
24 May 05 |
enell |
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 |
642 |
24 May 05 |
enell |
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/ |
642 |
24 May 05 |
enell |
9 |
|
642 |
24 May 05 |
enell |
BASE is free software; you can redistribute it and/or |
642 |
24 May 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 |
642 |
24 May 05 |
enell |
of the License, or (at your option) any later version. |
642 |
24 May 05 |
enell |
14 |
|
642 |
24 May 05 |
enell |
BASE is distributed in the hope that it will be useful, |
642 |
24 May 05 |
enell |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
642 |
24 May 05 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
642 |
24 May 05 |
enell |
GNU General Public License for more details. |
642 |
24 May 05 |
enell |
19 |
|
642 |
24 May 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/>. |
642 |
24 May 05 |
enell |
22 |
*/ |
1935 |
07 Feb 06 |
nicklas |
23 |
import net.sf.basedb.core.BaseException; |
1935 |
07 Feb 06 |
nicklas |
24 |
import net.sf.basedb.core.DbControl; |
1935 |
07 Feb 06 |
nicklas |
25 |
import net.sf.basedb.core.DiskUsage; |
1935 |
07 Feb 06 |
nicklas |
26 |
import net.sf.basedb.core.User; |
1935 |
07 Feb 06 |
nicklas |
27 |
import net.sf.basedb.core.ItemResultList; |
642 |
24 May 05 |
enell |
28 |
|
642 |
24 May 05 |
enell |
29 |
public class TestDiskUsage |
642 |
24 May 05 |
enell |
30 |
{ |
642 |
24 May 05 |
enell |
31 |
|
642 |
24 May 05 |
enell |
32 |
static boolean ok = true; |
642 |
24 May 05 |
enell |
33 |
|
642 |
24 May 05 |
enell |
34 |
public static void main(String[] args) |
642 |
24 May 05 |
enell |
35 |
{ |
642 |
24 May 05 |
enell |
36 |
TestUtil.checkArgs(args); |
642 |
24 May 05 |
enell |
37 |
TestUtil.begin(); |
642 |
24 May 05 |
enell |
38 |
ok = test_all(); |
642 |
24 May 05 |
enell |
39 |
TestUtil.stop(); |
642 |
24 May 05 |
enell |
40 |
} |
642 |
24 May 05 |
enell |
41 |
|
642 |
24 May 05 |
enell |
42 |
static boolean test_all() |
642 |
24 May 05 |
enell |
43 |
{ |
642 |
24 May 05 |
enell |
44 |
write("++Testing disk usage"); |
642 |
24 May 05 |
enell |
45 |
write_header(); |
642 |
24 May 05 |
enell |
46 |
|
642 |
24 May 05 |
enell |
// Standard tests: only list is meaningful |
3719 |
12 Sep 07 |
nicklas |
48 |
int file_id = TestFile.test_create("test.upload.txt", false, false); |
642 |
24 May 05 |
enell |
49 |
test_list(); |
1529 |
27 Oct 05 |
nicklas |
50 |
|
1529 |
27 Oct 05 |
nicklas |
51 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
642 |
24 May 05 |
enell |
52 |
TestFile.test_delete(file_id); |
642 |
24 May 05 |
enell |
53 |
|
642 |
24 May 05 |
enell |
// Standard test: Delete |
642 |
24 May 05 |
enell |
55 |
write("++Testing disk usage " + (ok ? "OK" : "Failed") + "\n"); |
642 |
24 May 05 |
enell |
56 |
return ok; |
642 |
24 May 05 |
enell |
57 |
} |
642 |
24 May 05 |
enell |
58 |
|
642 |
24 May 05 |
enell |
59 |
static void test_list() |
642 |
24 May 05 |
enell |
60 |
{ |
642 |
24 May 05 |
enell |
61 |
DbControl dc = null; |
642 |
24 May 05 |
enell |
62 |
try |
642 |
24 May 05 |
enell |
63 |
{ |
642 |
24 May 05 |
enell |
64 |
dc = TestUtil.getDbControl(); |
1935 |
07 Feb 06 |
nicklas |
65 |
User user = User.getById(dc, TestUtil.getSessionControl().getLoggedInUserId()); |
2930 |
17 Nov 06 |
nicklas |
66 |
ItemResultList<DiskUsage> l = DiskUsage.getQuery(user, null).list(dc); |
642 |
24 May 05 |
enell |
67 |
for (int i = 0; i < l.size(); i++) |
642 |
24 May 05 |
enell |
68 |
{ |
642 |
24 May 05 |
enell |
69 |
write_item(i, l.get(i)); |
642 |
24 May 05 |
enell |
70 |
} |
642 |
24 May 05 |
enell |
71 |
write("--List disk usage OK (" + l.size() + ")"); |
642 |
24 May 05 |
enell |
72 |
} |
816 |
23 Jun 05 |
nicklas |
73 |
catch (Throwable ex) |
642 |
24 May 05 |
enell |
74 |
{ |
642 |
24 May 05 |
enell |
75 |
write("--List disk usage FAILED"); |
642 |
24 May 05 |
enell |
76 |
ex.printStackTrace(); |
642 |
24 May 05 |
enell |
77 |
ok = false; |
642 |
24 May 05 |
enell |
78 |
} |
642 |
24 May 05 |
enell |
79 |
finally |
642 |
24 May 05 |
enell |
80 |
{ |
642 |
24 May 05 |
enell |
81 |
if (dc != null) |
642 |
24 May 05 |
enell |
82 |
dc.close(); |
642 |
24 May 05 |
enell |
83 |
} |
642 |
24 May 05 |
enell |
84 |
} |
642 |
24 May 05 |
enell |
85 |
|
642 |
24 May 05 |
enell |
86 |
static void write_header() |
642 |
24 May 05 |
enell |
87 |
{ |
642 |
24 May 05 |
enell |
88 |
if (!TestUtil.getSilent()) |
642 |
24 May 05 |
enell |
89 |
{ |
5011 |
24 Jun 09 |
nicklas |
90 |
write(" \tID \tItem\tQuotaType\tLocation\tBytes\tUser"); |
5011 |
24 Jun 09 |
nicklas |
91 |
write("-- \t-- \t----\t---------\t--------\t-----\t----"); |
642 |
24 May 05 |
enell |
92 |
} |
642 |
24 May 05 |
enell |
93 |
} |
642 |
24 May 05 |
enell |
94 |
|
642 |
24 May 05 |
enell |
95 |
static void write_item(int i, DiskUsage du) |
642 |
24 May 05 |
enell |
96 |
throws BaseException |
642 |
24 May 05 |
enell |
97 |
{ |
642 |
24 May 05 |
enell |
98 |
if (!TestUtil.getSilent()) |
5011 |
24 Jun 09 |
nicklas |
99 |
write(i + ":\t" + du.getId() + "\t" + du.getItem() + "\t" + du.getQuotaType() + "\t" + du.getLocation() + "\t" + du.getBytes() + "\t" + du.getUser()); |
642 |
24 May 05 |
enell |
100 |
} |
642 |
24 May 05 |
enell |
101 |
|
642 |
24 May 05 |
enell |
102 |
static void write(String message) |
642 |
24 May 05 |
enell |
103 |
{ |
642 |
24 May 05 |
enell |
104 |
System.out.println(message); |
642 |
24 May 05 |
enell |
105 |
} |
642 |
24 May 05 |
enell |
106 |
} |