2213 |
04 May 06 |
nicklas |
1 |
/* |
2213 |
04 May 06 |
nicklas |
$Id$ |
2213 |
04 May 06 |
nicklas |
3 |
|
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
2213 |
04 May 06 |
nicklas |
5 |
|
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/ |
2213 |
04 May 06 |
nicklas |
8 |
|
2213 |
04 May 06 |
nicklas |
BASE is free software; you can redistribute it and/or |
2213 |
04 May 06 |
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 |
2213 |
04 May 06 |
nicklas |
of the License, or (at your option) any later version. |
2213 |
04 May 06 |
nicklas |
13 |
|
2213 |
04 May 06 |
nicklas |
BASE is distributed in the hope that it will be useful, |
2213 |
04 May 06 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2213 |
04 May 06 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2213 |
04 May 06 |
nicklas |
GNU General Public License for more details. |
2213 |
04 May 06 |
nicklas |
18 |
|
2213 |
04 May 06 |
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/>. |
2213 |
04 May 06 |
nicklas |
21 |
*/ |
2213 |
04 May 06 |
nicklas |
22 |
import java.util.List; |
4347 |
18 Jun 08 |
nicklas |
23 |
import java.util.Set; |
2213 |
04 May 06 |
nicklas |
24 |
|
2213 |
04 May 06 |
nicklas |
25 |
import net.sf.basedb.core.DbControl; |
4347 |
18 Jun 08 |
nicklas |
26 |
import net.sf.basedb.core.Item; |
2213 |
04 May 06 |
nicklas |
27 |
import net.sf.basedb.core.Nameable; |
2213 |
04 May 06 |
nicklas |
28 |
import net.sf.basedb.core.Removable; |
2213 |
04 May 06 |
nicklas |
29 |
import net.sf.basedb.core.Trashcan; |
2213 |
04 May 06 |
nicklas |
30 |
|
2213 |
04 May 06 |
nicklas |
31 |
public class TestTrashcan |
2213 |
04 May 06 |
nicklas |
32 |
{ |
2213 |
04 May 06 |
nicklas |
33 |
|
2213 |
04 May 06 |
nicklas |
34 |
static boolean ok = true; |
2213 |
04 May 06 |
nicklas |
35 |
public static void main(String[] args) |
2213 |
04 May 06 |
nicklas |
36 |
{ |
2213 |
04 May 06 |
nicklas |
37 |
TestUtil.checkArgs(args); |
2213 |
04 May 06 |
nicklas |
38 |
TestUtil.begin(); |
2213 |
04 May 06 |
nicklas |
39 |
ok = test_all(); |
2213 |
04 May 06 |
nicklas |
40 |
TestUtil.stop(); |
2213 |
04 May 06 |
nicklas |
41 |
} |
2213 |
04 May 06 |
nicklas |
42 |
|
2213 |
04 May 06 |
nicklas |
43 |
static boolean test_all() |
2213 |
04 May 06 |
nicklas |
44 |
{ |
2213 |
04 May 06 |
nicklas |
45 |
write("++Testing Trashcan"); |
2213 |
04 May 06 |
nicklas |
46 |
write_header(); |
2213 |
04 May 06 |
nicklas |
47 |
test_list(); |
2213 |
04 May 06 |
nicklas |
48 |
write("++Testing Trashcan "+(ok ? "OK" : "Failed")+"\n"); |
2213 |
04 May 06 |
nicklas |
49 |
return ok; |
2213 |
04 May 06 |
nicklas |
50 |
} |
2213 |
04 May 06 |
nicklas |
51 |
|
2213 |
04 May 06 |
nicklas |
52 |
|
2213 |
04 May 06 |
nicklas |
53 |
static void test_list() |
2213 |
04 May 06 |
nicklas |
54 |
{ |
2213 |
04 May 06 |
nicklas |
55 |
DbControl dc = null; |
2213 |
04 May 06 |
nicklas |
56 |
try |
2213 |
04 May 06 |
nicklas |
57 |
{ |
2213 |
04 May 06 |
nicklas |
58 |
dc = TestUtil.getDbControl(); |
4347 |
18 Jun 08 |
nicklas |
59 |
List<Removable> l = Trashcan.getItems(dc, (Set<Item>)null, 0, 0); |
2213 |
04 May 06 |
nicklas |
60 |
for (int i = 0; i<l.size(); i++) |
2213 |
04 May 06 |
nicklas |
61 |
{ |
2213 |
04 May 06 |
nicklas |
62 |
write_item(i, l.get(i)); |
2213 |
04 May 06 |
nicklas |
63 |
} |
2213 |
04 May 06 |
nicklas |
64 |
write("--List items in trashcan OK"); |
2213 |
04 May 06 |
nicklas |
65 |
} |
2213 |
04 May 06 |
nicklas |
66 |
catch (Throwable ex) |
2213 |
04 May 06 |
nicklas |
67 |
{ |
2213 |
04 May 06 |
nicklas |
68 |
write("--List items in trashcan FAILED"); |
2213 |
04 May 06 |
nicklas |
69 |
ex.printStackTrace(); |
2213 |
04 May 06 |
nicklas |
70 |
ok = false; |
2213 |
04 May 06 |
nicklas |
71 |
} |
2213 |
04 May 06 |
nicklas |
72 |
} |
2213 |
04 May 06 |
nicklas |
73 |
|
2213 |
04 May 06 |
nicklas |
74 |
static void write_header() |
2213 |
04 May 06 |
nicklas |
75 |
{ |
2213 |
04 May 06 |
nicklas |
76 |
if (!TestUtil.getSilent()) |
2213 |
04 May 06 |
nicklas |
77 |
{ |
2213 |
04 May 06 |
nicklas |
78 |
write(" \tID \tType \tName \tDescription"); |
2213 |
04 May 06 |
nicklas |
79 |
write("-- \t-- \t---- \t--------- \t-----------"); |
2213 |
04 May 06 |
nicklas |
80 |
} |
2213 |
04 May 06 |
nicklas |
81 |
} |
2213 |
04 May 06 |
nicklas |
82 |
|
2213 |
04 May 06 |
nicklas |
83 |
static void write(String message) |
2213 |
04 May 06 |
nicklas |
84 |
{ |
2213 |
04 May 06 |
nicklas |
85 |
System.out.println(message); |
2213 |
04 May 06 |
nicklas |
86 |
} |
2213 |
04 May 06 |
nicklas |
87 |
|
2213 |
04 May 06 |
nicklas |
88 |
static void write_item(int i, Removable item) |
2213 |
04 May 06 |
nicklas |
89 |
{ |
2213 |
04 May 06 |
nicklas |
90 |
if (!TestUtil.getSilent()) |
2213 |
04 May 06 |
nicklas |
91 |
{ |
2213 |
04 May 06 |
nicklas |
92 |
System.out.print(i+":\t"+item.getId()+"\t"+item.getType()); |
2213 |
04 May 06 |
nicklas |
93 |
if (item instanceof Nameable) |
2213 |
04 May 06 |
nicklas |
94 |
{ |
2213 |
04 May 06 |
nicklas |
95 |
Nameable nameable = (Nameable)item; |
2213 |
04 May 06 |
nicklas |
96 |
String description = nameable.getDescription(); |
2213 |
04 May 06 |
nicklas |
97 |
if (description != null && description.length() > 20) |
2213 |
04 May 06 |
nicklas |
98 |
{ |
2213 |
04 May 06 |
nicklas |
99 |
description = description.substring(0, 20) + "..."; |
2213 |
04 May 06 |
nicklas |
100 |
} |
2213 |
04 May 06 |
nicklas |
101 |
System.out.println("\t" + nameable.getName() + "\t" + description); |
2213 |
04 May 06 |
nicklas |
102 |
} |
2213 |
04 May 06 |
nicklas |
103 |
else |
2213 |
04 May 06 |
nicklas |
104 |
{ |
2213 |
04 May 06 |
nicklas |
105 |
System.out.println("\t" + item.toString()); |
2213 |
04 May 06 |
nicklas |
106 |
} |
2213 |
04 May 06 |
nicklas |
107 |
} |
2213 |
04 May 06 |
nicklas |
108 |
|
2213 |
04 May 06 |
nicklas |
109 |
} |
2213 |
04 May 06 |
nicklas |
110 |
|
2213 |
04 May 06 |
nicklas |
111 |
} |
2213 |
04 May 06 |
nicklas |
112 |
|