625 |
20 May 05 |
samuel |
1 |
/* |
625 |
20 May 05 |
samuel |
$Id$ |
625 |
20 May 05 |
samuel |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Samuel Andersson, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
625 |
20 May 05 |
samuel |
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/ |
625 |
20 May 05 |
samuel |
9 |
|
625 |
20 May 05 |
samuel |
BASE is free software; you can redistribute it and/or |
625 |
20 May 05 |
samuel |
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 |
625 |
20 May 05 |
samuel |
of the License, or (at your option) any later version. |
625 |
20 May 05 |
samuel |
14 |
|
625 |
20 May 05 |
samuel |
BASE is distributed in the hope that it will be useful, |
625 |
20 May 05 |
samuel |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
625 |
20 May 05 |
samuel |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
625 |
20 May 05 |
samuel |
GNU General Public License for more details. |
625 |
20 May 05 |
samuel |
19 |
|
625 |
20 May 05 |
samuel |
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/>. |
625 |
20 May 05 |
samuel |
22 |
*/ |
625 |
20 May 05 |
samuel |
23 |
import net.sf.basedb.core.*; |
5340 |
10 May 10 |
nicklas |
24 |
|
625 |
20 May 05 |
samuel |
25 |
import java.util.Date; |
5340 |
10 May 10 |
nicklas |
26 |
import java.util.Set; |
625 |
20 May 05 |
samuel |
27 |
|
625 |
20 May 05 |
samuel |
28 |
public class TestReporterType |
625 |
20 May 05 |
samuel |
29 |
{ |
625 |
20 May 05 |
samuel |
30 |
|
625 |
20 May 05 |
samuel |
31 |
static boolean ok = true; |
625 |
20 May 05 |
samuel |
32 |
public static void main(String[] args) |
625 |
20 May 05 |
samuel |
33 |
{ |
625 |
20 May 05 |
samuel |
34 |
TestUtil.checkArgs(args); |
625 |
20 May 05 |
samuel |
35 |
TestUtil.begin(); |
625 |
20 May 05 |
samuel |
36 |
ok = test_all(); |
625 |
20 May 05 |
samuel |
37 |
TestUtil.stop(); |
625 |
20 May 05 |
samuel |
38 |
} |
625 |
20 May 05 |
samuel |
39 |
|
625 |
20 May 05 |
samuel |
40 |
static boolean test_all() |
625 |
20 May 05 |
samuel |
41 |
{ |
625 |
20 May 05 |
samuel |
42 |
write("++Testing reporter type"); |
625 |
20 May 05 |
samuel |
43 |
write_header(); |
625 |
20 May 05 |
samuel |
// Standard tests: create, load, list |
625 |
20 May 05 |
samuel |
45 |
int id = test_create(); |
625 |
20 May 05 |
samuel |
46 |
test_load(id); |
625 |
20 May 05 |
samuel |
47 |
test_list(); |
625 |
20 May 05 |
samuel |
48 |
|
625 |
20 May 05 |
samuel |
// Standard test: Delete |
1529 |
27 Oct 05 |
nicklas |
50 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
625 |
20 May 05 |
samuel |
51 |
test_delete(id); |
625 |
20 May 05 |
samuel |
52 |
write("++Testing reporter type "+(ok ? "OK" : "Failed")+"\n"); |
625 |
20 May 05 |
samuel |
53 |
return ok; |
625 |
20 May 05 |
samuel |
54 |
} |
625 |
20 May 05 |
samuel |
55 |
|
625 |
20 May 05 |
samuel |
56 |
static int test_create() |
625 |
20 May 05 |
samuel |
57 |
{ |
625 |
20 May 05 |
samuel |
58 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.REPORTERTYPE)) return 0; |
625 |
20 May 05 |
samuel |
59 |
int id = 0; |
625 |
20 May 05 |
samuel |
60 |
DbControl dc = null; |
625 |
20 May 05 |
samuel |
61 |
try |
625 |
20 May 05 |
samuel |
62 |
{ |
625 |
20 May 05 |
samuel |
63 |
dc = TestUtil.getDbControl(); |
625 |
20 May 05 |
samuel |
64 |
ReporterType rt = ReporterType.getNew(dc); |
625 |
20 May 05 |
samuel |
65 |
rt.setName("Test reporter type"); |
625 |
20 May 05 |
samuel |
66 |
rt.setDescription("Added at "+new Date()); |
625 |
20 May 05 |
samuel |
67 |
dc.saveItem(rt); |
625 |
20 May 05 |
samuel |
68 |
dc.commit(); |
625 |
20 May 05 |
samuel |
69 |
id = rt.getId(); |
625 |
20 May 05 |
samuel |
70 |
write_item(0, rt); |
625 |
20 May 05 |
samuel |
71 |
write("--Create reporter type OK"); |
625 |
20 May 05 |
samuel |
72 |
} |
816 |
23 Jun 05 |
nicklas |
73 |
catch (Throwable ex) |
625 |
20 May 05 |
samuel |
74 |
{ |
625 |
20 May 05 |
samuel |
75 |
write("--Create reporter type FAILED"); |
625 |
20 May 05 |
samuel |
76 |
ex.printStackTrace(); |
625 |
20 May 05 |
samuel |
77 |
ok = false; |
625 |
20 May 05 |
samuel |
78 |
} |
625 |
20 May 05 |
samuel |
79 |
finally |
625 |
20 May 05 |
samuel |
80 |
{ |
625 |
20 May 05 |
samuel |
81 |
if (dc != null) dc.close(); |
625 |
20 May 05 |
samuel |
82 |
} |
625 |
20 May 05 |
samuel |
83 |
return id; |
625 |
20 May 05 |
samuel |
84 |
} |
625 |
20 May 05 |
samuel |
85 |
|
625 |
20 May 05 |
samuel |
86 |
static void test_load(int id) |
625 |
20 May 05 |
samuel |
87 |
{ |
625 |
20 May 05 |
samuel |
88 |
if (id == 0) return; |
625 |
20 May 05 |
samuel |
89 |
DbControl dc = null; |
625 |
20 May 05 |
samuel |
90 |
try |
625 |
20 May 05 |
samuel |
91 |
{ |
625 |
20 May 05 |
samuel |
92 |
dc = TestUtil.getDbControl(); |
625 |
20 May 05 |
samuel |
93 |
ReporterType rt = ReporterType.getById(dc, id); |
625 |
20 May 05 |
samuel |
94 |
write_item(0, rt); |
625 |
20 May 05 |
samuel |
95 |
write("--Load reporter type OK"); |
625 |
20 May 05 |
samuel |
96 |
} |
816 |
23 Jun 05 |
nicklas |
97 |
catch (Throwable ex) |
625 |
20 May 05 |
samuel |
98 |
{ |
625 |
20 May 05 |
samuel |
99 |
write("--Load reporter type FAILED"); |
625 |
20 May 05 |
samuel |
100 |
ex.printStackTrace(); |
625 |
20 May 05 |
samuel |
101 |
ok = false; |
625 |
20 May 05 |
samuel |
102 |
} |
625 |
20 May 05 |
samuel |
103 |
finally |
625 |
20 May 05 |
samuel |
104 |
{ |
625 |
20 May 05 |
samuel |
105 |
if (dc != null) dc.close(); |
625 |
20 May 05 |
samuel |
106 |
} |
625 |
20 May 05 |
samuel |
107 |
} |
625 |
20 May 05 |
samuel |
108 |
|
625 |
20 May 05 |
samuel |
109 |
static void test_list() |
625 |
20 May 05 |
samuel |
110 |
{ |
625 |
20 May 05 |
samuel |
111 |
DbControl dc = null; |
625 |
20 May 05 |
samuel |
112 |
try |
625 |
20 May 05 |
samuel |
113 |
{ |
625 |
20 May 05 |
samuel |
114 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
115 |
ItemResultList<ReporterType> l = ReporterType.getQuery().list(dc); |
625 |
20 May 05 |
samuel |
116 |
for (int i = 0; i<l.size(); i++) |
625 |
20 May 05 |
samuel |
117 |
{ |
625 |
20 May 05 |
samuel |
118 |
write_item(i, l.get(i)); |
625 |
20 May 05 |
samuel |
119 |
} |
625 |
20 May 05 |
samuel |
120 |
write("--List reporter types OK ("+l.size()+")"); |
625 |
20 May 05 |
samuel |
121 |
} |
816 |
23 Jun 05 |
nicklas |
122 |
catch (Throwable ex) |
625 |
20 May 05 |
samuel |
123 |
{ |
625 |
20 May 05 |
samuel |
124 |
write("--List reporter types FAILED"); |
625 |
20 May 05 |
samuel |
125 |
ex.printStackTrace(); |
625 |
20 May 05 |
samuel |
126 |
ok = false; |
625 |
20 May 05 |
samuel |
127 |
} |
625 |
20 May 05 |
samuel |
128 |
finally |
625 |
20 May 05 |
samuel |
129 |
{ |
625 |
20 May 05 |
samuel |
130 |
if (dc != null) dc.close(); |
625 |
20 May 05 |
samuel |
131 |
} |
625 |
20 May 05 |
samuel |
132 |
} |
625 |
20 May 05 |
samuel |
133 |
|
625 |
20 May 05 |
samuel |
134 |
static void test_delete(int id) |
625 |
20 May 05 |
samuel |
135 |
{ |
625 |
20 May 05 |
samuel |
136 |
if (id == 0) return; |
625 |
20 May 05 |
samuel |
137 |
DbControl dc = null; |
625 |
20 May 05 |
samuel |
138 |
try |
625 |
20 May 05 |
samuel |
139 |
{ |
625 |
20 May 05 |
samuel |
140 |
dc = TestUtil.getDbControl(); |
625 |
20 May 05 |
samuel |
141 |
ReporterType rt = ReporterType.getById(dc, id); |
625 |
20 May 05 |
samuel |
142 |
dc.deleteItem(rt); |
5340 |
10 May 10 |
nicklas |
143 |
Set<ItemProxy> using = rt.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
144 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
145 |
{ |
5340 |
10 May 10 |
nicklas |
146 |
throw new BaseException(rt + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
147 |
} |
625 |
20 May 05 |
samuel |
148 |
dc.commit(); |
625 |
20 May 05 |
samuel |
149 |
write("--Delete reporter type OK"); |
625 |
20 May 05 |
samuel |
150 |
} |
816 |
23 Jun 05 |
nicklas |
151 |
catch (Throwable ex) |
625 |
20 May 05 |
samuel |
152 |
{ |
625 |
20 May 05 |
samuel |
153 |
write("--Delete reporter type FAILED"); |
625 |
20 May 05 |
samuel |
154 |
ex.printStackTrace(); |
625 |
20 May 05 |
samuel |
155 |
ok = false; |
625 |
20 May 05 |
samuel |
156 |
} |
625 |
20 May 05 |
samuel |
157 |
finally |
625 |
20 May 05 |
samuel |
158 |
{ |
625 |
20 May 05 |
samuel |
159 |
if (dc != null) dc.close(); |
625 |
20 May 05 |
samuel |
160 |
} |
625 |
20 May 05 |
samuel |
161 |
} |
625 |
20 May 05 |
samuel |
162 |
|
625 |
20 May 05 |
samuel |
163 |
static void write_header() |
625 |
20 May 05 |
samuel |
164 |
{ |
625 |
20 May 05 |
samuel |
165 |
if (!TestUtil.getSilent()) |
625 |
20 May 05 |
samuel |
166 |
{ |
625 |
20 May 05 |
samuel |
167 |
write(" \tID \tName \tDescription\tType"); |
625 |
20 May 05 |
samuel |
168 |
write("-- \t-- \t--------- \t-----------\t----"); |
625 |
20 May 05 |
samuel |
169 |
} |
625 |
20 May 05 |
samuel |
170 |
} |
625 |
20 May 05 |
samuel |
171 |
static void write_item(int i, ReporterType rt) |
625 |
20 May 05 |
samuel |
172 |
throws BaseException |
625 |
20 May 05 |
samuel |
173 |
{ |
625 |
20 May 05 |
samuel |
174 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+rt.getId()+"\t"+rt.getName()+"\t"+ |
625 |
20 May 05 |
samuel |
175 |
rt.getDescription()); |
625 |
20 May 05 |
samuel |
176 |
} |
625 |
20 May 05 |
samuel |
177 |
static void write(String message) |
625 |
20 May 05 |
samuel |
178 |
{ |
625 |
20 May 05 |
samuel |
179 |
System.out.println(message); |
625 |
20 May 05 |
samuel |
180 |
} |
625 |
20 May 05 |
samuel |
181 |
|
625 |
20 May 05 |
samuel |
182 |
|
625 |
20 May 05 |
samuel |
183 |
|
625 |
20 May 05 |
samuel |
184 |
|
625 |
20 May 05 |
samuel |
185 |
|
625 |
20 May 05 |
samuel |
186 |
} |
625 |
20 May 05 |
samuel |
187 |
|