132 |
10 Mar 05 |
nicklas |
1 |
/* |
132 |
10 Mar 05 |
nicklas |
$Id$ |
132 |
10 Mar 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 |
132 |
10 Mar 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/ |
132 |
10 Mar 05 |
nicklas |
9 |
|
132 |
10 Mar 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
132 |
10 Mar 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 |
132 |
10 Mar 05 |
nicklas |
of the License, or (at your option) any later version. |
132 |
10 Mar 05 |
nicklas |
14 |
|
132 |
10 Mar 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
132 |
10 Mar 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
132 |
10 Mar 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
132 |
10 Mar 05 |
nicklas |
GNU General Public License for more details. |
132 |
10 Mar 05 |
nicklas |
19 |
|
132 |
10 Mar 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/>. |
132 |
10 Mar 05 |
nicklas |
22 |
*/ |
132 |
10 Mar 05 |
nicklas |
23 |
import net.sf.basedb.core.*; |
5340 |
10 May 10 |
nicklas |
24 |
|
132 |
10 Mar 05 |
nicklas |
25 |
import java.util.Date; |
260 |
24 Mar 05 |
nicklas |
26 |
import java.util.EnumSet; |
5340 |
10 May 10 |
nicklas |
27 |
import java.util.Set; |
132 |
10 Mar 05 |
nicklas |
28 |
|
132 |
10 Mar 05 |
nicklas |
29 |
public class TestGroup |
132 |
10 Mar 05 |
nicklas |
30 |
{ |
132 |
10 Mar 05 |
nicklas |
31 |
static boolean ok = true; |
132 |
10 Mar 05 |
nicklas |
32 |
|
132 |
10 Mar 05 |
nicklas |
33 |
public static void main(String[] args) |
132 |
10 Mar 05 |
nicklas |
34 |
{ |
132 |
10 Mar 05 |
nicklas |
35 |
TestUtil.checkArgs(args); |
132 |
10 Mar 05 |
nicklas |
36 |
TestUtil.begin(); |
132 |
10 Mar 05 |
nicklas |
37 |
ok = test_all(); |
132 |
10 Mar 05 |
nicklas |
38 |
TestUtil.stop(); |
132 |
10 Mar 05 |
nicklas |
39 |
} |
132 |
10 Mar 05 |
nicklas |
40 |
|
132 |
10 Mar 05 |
nicklas |
41 |
static boolean test_all() |
132 |
10 Mar 05 |
nicklas |
42 |
{ |
132 |
10 Mar 05 |
nicklas |
43 |
write("++Testing groups"); |
132 |
10 Mar 05 |
nicklas |
44 |
write_header(); |
132 |
10 Mar 05 |
nicklas |
// Standard tests: create, load, list |
221 |
23 Mar 05 |
nicklas |
46 |
int id = test_create(true); |
221 |
23 Mar 05 |
nicklas |
47 |
int id2 = test_create(false); |
132 |
10 Mar 05 |
nicklas |
48 |
test_load(id); |
292 |
31 Mar 05 |
nicklas |
49 |
test_list(-1); |
132 |
10 Mar 05 |
nicklas |
50 |
|
132 |
10 Mar 05 |
nicklas |
// Extra tests: add, list and remove users |
292 |
31 Mar 05 |
nicklas |
52 |
test_listusers(id, 0); |
132 |
10 Mar 05 |
nicklas |
53 |
test_adduser(id, SystemItems.getId(User.ROOT)); |
292 |
31 Mar 05 |
nicklas |
54 |
test_listusers(id, 1); |
1529 |
27 Oct 05 |
nicklas |
55 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
132 |
10 Mar 05 |
nicklas |
56 |
test_removeuser(id, SystemItems.getId(User.ROOT)); |
292 |
31 Mar 05 |
nicklas |
57 |
test_listusers(id, 0); |
132 |
10 Mar 05 |
nicklas |
58 |
|
132 |
10 Mar 05 |
nicklas |
// Extra tests: add, list and remove groups |
292 |
31 Mar 05 |
nicklas |
60 |
test_listgroups(id, 0); |
132 |
10 Mar 05 |
nicklas |
61 |
test_addgroup(id, id2); |
292 |
31 Mar 05 |
nicklas |
62 |
test_listgroups(id, 1); |
1529 |
27 Oct 05 |
nicklas |
63 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
132 |
10 Mar 05 |
nicklas |
64 |
test_removegroup(id, id2); |
292 |
31 Mar 05 |
nicklas |
65 |
test_listgroups(id, 0); |
132 |
10 Mar 05 |
nicklas |
66 |
|
260 |
24 Mar 05 |
nicklas |
// Extra tests: add, list and remove projects |
5368 |
22 Jun 10 |
nicklas |
68 |
int projectId = TestProject.test_create("Group project", true); |
292 |
31 Mar 05 |
nicklas |
69 |
test_listprojects(id, 0); |
266 |
29 Mar 05 |
nicklas |
70 |
TestProject.test_addgroup(projectId, id, EnumSet.of(Permission.WRITE)); |
292 |
31 Mar 05 |
nicklas |
71 |
test_listprojects(id, 1); |
1529 |
27 Oct 05 |
nicklas |
72 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
260 |
24 Mar 05 |
nicklas |
73 |
TestProject.test_removegroup(projectId, id); |
292 |
31 Mar 05 |
nicklas |
74 |
test_listprojects(id, 0); |
260 |
24 Mar 05 |
nicklas |
75 |
TestProject.test_delete(projectId); |
260 |
24 Mar 05 |
nicklas |
76 |
|
132 |
10 Mar 05 |
nicklas |
// Standard test: Delete |
221 |
23 Mar 05 |
nicklas |
78 |
test_delete(id2); |
132 |
10 Mar 05 |
nicklas |
79 |
test_delete(id); |
132 |
10 Mar 05 |
nicklas |
80 |
write("++Testing groups "+(ok ? "OK" : "Failed")+"\n"); |
132 |
10 Mar 05 |
nicklas |
81 |
return ok; |
132 |
10 Mar 05 |
nicklas |
82 |
} |
132 |
10 Mar 05 |
nicklas |
83 |
|
221 |
23 Mar 05 |
nicklas |
84 |
static int test_create(boolean setAll) |
132 |
10 Mar 05 |
nicklas |
85 |
{ |
132 |
10 Mar 05 |
nicklas |
86 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.GROUP)) return 0; |
132 |
10 Mar 05 |
nicklas |
87 |
int id = 0; |
132 |
10 Mar 05 |
nicklas |
88 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
89 |
try |
132 |
10 Mar 05 |
nicklas |
90 |
{ |
132 |
10 Mar 05 |
nicklas |
91 |
dc = TestUtil.getDbControl(); |
132 |
10 Mar 05 |
nicklas |
92 |
Group g = Group.getNew(dc); |
221 |
23 Mar 05 |
nicklas |
93 |
if (setAll) |
221 |
23 Mar 05 |
nicklas |
94 |
{ |
221 |
23 Mar 05 |
nicklas |
95 |
g.setName("Test group"); |
221 |
23 Mar 05 |
nicklas |
96 |
g.setDescription("Added at "+new Date()); |
5077 |
26 Aug 09 |
nicklas |
97 |
g.setHiddenMembers(true); |
221 |
23 Mar 05 |
nicklas |
98 |
} |
132 |
10 Mar 05 |
nicklas |
99 |
dc.saveItem(g); |
132 |
10 Mar 05 |
nicklas |
100 |
dc.commit(); |
132 |
10 Mar 05 |
nicklas |
101 |
id = g.getId(); |
132 |
10 Mar 05 |
nicklas |
102 |
write_item(0, g); |
132 |
10 Mar 05 |
nicklas |
103 |
write("--Create group OK"); |
132 |
10 Mar 05 |
nicklas |
104 |
} |
358 |
04 Apr 05 |
nicklas |
105 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
106 |
{ |
132 |
10 Mar 05 |
nicklas |
107 |
write("--Create group FAILED"); |
132 |
10 Mar 05 |
nicklas |
108 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
109 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
110 |
} |
132 |
10 Mar 05 |
nicklas |
111 |
finally |
132 |
10 Mar 05 |
nicklas |
112 |
{ |
132 |
10 Mar 05 |
nicklas |
113 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
114 |
} |
132 |
10 Mar 05 |
nicklas |
115 |
return id; |
132 |
10 Mar 05 |
nicklas |
116 |
} |
132 |
10 Mar 05 |
nicklas |
117 |
|
132 |
10 Mar 05 |
nicklas |
118 |
static void test_load(int id) |
132 |
10 Mar 05 |
nicklas |
119 |
{ |
132 |
10 Mar 05 |
nicklas |
120 |
if (id == 0) return; |
132 |
10 Mar 05 |
nicklas |
121 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
122 |
try |
132 |
10 Mar 05 |
nicklas |
123 |
{ |
132 |
10 Mar 05 |
nicklas |
124 |
dc = TestUtil.getDbControl(); |
132 |
10 Mar 05 |
nicklas |
125 |
Group g = Group.getById(dc, id); |
132 |
10 Mar 05 |
nicklas |
126 |
write_item(0, g); |
132 |
10 Mar 05 |
nicklas |
127 |
write("--Load group OK"); |
132 |
10 Mar 05 |
nicklas |
128 |
} |
358 |
04 Apr 05 |
nicklas |
129 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
130 |
{ |
132 |
10 Mar 05 |
nicklas |
131 |
write("--Load group FAILED"); |
132 |
10 Mar 05 |
nicklas |
132 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
133 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
134 |
} |
132 |
10 Mar 05 |
nicklas |
135 |
finally |
132 |
10 Mar 05 |
nicklas |
136 |
{ |
132 |
10 Mar 05 |
nicklas |
137 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
138 |
} |
132 |
10 Mar 05 |
nicklas |
139 |
} |
132 |
10 Mar 05 |
nicklas |
140 |
|
292 |
31 Mar 05 |
nicklas |
141 |
static void test_list(int expectedResults) |
132 |
10 Mar 05 |
nicklas |
142 |
{ |
256 |
24 Mar 05 |
nicklas |
143 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
144 |
try |
132 |
10 Mar 05 |
nicklas |
145 |
{ |
256 |
24 Mar 05 |
nicklas |
146 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
147 |
ItemResultList<Group> l = Group.getQuery().list(dc); |
132 |
10 Mar 05 |
nicklas |
148 |
for (int i = 0; i<l.size(); i++) |
132 |
10 Mar 05 |
nicklas |
149 |
{ |
256 |
24 Mar 05 |
nicklas |
150 |
write_item(i, l.get(i)); |
132 |
10 Mar 05 |
nicklas |
151 |
} |
292 |
31 Mar 05 |
nicklas |
152 |
if (expectedResults >= 0 && expectedResults != l.size()) |
292 |
31 Mar 05 |
nicklas |
153 |
{ |
292 |
31 Mar 05 |
nicklas |
154 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
292 |
31 Mar 05 |
nicklas |
155 |
} |
132 |
10 Mar 05 |
nicklas |
156 |
write("--List groups OK ("+l.size()+")"); |
132 |
10 Mar 05 |
nicklas |
157 |
} |
358 |
04 Apr 05 |
nicklas |
158 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
159 |
{ |
132 |
10 Mar 05 |
nicklas |
160 |
write("--List groups FAILED"); |
132 |
10 Mar 05 |
nicklas |
161 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
162 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
163 |
} |
132 |
10 Mar 05 |
nicklas |
164 |
finally |
132 |
10 Mar 05 |
nicklas |
165 |
{ |
256 |
24 Mar 05 |
nicklas |
166 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
167 |
} |
132 |
10 Mar 05 |
nicklas |
168 |
} |
132 |
10 Mar 05 |
nicklas |
169 |
|
132 |
10 Mar 05 |
nicklas |
170 |
static void test_delete(int id) |
132 |
10 Mar 05 |
nicklas |
171 |
{ |
132 |
10 Mar 05 |
nicklas |
172 |
if (id == 0) return; |
132 |
10 Mar 05 |
nicklas |
173 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
174 |
try |
132 |
10 Mar 05 |
nicklas |
175 |
{ |
132 |
10 Mar 05 |
nicklas |
176 |
dc = TestUtil.getDbControl(); |
132 |
10 Mar 05 |
nicklas |
177 |
Group g = Group.getById(dc, id); |
132 |
10 Mar 05 |
nicklas |
178 |
dc.deleteItem(g); |
5340 |
10 May 10 |
nicklas |
179 |
Set<ItemProxy> using = g.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
180 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
181 |
{ |
5340 |
10 May 10 |
nicklas |
182 |
throw new BaseException(g + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
183 |
} |
132 |
10 Mar 05 |
nicklas |
184 |
dc.commit(); |
132 |
10 Mar 05 |
nicklas |
185 |
write("--Delete group OK"); |
132 |
10 Mar 05 |
nicklas |
186 |
} |
358 |
04 Apr 05 |
nicklas |
187 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
188 |
{ |
132 |
10 Mar 05 |
nicklas |
189 |
write("--Delete group FAILED"); |
132 |
10 Mar 05 |
nicklas |
190 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
191 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
192 |
} |
132 |
10 Mar 05 |
nicklas |
193 |
finally |
132 |
10 Mar 05 |
nicklas |
194 |
{ |
132 |
10 Mar 05 |
nicklas |
195 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
196 |
} |
132 |
10 Mar 05 |
nicklas |
197 |
} |
132 |
10 Mar 05 |
nicklas |
198 |
|
132 |
10 Mar 05 |
nicklas |
199 |
static void write_header() |
132 |
10 Mar 05 |
nicklas |
200 |
{ |
132 |
10 Mar 05 |
nicklas |
201 |
if (!TestUtil.getSilent()) |
132 |
10 Mar 05 |
nicklas |
202 |
{ |
5077 |
26 Aug 09 |
nicklas |
203 |
write(" \tID \tName \tHidden members\tDescription"); |
5077 |
26 Aug 09 |
nicklas |
204 |
write("-- \t-- \t--------- \t--------------\t-----------"); |
132 |
10 Mar 05 |
nicklas |
205 |
} |
132 |
10 Mar 05 |
nicklas |
206 |
} |
132 |
10 Mar 05 |
nicklas |
207 |
static void write_item(int i, Group g) |
132 |
10 Mar 05 |
nicklas |
208 |
throws BaseException |
132 |
10 Mar 05 |
nicklas |
209 |
{ |
5077 |
26 Aug 09 |
nicklas |
210 |
if (!TestUtil.getSilent()) |
5077 |
26 Aug 09 |
nicklas |
211 |
{ |
5077 |
26 Aug 09 |
nicklas |
212 |
System.out.println(i+":\t"+g.getId()+"\t"+g.getName()+"\t" + g.hasHiddenMembers() + |
5077 |
26 Aug 09 |
nicklas |
213 |
"\t"+g.getDescription()); |
5077 |
26 Aug 09 |
nicklas |
214 |
} |
132 |
10 Mar 05 |
nicklas |
215 |
} |
132 |
10 Mar 05 |
nicklas |
216 |
static void write_item(int i, User u) |
132 |
10 Mar 05 |
nicklas |
217 |
throws BaseException |
132 |
10 Mar 05 |
nicklas |
218 |
{ |
132 |
10 Mar 05 |
nicklas |
219 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+u.getId()+"\t"+u.getName()+"\t"+u.getDescription()); |
132 |
10 Mar 05 |
nicklas |
220 |
} |
260 |
24 Mar 05 |
nicklas |
221 |
static void write_item(int i, Project p) |
260 |
24 Mar 05 |
nicklas |
222 |
throws BaseException |
260 |
24 Mar 05 |
nicklas |
223 |
{ |
260 |
24 Mar 05 |
nicklas |
224 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+p.getId()+"\t"+p.getName()+"\t"+p.getDescription()); |
260 |
24 Mar 05 |
nicklas |
225 |
} |
132 |
10 Mar 05 |
nicklas |
226 |
static void write(String message) |
132 |
10 Mar 05 |
nicklas |
227 |
{ |
132 |
10 Mar 05 |
nicklas |
228 |
System.out.println(message); |
132 |
10 Mar 05 |
nicklas |
229 |
} |
132 |
10 Mar 05 |
nicklas |
230 |
|
132 |
10 Mar 05 |
nicklas |
231 |
static void test_adduser(int id, int userId) |
132 |
10 Mar 05 |
nicklas |
232 |
{ |
132 |
10 Mar 05 |
nicklas |
233 |
if (id == 0 || userId == 0) return; |
132 |
10 Mar 05 |
nicklas |
234 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
235 |
try |
132 |
10 Mar 05 |
nicklas |
236 |
{ |
132 |
10 Mar 05 |
nicklas |
237 |
dc = TestUtil.getDbControl(); |
132 |
10 Mar 05 |
nicklas |
238 |
Group g = Group.getById(dc, id); |
132 |
10 Mar 05 |
nicklas |
239 |
User u = User.getById(dc, userId); |
132 |
10 Mar 05 |
nicklas |
240 |
g.addUser(u); |
132 |
10 Mar 05 |
nicklas |
241 |
dc.commit(); |
132 |
10 Mar 05 |
nicklas |
242 |
write("--Add user to group OK"); |
132 |
10 Mar 05 |
nicklas |
243 |
} |
358 |
04 Apr 05 |
nicklas |
244 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
245 |
{ |
132 |
10 Mar 05 |
nicklas |
246 |
write("--Add user to group FAILED"); |
132 |
10 Mar 05 |
nicklas |
247 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
248 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
249 |
} |
132 |
10 Mar 05 |
nicklas |
250 |
finally |
132 |
10 Mar 05 |
nicklas |
251 |
{ |
132 |
10 Mar 05 |
nicklas |
252 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
253 |
} |
132 |
10 Mar 05 |
nicklas |
254 |
} |
132 |
10 Mar 05 |
nicklas |
255 |
|
292 |
31 Mar 05 |
nicklas |
256 |
static void test_listusers(int id, int expectedResults) |
132 |
10 Mar 05 |
nicklas |
257 |
{ |
132 |
10 Mar 05 |
nicklas |
258 |
if (id == 0) return; |
258 |
24 Mar 05 |
nicklas |
259 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
260 |
try |
132 |
10 Mar 05 |
nicklas |
261 |
{ |
258 |
24 Mar 05 |
nicklas |
262 |
dc = TestUtil.getDbControl(); |
258 |
24 Mar 05 |
nicklas |
263 |
Group g = Group.getById(dc, id); |
1418 |
07 Oct 05 |
nicklas |
264 |
ItemResultList<User> l = g.getUsers().list(dc); |
132 |
10 Mar 05 |
nicklas |
265 |
for (int i=0; i<l.size(); i++) |
132 |
10 Mar 05 |
nicklas |
266 |
{ |
258 |
24 Mar 05 |
nicklas |
267 |
write_item(i, l.get(i)); |
132 |
10 Mar 05 |
nicklas |
268 |
} |
292 |
31 Mar 05 |
nicklas |
269 |
if (expectedResults >= 0 && expectedResults != l.size()) |
292 |
31 Mar 05 |
nicklas |
270 |
{ |
292 |
31 Mar 05 |
nicklas |
271 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
292 |
31 Mar 05 |
nicklas |
272 |
} |
132 |
10 Mar 05 |
nicklas |
273 |
write("--List members of group OK ("+l.size()+")"); |
132 |
10 Mar 05 |
nicklas |
274 |
} |
358 |
04 Apr 05 |
nicklas |
275 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
276 |
{ |
132 |
10 Mar 05 |
nicklas |
277 |
write("--List members of group FAILED"); |
132 |
10 Mar 05 |
nicklas |
278 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
279 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
280 |
} |
132 |
10 Mar 05 |
nicklas |
281 |
finally |
132 |
10 Mar 05 |
nicklas |
282 |
{ |
258 |
24 Mar 05 |
nicklas |
283 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
284 |
} |
132 |
10 Mar 05 |
nicklas |
285 |
} |
132 |
10 Mar 05 |
nicklas |
286 |
|
132 |
10 Mar 05 |
nicklas |
287 |
static void test_removeuser(int id, int userId) |
132 |
10 Mar 05 |
nicklas |
288 |
{ |
132 |
10 Mar 05 |
nicklas |
289 |
if (id == 0 || userId == 0) return; |
132 |
10 Mar 05 |
nicklas |
290 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
291 |
try |
132 |
10 Mar 05 |
nicklas |
292 |
{ |
132 |
10 Mar 05 |
nicklas |
293 |
dc = TestUtil.getDbControl(); |
132 |
10 Mar 05 |
nicklas |
294 |
Group g = Group.getById(dc, id); |
132 |
10 Mar 05 |
nicklas |
295 |
User u = User.getById(dc, userId); |
132 |
10 Mar 05 |
nicklas |
296 |
g.removeUser(u); |
132 |
10 Mar 05 |
nicklas |
297 |
dc.commit(); |
132 |
10 Mar 05 |
nicklas |
298 |
write("--Remove user from group OK"); |
132 |
10 Mar 05 |
nicklas |
299 |
} |
358 |
04 Apr 05 |
nicklas |
300 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
301 |
{ |
132 |
10 Mar 05 |
nicklas |
302 |
write("--Remove user from group FAILED"); |
132 |
10 Mar 05 |
nicklas |
303 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
304 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
305 |
} |
132 |
10 Mar 05 |
nicklas |
306 |
finally |
132 |
10 Mar 05 |
nicklas |
307 |
{ |
132 |
10 Mar 05 |
nicklas |
308 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
309 |
} |
132 |
10 Mar 05 |
nicklas |
310 |
} |
132 |
10 Mar 05 |
nicklas |
311 |
|
132 |
10 Mar 05 |
nicklas |
312 |
static void test_addgroup(int id, int groupId) |
132 |
10 Mar 05 |
nicklas |
313 |
{ |
132 |
10 Mar 05 |
nicklas |
314 |
if (id == 0 || groupId == 0) return; |
132 |
10 Mar 05 |
nicklas |
315 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
316 |
try |
132 |
10 Mar 05 |
nicklas |
317 |
{ |
132 |
10 Mar 05 |
nicklas |
318 |
dc = TestUtil.getDbControl(); |
132 |
10 Mar 05 |
nicklas |
319 |
Group g = Group.getById(dc, id); |
132 |
10 Mar 05 |
nicklas |
320 |
Group g2 = Group.getById(dc, groupId); |
132 |
10 Mar 05 |
nicklas |
321 |
g.addGroup(g2); |
132 |
10 Mar 05 |
nicklas |
322 |
dc.commit(); |
132 |
10 Mar 05 |
nicklas |
323 |
write("--Add group to group OK"); |
132 |
10 Mar 05 |
nicklas |
324 |
} |
358 |
04 Apr 05 |
nicklas |
325 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
326 |
{ |
132 |
10 Mar 05 |
nicklas |
327 |
write("--Add group to group FAILED"); |
132 |
10 Mar 05 |
nicklas |
328 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
329 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
330 |
} |
132 |
10 Mar 05 |
nicklas |
331 |
finally |
132 |
10 Mar 05 |
nicklas |
332 |
{ |
132 |
10 Mar 05 |
nicklas |
333 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
334 |
} |
132 |
10 Mar 05 |
nicklas |
335 |
} |
132 |
10 Mar 05 |
nicklas |
336 |
|
292 |
31 Mar 05 |
nicklas |
337 |
static void test_listgroups(int id, int expectedResults) |
132 |
10 Mar 05 |
nicklas |
338 |
{ |
132 |
10 Mar 05 |
nicklas |
339 |
if (id == 0) return; |
258 |
24 Mar 05 |
nicklas |
340 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
341 |
try |
132 |
10 Mar 05 |
nicklas |
342 |
{ |
258 |
24 Mar 05 |
nicklas |
343 |
dc = TestUtil.getDbControl(); |
258 |
24 Mar 05 |
nicklas |
344 |
Group g = Group.getById(dc, id); |
1418 |
07 Oct 05 |
nicklas |
345 |
ItemResultList<Group> l = g.getGroups().list(dc); |
132 |
10 Mar 05 |
nicklas |
346 |
for (int i=0; i<l.size(); i++) |
132 |
10 Mar 05 |
nicklas |
347 |
{ |
258 |
24 Mar 05 |
nicklas |
348 |
write_item(i, l.get(i)); |
132 |
10 Mar 05 |
nicklas |
349 |
} |
292 |
31 Mar 05 |
nicklas |
350 |
if (expectedResults >= 0 && expectedResults != l.size()) |
292 |
31 Mar 05 |
nicklas |
351 |
{ |
292 |
31 Mar 05 |
nicklas |
352 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
292 |
31 Mar 05 |
nicklas |
353 |
} |
132 |
10 Mar 05 |
nicklas |
354 |
write("--List groups in group OK ("+l.size()+")"); |
132 |
10 Mar 05 |
nicklas |
355 |
} |
358 |
04 Apr 05 |
nicklas |
356 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
357 |
{ |
132 |
10 Mar 05 |
nicklas |
358 |
write("--List groups in group FAILED"); |
132 |
10 Mar 05 |
nicklas |
359 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
360 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
361 |
} |
132 |
10 Mar 05 |
nicklas |
362 |
finally |
132 |
10 Mar 05 |
nicklas |
363 |
{ |
258 |
24 Mar 05 |
nicklas |
364 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
365 |
} |
132 |
10 Mar 05 |
nicklas |
366 |
} |
132 |
10 Mar 05 |
nicklas |
367 |
|
132 |
10 Mar 05 |
nicklas |
368 |
static void test_removegroup(int id, int groupId) |
132 |
10 Mar 05 |
nicklas |
369 |
{ |
132 |
10 Mar 05 |
nicklas |
370 |
if (id == 0 || groupId == 0) return; |
132 |
10 Mar 05 |
nicklas |
371 |
DbControl dc = null; |
132 |
10 Mar 05 |
nicklas |
372 |
try |
132 |
10 Mar 05 |
nicklas |
373 |
{ |
132 |
10 Mar 05 |
nicklas |
374 |
dc = TestUtil.getDbControl(); |
132 |
10 Mar 05 |
nicklas |
375 |
Group g = Group.getById(dc, id); |
132 |
10 Mar 05 |
nicklas |
376 |
Group g2 = Group.getById(dc, groupId); |
132 |
10 Mar 05 |
nicklas |
377 |
g.removeGroup(g2); |
132 |
10 Mar 05 |
nicklas |
378 |
dc.commit(); |
132 |
10 Mar 05 |
nicklas |
379 |
write("--Remove group from group OK"); |
132 |
10 Mar 05 |
nicklas |
380 |
} |
358 |
04 Apr 05 |
nicklas |
381 |
catch (Throwable ex) |
132 |
10 Mar 05 |
nicklas |
382 |
{ |
132 |
10 Mar 05 |
nicklas |
383 |
write("--Remove group from group FAILED"); |
132 |
10 Mar 05 |
nicklas |
384 |
ex.printStackTrace(); |
132 |
10 Mar 05 |
nicklas |
385 |
ok = false; |
132 |
10 Mar 05 |
nicklas |
386 |
} |
132 |
10 Mar 05 |
nicklas |
387 |
finally |
132 |
10 Mar 05 |
nicklas |
388 |
{ |
132 |
10 Mar 05 |
nicklas |
389 |
if (dc != null) dc.close(); |
132 |
10 Mar 05 |
nicklas |
390 |
} |
132 |
10 Mar 05 |
nicklas |
391 |
} |
260 |
24 Mar 05 |
nicklas |
392 |
|
292 |
31 Mar 05 |
nicklas |
393 |
static void test_listprojects(int id, int expectedResults) |
260 |
24 Mar 05 |
nicklas |
394 |
{ |
260 |
24 Mar 05 |
nicklas |
395 |
if (id == 0) return; |
260 |
24 Mar 05 |
nicklas |
396 |
DbControl dc = null; |
260 |
24 Mar 05 |
nicklas |
397 |
try |
260 |
24 Mar 05 |
nicklas |
398 |
{ |
260 |
24 Mar 05 |
nicklas |
399 |
dc = TestUtil.getDbControl(); |
260 |
24 Mar 05 |
nicklas |
400 |
Group g = Group.getById(dc, id); |
1418 |
07 Oct 05 |
nicklas |
401 |
ItemResultList<Project> l = g.getProjects().list(dc); |
260 |
24 Mar 05 |
nicklas |
402 |
for (int i=0; i<l.size(); i++) |
260 |
24 Mar 05 |
nicklas |
403 |
{ |
260 |
24 Mar 05 |
nicklas |
404 |
write_item(i, l.get(i)); |
260 |
24 Mar 05 |
nicklas |
405 |
} |
292 |
31 Mar 05 |
nicklas |
406 |
if (expectedResults >= 0 && expectedResults != l.size()) |
292 |
31 Mar 05 |
nicklas |
407 |
{ |
292 |
31 Mar 05 |
nicklas |
408 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
292 |
31 Mar 05 |
nicklas |
409 |
} |
260 |
24 Mar 05 |
nicklas |
410 |
write("--List projects for group OK ("+l.size()+")"); |
260 |
24 Mar 05 |
nicklas |
411 |
} |
358 |
04 Apr 05 |
nicklas |
412 |
catch (Throwable ex) |
260 |
24 Mar 05 |
nicklas |
413 |
{ |
260 |
24 Mar 05 |
nicklas |
414 |
write("--List projects for group FAILED"); |
260 |
24 Mar 05 |
nicklas |
415 |
ex.printStackTrace(); |
260 |
24 Mar 05 |
nicklas |
416 |
ok = false; |
260 |
24 Mar 05 |
nicklas |
417 |
} |
260 |
24 Mar 05 |
nicklas |
418 |
finally |
260 |
24 Mar 05 |
nicklas |
419 |
{ |
260 |
24 Mar 05 |
nicklas |
420 |
if (dc != null) dc.close(); |
260 |
24 Mar 05 |
nicklas |
421 |
} |
260 |
24 Mar 05 |
nicklas |
422 |
} |
132 |
10 Mar 05 |
nicklas |
423 |
} |
132 |
10 Mar 05 |
nicklas |
424 |
|