5368 |
22 Jun 10 |
nicklas |
1 |
/* |
5368 |
22 Jun 10 |
nicklas |
$Id$ |
5368 |
22 Jun 10 |
nicklas |
3 |
|
5368 |
22 Jun 10 |
nicklas |
Copyright (C) 2005 Nicklas Nordborg |
5368 |
22 Jun 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
5368 |
22 Jun 10 |
nicklas |
6 |
|
5368 |
22 Jun 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5368 |
22 Jun 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5368 |
22 Jun 10 |
nicklas |
9 |
|
5368 |
22 Jun 10 |
nicklas |
BASE is free software; you can redistribute it and/or |
5368 |
22 Jun 10 |
nicklas |
modify it under the terms of the GNU General Public License |
5368 |
22 Jun 10 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5368 |
22 Jun 10 |
nicklas |
of the License, or (at your option) any later version. |
5368 |
22 Jun 10 |
nicklas |
14 |
|
5368 |
22 Jun 10 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5368 |
22 Jun 10 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5368 |
22 Jun 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5368 |
22 Jun 10 |
nicklas |
GNU General Public License for more details. |
5368 |
22 Jun 10 |
nicklas |
19 |
|
5368 |
22 Jun 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5368 |
22 Jun 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5368 |
22 Jun 10 |
nicklas |
22 |
*/ |
5368 |
22 Jun 10 |
nicklas |
23 |
import net.sf.basedb.core.*; |
5368 |
22 Jun 10 |
nicklas |
24 |
import net.sf.basedb.core.query.Expressions; |
5368 |
22 Jun 10 |
nicklas |
25 |
import net.sf.basedb.core.query.Hql; |
5368 |
22 Jun 10 |
nicklas |
26 |
import net.sf.basedb.core.query.Restrictions; |
5368 |
22 Jun 10 |
nicklas |
27 |
|
5368 |
22 Jun 10 |
nicklas |
28 |
import java.util.Date; |
5368 |
22 Jun 10 |
nicklas |
29 |
import java.util.EnumSet; |
5368 |
22 Jun 10 |
nicklas |
30 |
import java.util.Set; |
5368 |
22 Jun 10 |
nicklas |
31 |
|
5368 |
22 Jun 10 |
nicklas |
32 |
public class TestPermissionTemplate |
5368 |
22 Jun 10 |
nicklas |
33 |
{ |
5368 |
22 Jun 10 |
nicklas |
34 |
|
5368 |
22 Jun 10 |
nicklas |
35 |
static boolean ok = true; |
5368 |
22 Jun 10 |
nicklas |
36 |
public static void main(String[] args) |
5368 |
22 Jun 10 |
nicklas |
37 |
{ |
5368 |
22 Jun 10 |
nicklas |
38 |
TestUtil.checkArgs(args); |
5368 |
22 Jun 10 |
nicklas |
39 |
TestUtil.begin(); |
5368 |
22 Jun 10 |
nicklas |
40 |
ok = test_all(); |
5368 |
22 Jun 10 |
nicklas |
41 |
TestUtil.stop(); |
5368 |
22 Jun 10 |
nicklas |
42 |
} |
5368 |
22 Jun 10 |
nicklas |
43 |
|
5368 |
22 Jun 10 |
nicklas |
44 |
static boolean test_all() |
5368 |
22 Jun 10 |
nicklas |
45 |
{ |
5368 |
22 Jun 10 |
nicklas |
46 |
write("++Testing permission templates"); |
5368 |
22 Jun 10 |
nicklas |
47 |
write_header(); |
5368 |
22 Jun 10 |
nicklas |
// Standard tests: create, load, list |
5368 |
22 Jun 10 |
nicklas |
49 |
|
5368 |
22 Jun 10 |
nicklas |
// Create a user, group and project and keys for sharing |
5368 |
22 Jun 10 |
nicklas |
51 |
int userId = TestUser.test_create(false); |
5368 |
22 Jun 10 |
nicklas |
52 |
int groupId = TestGroup.test_create(false); |
5368 |
22 Jun 10 |
nicklas |
53 |
int projectId = TestProject.test_create("Main project", false); |
5368 |
22 Jun 10 |
nicklas |
54 |
int itemKeyId = TestItemKey.test_create(userId, EnumSet.of(Permission.WRITE), groupId, EnumSet.of(Permission.READ)); |
5368 |
22 Jun 10 |
nicklas |
55 |
int projectKeyId = TestProjectKey.test_create(projectId, EnumSet.of(Permission.DELETE)); |
5368 |
22 Jun 10 |
nicklas |
56 |
|
5368 |
22 Jun 10 |
nicklas |
57 |
int id = test_create("Test template", itemKeyId, projectKeyId); |
5368 |
22 Jun 10 |
nicklas |
58 |
test_load(id); |
5368 |
22 Jun 10 |
nicklas |
59 |
test_list(-1); |
5368 |
22 Jun 10 |
nicklas |
60 |
|
5368 |
22 Jun 10 |
nicklas |
61 |
int projectId2 = TestProject.test_create("Template project", false); |
5368 |
22 Jun 10 |
nicklas |
62 |
test_assign_to_project(id, projectId2); |
5368 |
22 Jun 10 |
nicklas |
63 |
TestProject.test_activate_project(projectId2, null); |
6100 |
04 Sep 12 |
nicklas |
64 |
int sampleId = TestSample.test_create(0, "Sample (shared via template)", 0, false); |
5368 |
22 Jun 10 |
nicklas |
65 |
test_verify_share(Item.SAMPLE, sampleId, itemKeyId, projectKeyId); |
5368 |
22 Jun 10 |
nicklas |
66 |
TestProject.test_noactive_project(); |
5368 |
22 Jun 10 |
nicklas |
67 |
|
5368 |
22 Jun 10 |
nicklas |
// Standard test: Delete |
5368 |
22 Jun 10 |
nicklas |
69 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5368 |
22 Jun 10 |
nicklas |
70 |
TestSample.test_delete(sampleId); |
5368 |
22 Jun 10 |
nicklas |
71 |
TestProject.test_delete(projectId2); |
5368 |
22 Jun 10 |
nicklas |
72 |
test_delete(id); |
5368 |
22 Jun 10 |
nicklas |
73 |
|
5368 |
22 Jun 10 |
nicklas |
74 |
TestItemKey.test_delete_unused(-1); |
5368 |
22 Jun 10 |
nicklas |
75 |
TestProjectKey.test_delete_unused(-1); |
5368 |
22 Jun 10 |
nicklas |
76 |
TestProject.test_delete(projectId); |
5368 |
22 Jun 10 |
nicklas |
77 |
TestGroup.test_delete(groupId); |
5368 |
22 Jun 10 |
nicklas |
78 |
TestUser.test_delete(userId); |
5368 |
22 Jun 10 |
nicklas |
79 |
|
5368 |
22 Jun 10 |
nicklas |
80 |
write("++Testing permission templates "+(ok ? "OK" : "Failed")+"\n"); |
5368 |
22 Jun 10 |
nicklas |
81 |
return ok; |
5368 |
22 Jun 10 |
nicklas |
82 |
} |
5368 |
22 Jun 10 |
nicklas |
83 |
|
5368 |
22 Jun 10 |
nicklas |
84 |
static int test_create(String name, int itemKeyId, int projectKeyId) |
5368 |
22 Jun 10 |
nicklas |
85 |
{ |
5632 |
17 May 11 |
nicklas |
86 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.PERMISSIONTEMPLATE)) return 0; |
5368 |
22 Jun 10 |
nicklas |
87 |
int id = 0; |
5368 |
22 Jun 10 |
nicklas |
88 |
DbControl dc = null; |
5368 |
22 Jun 10 |
nicklas |
89 |
try |
5368 |
22 Jun 10 |
nicklas |
90 |
{ |
5368 |
22 Jun 10 |
nicklas |
91 |
dc = TestUtil.getDbControl(); |
5368 |
22 Jun 10 |
nicklas |
92 |
PermissionTemplate pt = PermissionTemplate.getNew(dc); |
5368 |
22 Jun 10 |
nicklas |
93 |
pt.setName(name); |
5368 |
22 Jun 10 |
nicklas |
94 |
if (itemKeyId != 0) pt.setItemKey(ItemKey.getById(dc, itemKeyId)); |
5368 |
22 Jun 10 |
nicklas |
95 |
if (projectKeyId != 0) pt.setProjectKey(ProjectKey.getById(dc, projectKeyId)); |
5368 |
22 Jun 10 |
nicklas |
96 |
pt.setDescription("Added at "+new Date()); |
5368 |
22 Jun 10 |
nicklas |
97 |
dc.saveItem(pt); |
5368 |
22 Jun 10 |
nicklas |
98 |
dc.commit(); |
5368 |
22 Jun 10 |
nicklas |
99 |
id = pt.getId(); |
5368 |
22 Jun 10 |
nicklas |
100 |
dc = TestUtil.getDbControl(); |
5368 |
22 Jun 10 |
nicklas |
101 |
dc.reattachItem(pt, false); |
5368 |
22 Jun 10 |
nicklas |
102 |
write_item(0, pt); |
5368 |
22 Jun 10 |
nicklas |
103 |
write("--Create permission template OK"); |
5368 |
22 Jun 10 |
nicklas |
104 |
} |
5368 |
22 Jun 10 |
nicklas |
105 |
catch (Throwable ex) |
5368 |
22 Jun 10 |
nicklas |
106 |
{ |
5368 |
22 Jun 10 |
nicklas |
107 |
write("--Create permission template FAILED"); |
5368 |
22 Jun 10 |
nicklas |
108 |
ex.printStackTrace(); |
5368 |
22 Jun 10 |
nicklas |
109 |
ok = false; |
5368 |
22 Jun 10 |
nicklas |
110 |
} |
5368 |
22 Jun 10 |
nicklas |
111 |
finally |
5368 |
22 Jun 10 |
nicklas |
112 |
{ |
5368 |
22 Jun 10 |
nicklas |
113 |
if (dc != null) dc.close(); |
5368 |
22 Jun 10 |
nicklas |
114 |
} |
5368 |
22 Jun 10 |
nicklas |
115 |
return id; |
5368 |
22 Jun 10 |
nicklas |
116 |
} |
5368 |
22 Jun 10 |
nicklas |
117 |
|
5368 |
22 Jun 10 |
nicklas |
118 |
static void test_load(int id) |
5368 |
22 Jun 10 |
nicklas |
119 |
{ |
5368 |
22 Jun 10 |
nicklas |
120 |
if (id == 0) return; |
5368 |
22 Jun 10 |
nicklas |
121 |
DbControl dc = null; |
5368 |
22 Jun 10 |
nicklas |
122 |
try |
5368 |
22 Jun 10 |
nicklas |
123 |
{ |
5368 |
22 Jun 10 |
nicklas |
124 |
dc = TestUtil.getDbControl(); |
5368 |
22 Jun 10 |
nicklas |
125 |
PermissionTemplate pt = PermissionTemplate.getById(dc, id); |
5368 |
22 Jun 10 |
nicklas |
126 |
write_item(0, pt); |
5368 |
22 Jun 10 |
nicklas |
127 |
write("--Load permission template OK"); |
5368 |
22 Jun 10 |
nicklas |
128 |
} |
5368 |
22 Jun 10 |
nicklas |
129 |
catch (Throwable ex) |
5368 |
22 Jun 10 |
nicklas |
130 |
{ |
5368 |
22 Jun 10 |
nicklas |
131 |
write("--Load permission template FAILED"); |
5368 |
22 Jun 10 |
nicklas |
132 |
ex.printStackTrace(); |
5368 |
22 Jun 10 |
nicklas |
133 |
ok = false; |
5368 |
22 Jun 10 |
nicklas |
134 |
} |
5368 |
22 Jun 10 |
nicklas |
135 |
finally |
5368 |
22 Jun 10 |
nicklas |
136 |
{ |
5368 |
22 Jun 10 |
nicklas |
137 |
if (dc != null) dc.close(); |
5368 |
22 Jun 10 |
nicklas |
138 |
} |
5368 |
22 Jun 10 |
nicklas |
139 |
} |
5368 |
22 Jun 10 |
nicklas |
140 |
|
5368 |
22 Jun 10 |
nicklas |
141 |
static int test_load(String name) |
5368 |
22 Jun 10 |
nicklas |
142 |
{ |
5368 |
22 Jun 10 |
nicklas |
143 |
if (name == null) return 0; |
5368 |
22 Jun 10 |
nicklas |
144 |
DbControl dc = null; |
5368 |
22 Jun 10 |
nicklas |
145 |
int id = 0; |
5368 |
22 Jun 10 |
nicklas |
146 |
try |
5368 |
22 Jun 10 |
nicklas |
147 |
{ |
5368 |
22 Jun 10 |
nicklas |
148 |
dc = TestUtil.getDbControl(); |
5368 |
22 Jun 10 |
nicklas |
149 |
ItemQuery<PermissionTemplate> query = PermissionTemplate.getQuery(); |
5368 |
22 Jun 10 |
nicklas |
150 |
query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(name))); |
5368 |
22 Jun 10 |
nicklas |
151 |
PermissionTemplate pt = query.list(dc).get(0); |
5368 |
22 Jun 10 |
nicklas |
152 |
write_item(0, pt); |
5368 |
22 Jun 10 |
nicklas |
153 |
write("--Load permission template by name OK"); |
5368 |
22 Jun 10 |
nicklas |
154 |
id = pt.getId(); |
5368 |
22 Jun 10 |
nicklas |
155 |
} |
5368 |
22 Jun 10 |
nicklas |
156 |
catch (Throwable ex) |
5368 |
22 Jun 10 |
nicklas |
157 |
{ |
5368 |
22 Jun 10 |
nicklas |
158 |
write("--Load permission template by name FAILED"); |
5368 |
22 Jun 10 |
nicklas |
159 |
ex.printStackTrace(); |
5368 |
22 Jun 10 |
nicklas |
160 |
ok = false; |
5368 |
22 Jun 10 |
nicklas |
161 |
} |
5368 |
22 Jun 10 |
nicklas |
162 |
finally |
5368 |
22 Jun 10 |
nicklas |
163 |
{ |
5368 |
22 Jun 10 |
nicklas |
164 |
if (dc != null) dc.close(); |
5368 |
22 Jun 10 |
nicklas |
165 |
} |
5368 |
22 Jun 10 |
nicklas |
166 |
return id; |
5368 |
22 Jun 10 |
nicklas |
167 |
} |
5368 |
22 Jun 10 |
nicklas |
168 |
|
5368 |
22 Jun 10 |
nicklas |
169 |
|
5368 |
22 Jun 10 |
nicklas |
170 |
static void test_list(int expectedResults) |
5368 |
22 Jun 10 |
nicklas |
171 |
{ |
5368 |
22 Jun 10 |
nicklas |
172 |
DbControl dc = null; |
5368 |
22 Jun 10 |
nicklas |
173 |
try |
5368 |
22 Jun 10 |
nicklas |
174 |
{ |
5368 |
22 Jun 10 |
nicklas |
175 |
dc = TestUtil.getDbControl(); |
5368 |
22 Jun 10 |
nicklas |
176 |
ItemResultList<PermissionTemplate> l = PermissionTemplate.getQuery().list(dc); |
5368 |
22 Jun 10 |
nicklas |
177 |
for (int i = 0; i<l.size(); i++) |
5368 |
22 Jun 10 |
nicklas |
178 |
{ |
5368 |
22 Jun 10 |
nicklas |
179 |
write_item(i, l.get(i)); |
5368 |
22 Jun 10 |
nicklas |
180 |
} |
5368 |
22 Jun 10 |
nicklas |
181 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5368 |
22 Jun 10 |
nicklas |
182 |
{ |
5368 |
22 Jun 10 |
nicklas |
183 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5368 |
22 Jun 10 |
nicklas |
184 |
} |
5368 |
22 Jun 10 |
nicklas |
185 |
write("--List permission templates OK ("+l.size()+")"); |
5368 |
22 Jun 10 |
nicklas |
186 |
} |
5368 |
22 Jun 10 |
nicklas |
187 |
catch (Throwable ex) |
5368 |
22 Jun 10 |
nicklas |
188 |
{ |
5368 |
22 Jun 10 |
nicklas |
189 |
write("--List permission templates FAILED"); |
5368 |
22 Jun 10 |
nicklas |
190 |
ex.printStackTrace(); |
5368 |
22 Jun 10 |
nicklas |
191 |
ok = false; |
5368 |
22 Jun 10 |
nicklas |
192 |
} |
5368 |
22 Jun 10 |
nicklas |
193 |
finally |
5368 |
22 Jun 10 |
nicklas |
194 |
{ |
5368 |
22 Jun 10 |
nicklas |
195 |
if (dc != null) dc.close(); |
5368 |
22 Jun 10 |
nicklas |
196 |
} |
5368 |
22 Jun 10 |
nicklas |
197 |
} |
5368 |
22 Jun 10 |
nicklas |
198 |
|
5368 |
22 Jun 10 |
nicklas |
199 |
static void test_delete(int id) |
5368 |
22 Jun 10 |
nicklas |
200 |
{ |
5368 |
22 Jun 10 |
nicklas |
201 |
if (id == 0) return; |
5368 |
22 Jun 10 |
nicklas |
202 |
DbControl dc = null; |
5368 |
22 Jun 10 |
nicklas |
203 |
try |
5368 |
22 Jun 10 |
nicklas |
204 |
{ |
5368 |
22 Jun 10 |
nicklas |
205 |
dc = TestUtil.getDbControl(); |
5368 |
22 Jun 10 |
nicklas |
206 |
PermissionTemplate pt = PermissionTemplate.getById(dc, id); |
5368 |
22 Jun 10 |
nicklas |
207 |
dc.deleteItem(pt); |
5368 |
22 Jun 10 |
nicklas |
208 |
Set<ItemProxy> using = pt.getUsingItems(); |
5368 |
22 Jun 10 |
nicklas |
209 |
if (using.size() > 0) |
5368 |
22 Jun 10 |
nicklas |
210 |
{ |
5368 |
22 Jun 10 |
nicklas |
211 |
throw new BaseException(pt + " is used by " + using); |
5368 |
22 Jun 10 |
nicklas |
212 |
} |
5368 |
22 Jun 10 |
nicklas |
213 |
dc.commit(); |
5368 |
22 Jun 10 |
nicklas |
214 |
write("--Delete permission template OK"); |
5368 |
22 Jun 10 |
nicklas |
215 |
} |
5368 |
22 Jun 10 |
nicklas |
216 |
catch (Throwable ex) |
5368 |
22 Jun 10 |
nicklas |
217 |
{ |
5368 |
22 Jun 10 |
nicklas |
218 |
write("--Delete permission template FAILED"); |
5368 |
22 Jun 10 |
nicklas |
219 |
ex.printStackTrace(); |
5368 |
22 Jun 10 |
nicklas |
220 |
ok = false; |
5368 |
22 Jun 10 |
nicklas |
221 |
} |
5368 |
22 Jun 10 |
nicklas |
222 |
finally |
5368 |
22 Jun 10 |
nicklas |
223 |
{ |
5368 |
22 Jun 10 |
nicklas |
224 |
if (dc != null) dc.close(); |
5368 |
22 Jun 10 |
nicklas |
225 |
} |
5368 |
22 Jun 10 |
nicklas |
226 |
} |
5368 |
22 Jun 10 |
nicklas |
227 |
|
5368 |
22 Jun 10 |
nicklas |
228 |
static void write_header() |
5368 |
22 Jun 10 |
nicklas |
229 |
{ |
5368 |
22 Jun 10 |
nicklas |
230 |
if (!TestUtil.getSilent()) |
5368 |
22 Jun 10 |
nicklas |
231 |
{ |
5368 |
22 Jun 10 |
nicklas |
232 |
write(" \tID \tName \tDescription\tItem key\tProject key"); |
5368 |
22 Jun 10 |
nicklas |
233 |
write("-- \t-- \t--------- \t-----------\t--------\t-----------"); |
5368 |
22 Jun 10 |
nicklas |
234 |
} |
5368 |
22 Jun 10 |
nicklas |
235 |
} |
5368 |
22 Jun 10 |
nicklas |
236 |
static void write_item(int i, PermissionTemplate pt) |
5368 |
22 Jun 10 |
nicklas |
237 |
throws BaseException |
5368 |
22 Jun 10 |
nicklas |
238 |
{ |
5368 |
22 Jun 10 |
nicklas |
239 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+pt.getId()+"\t"+pt.getName()+"\t"+pt.getDescription()+ |
5368 |
22 Jun 10 |
nicklas |
240 |
"\t"+pt.getItemKey() + "\t" + pt.getProjectKey()); |
5368 |
22 Jun 10 |
nicklas |
241 |
} |
5368 |
22 Jun 10 |
nicklas |
242 |
static void write(String message) |
5368 |
22 Jun 10 |
nicklas |
243 |
{ |
5368 |
22 Jun 10 |
nicklas |
244 |
System.out.println(message); |
5368 |
22 Jun 10 |
nicklas |
245 |
} |
5368 |
22 Jun 10 |
nicklas |
246 |
|
5368 |
22 Jun 10 |
nicklas |
247 |
static void test_assign_to_project(int templateId, int projectId) |
5368 |
22 Jun 10 |
nicklas |
248 |
{ |
5368 |
22 Jun 10 |
nicklas |
249 |
if (templateId == 0 || projectId == 0) return; |
5368 |
22 Jun 10 |
nicklas |
250 |
DbControl dc = null; |
5368 |
22 Jun 10 |
nicklas |
251 |
try |
5368 |
22 Jun 10 |
nicklas |
252 |
{ |
5368 |
22 Jun 10 |
nicklas |
253 |
dc = TestUtil.getDbControl(); |
5368 |
22 Jun 10 |
nicklas |
254 |
PermissionTemplate pt = PermissionTemplate.getById(dc, templateId); |
5368 |
22 Jun 10 |
nicklas |
255 |
Project p = Project.getById(dc, projectId); |
5368 |
22 Jun 10 |
nicklas |
256 |
p.setPermissionTemplate(pt); |
5368 |
22 Jun 10 |
nicklas |
257 |
dc.commit(); |
5368 |
22 Jun 10 |
nicklas |
258 |
write("--Assign permission template to project OK"); |
5368 |
22 Jun 10 |
nicklas |
259 |
} |
5368 |
22 Jun 10 |
nicklas |
260 |
catch (Throwable ex) |
5368 |
22 Jun 10 |
nicklas |
261 |
{ |
5368 |
22 Jun 10 |
nicklas |
262 |
write("--Assign permission template to project FAILED"); |
5368 |
22 Jun 10 |
nicklas |
263 |
ex.printStackTrace(); |
5368 |
22 Jun 10 |
nicklas |
264 |
ok = false; |
5368 |
22 Jun 10 |
nicklas |
265 |
} |
5368 |
22 Jun 10 |
nicklas |
266 |
finally |
5368 |
22 Jun 10 |
nicklas |
267 |
{ |
5368 |
22 Jun 10 |
nicklas |
268 |
if (dc != null) dc.close(); |
5368 |
22 Jun 10 |
nicklas |
269 |
} |
5368 |
22 Jun 10 |
nicklas |
270 |
} |
5368 |
22 Jun 10 |
nicklas |
271 |
|
5368 |
22 Jun 10 |
nicklas |
272 |
static void test_verify_share(Item itemType, int itemId, int expectedItemKeyId, int expectedProjectKeyId) |
5368 |
22 Jun 10 |
nicklas |
273 |
{ |
5368 |
22 Jun 10 |
nicklas |
274 |
if (itemId == 0) return; |
5368 |
22 Jun 10 |
nicklas |
275 |
DbControl dc = null; |
5368 |
22 Jun 10 |
nicklas |
276 |
try |
5368 |
22 Jun 10 |
nicklas |
277 |
{ |
5368 |
22 Jun 10 |
nicklas |
278 |
dc = TestUtil.getDbControl(); |
5368 |
22 Jun 10 |
nicklas |
279 |
Shareable item = (Shareable)itemType.getById(dc, itemId); |
5368 |
22 Jun 10 |
nicklas |
280 |
|
5368 |
22 Jun 10 |
nicklas |
281 |
if (expectedItemKeyId >= 0) |
5368 |
22 Jun 10 |
nicklas |
282 |
{ |
5368 |
22 Jun 10 |
nicklas |
283 |
ItemKey itemKey = item.getItemKey(); |
5368 |
22 Jun 10 |
nicklas |
284 |
if (expectedItemKeyId != (itemKey == null ? 0 : itemKey.getId())) |
5368 |
22 Jun 10 |
nicklas |
285 |
{ |
5368 |
22 Jun 10 |
nicklas |
286 |
throw new BaseException("Item " + item + " is not shared with the expected item key: " + |
5368 |
22 Jun 10 |
nicklas |
287 |
itemKey + "; expected id = " + expectedItemKeyId); |
5368 |
22 Jun 10 |
nicklas |
288 |
} |
5368 |
22 Jun 10 |
nicklas |
289 |
} |
5368 |
22 Jun 10 |
nicklas |
290 |
if (expectedProjectKeyId >= 0) |
5368 |
22 Jun 10 |
nicklas |
291 |
{ |
5368 |
22 Jun 10 |
nicklas |
292 |
ProjectKey projectKey = item.getProjectKey(); |
5368 |
22 Jun 10 |
nicklas |
293 |
if (expectedProjectKeyId != (projectKey == null ? 0 : projectKey.getId())) |
5368 |
22 Jun 10 |
nicklas |
294 |
{ |
5368 |
22 Jun 10 |
nicklas |
295 |
throw new BaseException("Item " + item + " is not shared with the expected project key: " + |
5368 |
22 Jun 10 |
nicklas |
296 |
projectKey + "; expected id = " + expectedProjectKeyId); |
5368 |
22 Jun 10 |
nicklas |
297 |
} |
5368 |
22 Jun 10 |
nicklas |
298 |
} |
5368 |
22 Jun 10 |
nicklas |
299 |
|
5368 |
22 Jun 10 |
nicklas |
300 |
dc.commit(); |
5368 |
22 Jun 10 |
nicklas |
301 |
write("--Verify item share " + item + " OK"); |
5368 |
22 Jun 10 |
nicklas |
302 |
} |
5368 |
22 Jun 10 |
nicklas |
303 |
catch (Throwable ex) |
5368 |
22 Jun 10 |
nicklas |
304 |
{ |
5368 |
22 Jun 10 |
nicklas |
305 |
write("--Verify item share " + itemType + "[id=" + itemId + "] FAILED"); |
5368 |
22 Jun 10 |
nicklas |
306 |
ex.printStackTrace(); |
5368 |
22 Jun 10 |
nicklas |
307 |
ok = false; |
5368 |
22 Jun 10 |
nicklas |
308 |
} |
5368 |
22 Jun 10 |
nicklas |
309 |
finally |
5368 |
22 Jun 10 |
nicklas |
310 |
{ |
5368 |
22 Jun 10 |
nicklas |
311 |
if (dc != null) dc.close(); |
5368 |
22 Jun 10 |
nicklas |
312 |
} |
5368 |
22 Jun 10 |
nicklas |
313 |
} |
5368 |
22 Jun 10 |
nicklas |
314 |
|
5368 |
22 Jun 10 |
nicklas |
315 |
} |