361 |
04 Apr 05 |
nicklas |
1 |
/* |
361 |
04 Apr 05 |
nicklas |
$Id$ |
361 |
04 Apr 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
361 |
04 Apr 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/ |
361 |
04 Apr 05 |
nicklas |
9 |
|
361 |
04 Apr 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
361 |
04 Apr 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 |
361 |
04 Apr 05 |
nicklas |
of the License, or (at your option) any later version. |
361 |
04 Apr 05 |
nicklas |
14 |
|
361 |
04 Apr 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
361 |
04 Apr 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
361 |
04 Apr 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
361 |
04 Apr 05 |
nicklas |
GNU General Public License for more details. |
361 |
04 Apr 05 |
nicklas |
19 |
|
361 |
04 Apr 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/>. |
361 |
04 Apr 05 |
nicklas |
22 |
*/ |
361 |
04 Apr 05 |
nicklas |
23 |
import net.sf.basedb.core.*; |
361 |
04 Apr 05 |
nicklas |
24 |
|
361 |
04 Apr 05 |
nicklas |
25 |
public class TestSession |
361 |
04 Apr 05 |
nicklas |
26 |
{ |
361 |
04 Apr 05 |
nicklas |
27 |
|
361 |
04 Apr 05 |
nicklas |
28 |
static boolean ok = true; |
361 |
04 Apr 05 |
nicklas |
29 |
|
361 |
04 Apr 05 |
nicklas |
30 |
public static void main(String[] args) |
361 |
04 Apr 05 |
nicklas |
31 |
{ |
361 |
04 Apr 05 |
nicklas |
32 |
TestUtil.checkArgs(args); |
361 |
04 Apr 05 |
nicklas |
33 |
TestUtil.begin(); |
361 |
04 Apr 05 |
nicklas |
34 |
ok = test_all(); |
361 |
04 Apr 05 |
nicklas |
35 |
TestUtil.stop(); |
361 |
04 Apr 05 |
nicklas |
36 |
} |
361 |
04 Apr 05 |
nicklas |
37 |
|
361 |
04 Apr 05 |
nicklas |
38 |
static boolean test_all() |
361 |
04 Apr 05 |
nicklas |
39 |
{ |
361 |
04 Apr 05 |
nicklas |
40 |
write("++Testing session"); |
361 |
04 Apr 05 |
nicklas |
41 |
write_header(); |
361 |
04 Apr 05 |
nicklas |
// Standard tests: only list has meaning |
361 |
04 Apr 05 |
nicklas |
43 |
test_list(); |
361 |
04 Apr 05 |
nicklas |
44 |
|
361 |
04 Apr 05 |
nicklas |
// Extra tests: |
361 |
04 Apr 05 |
nicklas |
46 |
|
361 |
04 Apr 05 |
nicklas |
// Standard test: Delete - not applicable to session items |
361 |
04 Apr 05 |
nicklas |
48 |
|
361 |
04 Apr 05 |
nicklas |
49 |
write("++Testing session "+(ok ? "OK" : "Failed")+"\n"); |
361 |
04 Apr 05 |
nicklas |
50 |
return ok; |
361 |
04 Apr 05 |
nicklas |
51 |
} |
361 |
04 Apr 05 |
nicklas |
52 |
|
361 |
04 Apr 05 |
nicklas |
53 |
static void test_list() |
361 |
04 Apr 05 |
nicklas |
54 |
{ |
361 |
04 Apr 05 |
nicklas |
55 |
DbControl dc = null; |
361 |
04 Apr 05 |
nicklas |
56 |
try |
361 |
04 Apr 05 |
nicklas |
57 |
{ |
361 |
04 Apr 05 |
nicklas |
58 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
59 |
ItemResultList<Session> l = Session.getQuery(null).list(dc); |
361 |
04 Apr 05 |
nicklas |
60 |
for (int i = 0; i<l.size(); i++) |
361 |
04 Apr 05 |
nicklas |
61 |
{ |
361 |
04 Apr 05 |
nicklas |
62 |
write_item(i, l.get(i)); |
361 |
04 Apr 05 |
nicklas |
63 |
} |
361 |
04 Apr 05 |
nicklas |
64 |
write("--List sessions OK ("+l.size()+")"); |
361 |
04 Apr 05 |
nicklas |
65 |
} |
361 |
04 Apr 05 |
nicklas |
66 |
catch (Throwable ex) |
361 |
04 Apr 05 |
nicklas |
67 |
{ |
361 |
04 Apr 05 |
nicklas |
68 |
write("--List sessions FAILED"); |
361 |
04 Apr 05 |
nicklas |
69 |
ex.printStackTrace(); |
361 |
04 Apr 05 |
nicklas |
70 |
ok = false; |
361 |
04 Apr 05 |
nicklas |
71 |
} |
361 |
04 Apr 05 |
nicklas |
72 |
finally |
361 |
04 Apr 05 |
nicklas |
73 |
{ |
361 |
04 Apr 05 |
nicklas |
74 |
if (dc != null) dc.close(); |
361 |
04 Apr 05 |
nicklas |
75 |
} |
361 |
04 Apr 05 |
nicklas |
76 |
} |
361 |
04 Apr 05 |
nicklas |
77 |
|
361 |
04 Apr 05 |
nicklas |
78 |
static void write_header() |
361 |
04 Apr 05 |
nicklas |
79 |
{ |
361 |
04 Apr 05 |
nicklas |
80 |
if (!TestUtil.getSilent()) |
361 |
04 Apr 05 |
nicklas |
81 |
{ |
361 |
04 Apr 05 |
nicklas |
82 |
write(" \tID \tLogin time\tLogout time\tUser\tClient"); |
361 |
04 Apr 05 |
nicklas |
83 |
write("-- \t-- \t----------\t-----------\t----\t------"); |
361 |
04 Apr 05 |
nicklas |
84 |
} |
361 |
04 Apr 05 |
nicklas |
85 |
} |
361 |
04 Apr 05 |
nicklas |
86 |
static void write_item(int i, Session ses) |
361 |
04 Apr 05 |
nicklas |
87 |
throws BaseException |
361 |
04 Apr 05 |
nicklas |
88 |
{ |
361 |
04 Apr 05 |
nicklas |
89 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+ses.getId()+"\t"+ |
361 |
04 Apr 05 |
nicklas |
90 |
ses.getLoginTime()+"\t"+ses.getLogoutTime()+"\t"+ses.getUser()+"\t"+ses.getClient()); |
361 |
04 Apr 05 |
nicklas |
91 |
} |
361 |
04 Apr 05 |
nicklas |
92 |
static void write(String message) |
361 |
04 Apr 05 |
nicklas |
93 |
{ |
361 |
04 Apr 05 |
nicklas |
94 |
System.out.println(message); |
361 |
04 Apr 05 |
nicklas |
95 |
} |
361 |
04 Apr 05 |
nicklas |
96 |
|
361 |
04 Apr 05 |
nicklas |
97 |
} |
361 |
04 Apr 05 |
nicklas |
98 |
|