930 |
13 Jul 05 |
samuel |
1 |
/* |
930 |
13 Jul 05 |
samuel |
$Id$ |
930 |
13 Jul 05 |
samuel |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Samuel Andersson, Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
930 |
13 Jul 05 |
samuel |
7 |
|
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/ |
930 |
13 Jul 05 |
samuel |
10 |
|
930 |
13 Jul 05 |
samuel |
BASE is free software; you can redistribute it and/or |
930 |
13 Jul 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 |
930 |
13 Jul 05 |
samuel |
of the License, or (at your option) any later version. |
930 |
13 Jul 05 |
samuel |
15 |
|
930 |
13 Jul 05 |
samuel |
BASE is distributed in the hope that it will be useful, |
930 |
13 Jul 05 |
samuel |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
930 |
13 Jul 05 |
samuel |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
930 |
13 Jul 05 |
samuel |
GNU General Public License for more details. |
930 |
13 Jul 05 |
samuel |
20 |
|
930 |
13 Jul 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/>. |
930 |
13 Jul 05 |
samuel |
23 |
*/ |
930 |
13 Jul 05 |
samuel |
24 |
import net.sf.basedb.core.*; |
2817 |
30 Oct 06 |
nicklas |
25 |
import net.sf.basedb.core.plugin.GuiContext; |
2657 |
22 Sep 06 |
martin |
26 |
import net.sf.basedb.core.plugin.Response; |
2817 |
30 Oct 06 |
nicklas |
27 |
import net.sf.basedb.core.plugin.Plugin.MainType; |
930 |
13 Jul 05 |
samuel |
28 |
import net.sf.basedb.core.query.*; |
2657 |
22 Sep 06 |
martin |
29 |
import net.sf.basedb.util.ConsoleProgressReporter; |
930 |
13 Jul 05 |
samuel |
30 |
|
2722 |
11 Oct 06 |
nicklas |
31 |
import java.util.EnumSet; |
2817 |
30 Oct 06 |
nicklas |
32 |
import java.util.Map; |
2657 |
22 Sep 06 |
martin |
33 |
import java.util.Set; |
2646 |
18 Sep 06 |
martin |
34 |
|
930 |
13 Jul 05 |
samuel |
35 |
public class TestPluginDefinition |
930 |
13 Jul 05 |
samuel |
36 |
{ |
930 |
13 Jul 05 |
samuel |
37 |
|
930 |
13 Jul 05 |
samuel |
38 |
static boolean ok = true; |
930 |
13 Jul 05 |
samuel |
39 |
public static void main(String[] args) |
930 |
13 Jul 05 |
samuel |
40 |
{ |
930 |
13 Jul 05 |
samuel |
41 |
TestUtil.checkArgs(args); |
930 |
13 Jul 05 |
samuel |
42 |
TestUtil.begin(); |
930 |
13 Jul 05 |
samuel |
43 |
ok = test_all(); |
930 |
13 Jul 05 |
samuel |
44 |
TestUtil.stop(); |
930 |
13 Jul 05 |
samuel |
45 |
} |
930 |
13 Jul 05 |
samuel |
46 |
|
930 |
13 Jul 05 |
samuel |
47 |
static boolean test_all() |
930 |
13 Jul 05 |
samuel |
48 |
{ |
930 |
13 Jul 05 |
samuel |
49 |
write("++Testing plugin definition"); |
930 |
13 Jul 05 |
samuel |
50 |
write_header(); |
930 |
13 Jul 05 |
samuel |
// Standard tests: create, load, list |
1377 |
22 Sep 05 |
nicklas |
52 |
int pluginType1 = TestPluginType.test_create("NullPluginInterface", null, false); |
1377 |
22 Sep 05 |
nicklas |
53 |
int pluginType2 = TestPluginType.test_create("JarPluginInterface", "JarPlugin.jar", false); |
1377 |
22 Sep 05 |
nicklas |
54 |
|
2722 |
11 Oct 06 |
nicklas |
55 |
ok = ok & TestPluginType.ok; |
2722 |
11 Oct 06 |
nicklas |
56 |
|
1344 |
15 Sep 05 |
nicklas |
57 |
int id = test_create("NullPlugin", null); |
1345 |
19 Sep 05 |
nicklas |
58 |
int id2 = test_create("JarPlugin", "JarPlugin.jar"); |
2657 |
22 Sep 06 |
martin |
59 |
int id3 = test_create("PermissionPlugin", null); |
930 |
13 Jul 05 |
samuel |
60 |
test_load(id); |
2817 |
30 Oct 06 |
nicklas |
61 |
test_count(Item.REPORTER, GuiContext.Type.LIST); |
930 |
13 Jul 05 |
samuel |
62 |
test_list(); |
930 |
13 Jul 05 |
samuel |
63 |
|
5596 |
18 Mar 11 |
nicklas |
64 |
int jobId = test_execute(id2, "foo", false); |
5596 |
18 Mar 11 |
nicklas |
65 |
|
2722 |
11 Oct 06 |
nicklas |
// extra test: test permissions |
2722 |
11 Oct 06 |
nicklas |
67 |
test_set_permissions(id3, Item.NEWS, true, null, null); |
2722 |
11 Oct 06 |
nicklas |
68 |
int job1Id = test_execute(id3, "create", true); |
2722 |
11 Oct 06 |
nicklas |
69 |
test_set_permissions(id3, Item.NEWS, true, EnumSet.of(Permission.CREATE), EnumSet.of(Permission.READ)); |
2722 |
11 Oct 06 |
nicklas |
70 |
int job2Id = test_execute(id3, "create", false); |
2722 |
11 Oct 06 |
nicklas |
71 |
int job3Id = test_execute(id3, "export", true); |
2722 |
11 Oct 06 |
nicklas |
72 |
test_set_permissions(id3, Item.NEWS, true, EnumSet.of(Permission.READ), EnumSet.of(Permission.WRITE)); |
2722 |
11 Oct 06 |
nicklas |
73 |
int job4Id = test_execute(id3, "export", false); |
2722 |
11 Oct 06 |
nicklas |
74 |
test_list_permissions(id3); |
2646 |
18 Sep 06 |
martin |
75 |
|
930 |
13 Jul 05 |
samuel |
// Standard test: Delete |
1529 |
27 Oct 05 |
nicklas |
77 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
2722 |
11 Oct 06 |
nicklas |
78 |
|
5596 |
18 Mar 11 |
nicklas |
79 |
TestJob.test_delete(jobId); |
2722 |
11 Oct 06 |
nicklas |
80 |
TestJob.test_delete(job1Id); |
2722 |
11 Oct 06 |
nicklas |
81 |
TestJob.test_delete(job2Id); |
2722 |
11 Oct 06 |
nicklas |
82 |
TestJob.test_delete(job3Id); |
2722 |
11 Oct 06 |
nicklas |
83 |
TestJob.test_delete(job4Id); |
2722 |
11 Oct 06 |
nicklas |
84 |
|
930 |
13 Jul 05 |
samuel |
85 |
test_delete(id); |
1344 |
15 Sep 05 |
nicklas |
86 |
test_delete(id2); |
2657 |
22 Sep 06 |
martin |
87 |
test_delete(id3); |
1377 |
22 Sep 05 |
nicklas |
88 |
|
1377 |
22 Sep 05 |
nicklas |
89 |
TestPluginType.test_delete(pluginType1); |
1377 |
22 Sep 05 |
nicklas |
90 |
TestPluginType.test_delete(pluginType2); |
930 |
13 Jul 05 |
samuel |
91 |
write("++Testing plugin definition "+(ok ? "OK" : "Failed")+"\n"); |
930 |
13 Jul 05 |
samuel |
92 |
return ok; |
930 |
13 Jul 05 |
samuel |
93 |
} |
930 |
13 Jul 05 |
samuel |
94 |
|
1344 |
15 Sep 05 |
nicklas |
95 |
static int test_create(String className, String jarPath) |
930 |
13 Jul 05 |
samuel |
96 |
{ |
930 |
13 Jul 05 |
samuel |
97 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.PLUGINDEFINITION)) return 0; |
930 |
13 Jul 05 |
samuel |
98 |
int id = 0; |
930 |
13 Jul 05 |
samuel |
99 |
DbControl dc = null; |
930 |
13 Jul 05 |
samuel |
100 |
try |
930 |
13 Jul 05 |
samuel |
101 |
{ |
930 |
13 Jul 05 |
samuel |
102 |
dc = TestUtil.getDbControl(); |
2722 |
11 Oct 06 |
nicklas |
103 |
PluginDefinition pd = PluginDefinition.getNew(dc, className, jarPath, false); |
930 |
13 Jul 05 |
samuel |
104 |
dc.saveItem(pd); |
930 |
13 Jul 05 |
samuel |
105 |
dc.commit(); |
930 |
13 Jul 05 |
samuel |
106 |
id = pd.getId(); |
930 |
13 Jul 05 |
samuel |
107 |
write_item(0, pd); |
930 |
13 Jul 05 |
samuel |
108 |
write("--Create plugin definition OK"); |
930 |
13 Jul 05 |
samuel |
109 |
} |
1309 |
08 Sep 05 |
enell |
110 |
catch (Throwable ex) |
930 |
13 Jul 05 |
samuel |
111 |
{ |
930 |
13 Jul 05 |
samuel |
112 |
write("--Create plugin definition FAILED"); |
930 |
13 Jul 05 |
samuel |
113 |
ex.printStackTrace(); |
930 |
13 Jul 05 |
samuel |
114 |
ok = false; |
930 |
13 Jul 05 |
samuel |
115 |
} |
930 |
13 Jul 05 |
samuel |
116 |
finally |
930 |
13 Jul 05 |
samuel |
117 |
{ |
930 |
13 Jul 05 |
samuel |
118 |
if (dc != null) dc.close(); |
930 |
13 Jul 05 |
samuel |
119 |
} |
930 |
13 Jul 05 |
samuel |
120 |
return id; |
930 |
13 Jul 05 |
samuel |
121 |
} |
930 |
13 Jul 05 |
samuel |
122 |
|
930 |
13 Jul 05 |
samuel |
123 |
static void test_load(int id) |
930 |
13 Jul 05 |
samuel |
124 |
{ |
930 |
13 Jul 05 |
samuel |
125 |
if (id == 0) return; |
930 |
13 Jul 05 |
samuel |
126 |
DbControl dc = null; |
930 |
13 Jul 05 |
samuel |
127 |
try |
930 |
13 Jul 05 |
samuel |
128 |
{ |
930 |
13 Jul 05 |
samuel |
129 |
dc = TestUtil.getDbControl(); |
930 |
13 Jul 05 |
samuel |
130 |
PluginDefinition pd = PluginDefinition.getById(dc, id); |
930 |
13 Jul 05 |
samuel |
131 |
write_item(0, pd); |
930 |
13 Jul 05 |
samuel |
132 |
write("--Load plugin definition OK"); |
930 |
13 Jul 05 |
samuel |
133 |
} |
1309 |
08 Sep 05 |
enell |
134 |
catch (Throwable ex) |
930 |
13 Jul 05 |
samuel |
135 |
{ |
930 |
13 Jul 05 |
samuel |
136 |
write("--Load plugin definition FAILED"); |
930 |
13 Jul 05 |
samuel |
137 |
ex.printStackTrace(); |
930 |
13 Jul 05 |
samuel |
138 |
ok = false; |
930 |
13 Jul 05 |
samuel |
139 |
} |
930 |
13 Jul 05 |
samuel |
140 |
finally |
930 |
13 Jul 05 |
samuel |
141 |
{ |
930 |
13 Jul 05 |
samuel |
142 |
if (dc != null) dc.close(); |
930 |
13 Jul 05 |
samuel |
143 |
} |
930 |
13 Jul 05 |
samuel |
144 |
} |
930 |
13 Jul 05 |
samuel |
145 |
|
2817 |
30 Oct 06 |
nicklas |
146 |
static void test_count(Item itemType, GuiContext.Type contextType) |
2817 |
30 Oct 06 |
nicklas |
147 |
{ |
2817 |
30 Oct 06 |
nicklas |
148 |
DbControl dc = null; |
2817 |
30 Oct 06 |
nicklas |
149 |
try |
2817 |
30 Oct 06 |
nicklas |
150 |
{ |
2817 |
30 Oct 06 |
nicklas |
151 |
dc = TestUtil.getDbControl(); |
2817 |
30 Oct 06 |
nicklas |
152 |
Map<MainType, Integer> count = PluginDefinition.countPlugins(dc, new GuiContext(itemType, contextType)); |
2817 |
30 Oct 06 |
nicklas |
153 |
for (Map.Entry<MainType, Integer> entry : count.entrySet()) |
2817 |
30 Oct 06 |
nicklas |
154 |
{ |
2817 |
30 Oct 06 |
nicklas |
155 |
if (!TestUtil.getSilent()) write(entry.getKey() + "\t" + entry.getValue()); |
2817 |
30 Oct 06 |
nicklas |
156 |
} |
2817 |
30 Oct 06 |
nicklas |
157 |
write("--Count plugin definitions OK"); |
2817 |
30 Oct 06 |
nicklas |
158 |
} |
2817 |
30 Oct 06 |
nicklas |
159 |
|
2817 |
30 Oct 06 |
nicklas |
160 |
catch (Throwable ex) |
2817 |
30 Oct 06 |
nicklas |
161 |
{ |
2817 |
30 Oct 06 |
nicklas |
162 |
write("--Count plugin definitions FAILED"); |
2817 |
30 Oct 06 |
nicklas |
163 |
ex.printStackTrace(); |
2817 |
30 Oct 06 |
nicklas |
164 |
ok = false; |
2817 |
30 Oct 06 |
nicklas |
165 |
} |
2817 |
30 Oct 06 |
nicklas |
166 |
finally |
2817 |
30 Oct 06 |
nicklas |
167 |
{ |
2817 |
30 Oct 06 |
nicklas |
168 |
if (dc != null) dc.close(); |
2817 |
30 Oct 06 |
nicklas |
169 |
} |
2817 |
30 Oct 06 |
nicklas |
170 |
|
2817 |
30 Oct 06 |
nicklas |
171 |
} |
2817 |
30 Oct 06 |
nicklas |
172 |
|
930 |
13 Jul 05 |
samuel |
173 |
static void test_list() |
930 |
13 Jul 05 |
samuel |
174 |
{ |
930 |
13 Jul 05 |
samuel |
175 |
DbControl dc = null; |
930 |
13 Jul 05 |
samuel |
176 |
try |
930 |
13 Jul 05 |
samuel |
177 |
{ |
930 |
13 Jul 05 |
samuel |
178 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
179 |
ItemQuery<PluginDefinition> q = PluginDefinition.getQuery(); |
1418 |
07 Oct 05 |
nicklas |
180 |
ItemResultList<PluginDefinition> l = q.list(dc); |
930 |
13 Jul 05 |
samuel |
181 |
for (int i = 0; i<l.size(); i++) |
930 |
13 Jul 05 |
samuel |
182 |
{ |
930 |
13 Jul 05 |
samuel |
183 |
write_item(i, l.get(i)); |
930 |
13 Jul 05 |
samuel |
184 |
} |
930 |
13 Jul 05 |
samuel |
185 |
write("--List plugin definitions OK ("+l.size()+")"); |
930 |
13 Jul 05 |
samuel |
186 |
} |
1309 |
08 Sep 05 |
enell |
187 |
catch (Throwable ex) |
930 |
13 Jul 05 |
samuel |
188 |
{ |
930 |
13 Jul 05 |
samuel |
189 |
write("--List plugin definitions FAILED"); |
930 |
13 Jul 05 |
samuel |
190 |
ex.printStackTrace(); |
930 |
13 Jul 05 |
samuel |
191 |
ok = false; |
930 |
13 Jul 05 |
samuel |
192 |
} |
930 |
13 Jul 05 |
samuel |
193 |
finally |
930 |
13 Jul 05 |
samuel |
194 |
{ |
930 |
13 Jul 05 |
samuel |
195 |
if (dc != null) dc.close(); |
930 |
13 Jul 05 |
samuel |
196 |
} |
930 |
13 Jul 05 |
samuel |
197 |
} |
930 |
13 Jul 05 |
samuel |
198 |
|
930 |
13 Jul 05 |
samuel |
199 |
static int test_get(String className) |
930 |
13 Jul 05 |
samuel |
200 |
{ |
930 |
13 Jul 05 |
samuel |
201 |
DbControl dc = null; |
930 |
13 Jul 05 |
samuel |
202 |
int pluginDefinitionId = 0; |
930 |
13 Jul 05 |
samuel |
203 |
try |
930 |
13 Jul 05 |
samuel |
204 |
{ |
930 |
13 Jul 05 |
samuel |
205 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
206 |
ItemQuery<PluginDefinition> q = PluginDefinition.getQuery(); |
1418 |
07 Oct 05 |
nicklas |
207 |
q.restrict( |
1256 |
06 Sep 05 |
nicklas |
208 |
Restrictions.eq( |
1418 |
07 Oct 05 |
nicklas |
209 |
Hql.property("className"), |
1256 |
06 Sep 05 |
nicklas |
210 |
Expressions.parameter("className") |
1256 |
06 Sep 05 |
nicklas |
211 |
) |
1256 |
06 Sep 05 |
nicklas |
212 |
); |
1979 |
14 Feb 06 |
nicklas |
213 |
q.setParameter("className", className, Type.STRING); |
1418 |
07 Oct 05 |
nicklas |
214 |
ItemResultList<PluginDefinition> pluginDefinitions = q.list(dc); |
930 |
13 Jul 05 |
samuel |
215 |
if (pluginDefinitions.size() > 0) |
930 |
13 Jul 05 |
samuel |
216 |
{ |
930 |
13 Jul 05 |
samuel |
217 |
PluginDefinition pd = pluginDefinitions.get(0); |
930 |
13 Jul 05 |
samuel |
218 |
pluginDefinitionId = pd.getId(); |
3626 |
03 Aug 07 |
nicklas |
219 |
write("--Get plugin definition "+className+" OK"); |
930 |
13 Jul 05 |
samuel |
220 |
} |
930 |
13 Jul 05 |
samuel |
221 |
else |
930 |
13 Jul 05 |
samuel |
222 |
{ |
3626 |
03 Aug 07 |
nicklas |
223 |
write("--Get plugin definition "+className+" NOT FOUND"); |
930 |
13 Jul 05 |
samuel |
224 |
} |
930 |
13 Jul 05 |
samuel |
225 |
} |
1309 |
08 Sep 05 |
enell |
226 |
catch (Throwable ex) |
930 |
13 Jul 05 |
samuel |
227 |
{ |
3626 |
03 Aug 07 |
nicklas |
228 |
write("--Get plugin definition FAILED"); |
930 |
13 Jul 05 |
samuel |
229 |
ex.printStackTrace(); |
930 |
13 Jul 05 |
samuel |
230 |
ok = false; |
930 |
13 Jul 05 |
samuel |
231 |
} |
930 |
13 Jul 05 |
samuel |
232 |
finally |
930 |
13 Jul 05 |
samuel |
233 |
{ |
930 |
13 Jul 05 |
samuel |
234 |
if (dc != null) dc.close(); |
930 |
13 Jul 05 |
samuel |
235 |
} |
930 |
13 Jul 05 |
samuel |
236 |
return pluginDefinitionId; |
930 |
13 Jul 05 |
samuel |
237 |
} |
930 |
13 Jul 05 |
samuel |
238 |
|
930 |
13 Jul 05 |
samuel |
239 |
static void test_delete(int id) |
930 |
13 Jul 05 |
samuel |
240 |
{ |
930 |
13 Jul 05 |
samuel |
241 |
if (id == 0) return; |
930 |
13 Jul 05 |
samuel |
242 |
DbControl dc = null; |
930 |
13 Jul 05 |
samuel |
243 |
try |
930 |
13 Jul 05 |
samuel |
244 |
{ |
930 |
13 Jul 05 |
samuel |
245 |
dc = TestUtil.getDbControl(); |
930 |
13 Jul 05 |
samuel |
246 |
PluginDefinition pd = PluginDefinition.getById(dc, id); |
930 |
13 Jul 05 |
samuel |
247 |
dc.deleteItem(pd); |
5340 |
10 May 10 |
nicklas |
248 |
Set<ItemProxy> using = pd.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
249 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
250 |
{ |
5340 |
10 May 10 |
nicklas |
251 |
throw new BaseException(pd + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
252 |
} |
930 |
13 Jul 05 |
samuel |
253 |
dc.commit(); |
930 |
13 Jul 05 |
samuel |
254 |
write("--Delete plugin definition OK"); |
930 |
13 Jul 05 |
samuel |
255 |
} |
1309 |
08 Sep 05 |
enell |
256 |
catch (Throwable ex) |
930 |
13 Jul 05 |
samuel |
257 |
{ |
930 |
13 Jul 05 |
samuel |
258 |
write("--Delete plugin definition FAILED"); |
930 |
13 Jul 05 |
samuel |
259 |
ex.printStackTrace(); |
930 |
13 Jul 05 |
samuel |
260 |
ok = false; |
930 |
13 Jul 05 |
samuel |
261 |
} |
930 |
13 Jul 05 |
samuel |
262 |
finally |
930 |
13 Jul 05 |
samuel |
263 |
{ |
930 |
13 Jul 05 |
samuel |
264 |
if (dc != null) dc.close(); |
930 |
13 Jul 05 |
samuel |
265 |
} |
930 |
13 Jul 05 |
samuel |
266 |
} |
2646 |
18 Sep 06 |
martin |
267 |
|
2722 |
11 Oct 06 |
nicklas |
268 |
static int test_execute(int pluginId, String cmd, boolean shouldFail) |
2646 |
18 Sep 06 |
martin |
269 |
{ |
2722 |
11 Oct 06 |
nicklas |
270 |
if (pluginId == 0) return 0; |
2657 |
22 Sep 06 |
martin |
271 |
DbControl dc = null; |
2722 |
11 Oct 06 |
nicklas |
272 |
int jobId = 0; |
2657 |
22 Sep 06 |
martin |
273 |
try |
2657 |
22 Sep 06 |
martin |
274 |
{ |
2657 |
22 Sep 06 |
martin |
275 |
dc = TestUtil.getDbControl(); |
2657 |
22 Sep 06 |
martin |
276 |
|
2722 |
11 Oct 06 |
nicklas |
277 |
PluginDefinition plugin = PluginDefinition.getById(dc, pluginId); |
2722 |
11 Oct 06 |
nicklas |
278 |
int numNews = (int)News.getQuery().count(dc); |
4254 |
28 Apr 08 |
nicklas |
279 |
Job job = Job.getNew(dc, plugin, null, null); |
2722 |
11 Oct 06 |
nicklas |
280 |
job.setParameterValue("cmd", new StringParameterType(), cmd); |
2722 |
11 Oct 06 |
nicklas |
281 |
job.setParameterValue("shouldFail", new BooleanParameterType(), shouldFail); |
2722 |
11 Oct 06 |
nicklas |
282 |
job.setParameterValue("numNews", new IntegerParameterType(), numNews); |
6433 |
14 Mar 14 |
nicklas |
283 |
job.setScheduled(null, null); |
4819 |
18 Mar 09 |
nicklas |
284 |
dc.saveItem(job); |
4819 |
18 Mar 09 |
nicklas |
285 |
dc.commit(); |
4819 |
18 Mar 09 |
nicklas |
286 |
jobId = job.getId(); |
2657 |
22 Sep 06 |
martin |
287 |
|
4819 |
18 Mar 09 |
nicklas |
288 |
dc = TestUtil.getDbControl(); |
4819 |
18 Mar 09 |
nicklas |
289 |
job = Job.getById(dc, jobId); |
2722 |
11 Oct 06 |
nicklas |
290 |
PluginExecutionRequest request = |
2722 |
11 Oct 06 |
nicklas |
291 |
job.execute(TestUtil.getSilent() ? null : new ConsoleProgressReporter(), TestUtil.getLocalIp()); |
2722 |
11 Oct 06 |
nicklas |
292 |
dc.commit(); |
2657 |
22 Sep 06 |
martin |
293 |
|
2722 |
11 Oct 06 |
nicklas |
294 |
PluginResponse response = request.invoke(); |
2722 |
11 Oct 06 |
nicklas |
295 |
if (response.getStatus() != Response.Status.DONE) |
2657 |
22 Sep 06 |
martin |
296 |
{ |
2722 |
11 Oct 06 |
nicklas |
297 |
throw new BaseException(response.getMessage(), response.getErrorList() != null ? |
2722 |
11 Oct 06 |
nicklas |
298 |
response.getErrorList().get(0) : null); |
2657 |
22 Sep 06 |
martin |
299 |
} |
2722 |
11 Oct 06 |
nicklas |
300 |
write("--Execute plugin with permissions OK; response=" + response.getMessage()); |
2657 |
22 Sep 06 |
martin |
301 |
} |
2722 |
11 Oct 06 |
nicklas |
302 |
catch (Throwable ex) |
2657 |
22 Sep 06 |
martin |
303 |
{ |
2722 |
11 Oct 06 |
nicklas |
304 |
write("--Execute plugin with permissions FAILED"); |
2657 |
22 Sep 06 |
martin |
305 |
ok = false; |
2657 |
22 Sep 06 |
martin |
306 |
ex.printStackTrace(); |
2657 |
22 Sep 06 |
martin |
307 |
} |
2657 |
22 Sep 06 |
martin |
308 |
finally |
2657 |
22 Sep 06 |
martin |
309 |
{ |
2657 |
22 Sep 06 |
martin |
310 |
if (dc != null) dc.close(); |
2657 |
22 Sep 06 |
martin |
311 |
} |
2722 |
11 Oct 06 |
nicklas |
312 |
return jobId; |
2657 |
22 Sep 06 |
martin |
313 |
} |
2657 |
22 Sep 06 |
martin |
314 |
|
2722 |
11 Oct 06 |
nicklas |
315 |
static void test_set_permissions(int id, Item itemType, boolean usePermission, Set<Permission> granted, Set<Permission> denied) |
2657 |
22 Sep 06 |
martin |
316 |
{ |
2722 |
11 Oct 06 |
nicklas |
317 |
if (id == 0) return; |
2646 |
18 Sep 06 |
martin |
318 |
DbControl dc = null; |
2646 |
18 Sep 06 |
martin |
319 |
try |
2646 |
18 Sep 06 |
martin |
320 |
{ |
2646 |
18 Sep 06 |
martin |
321 |
dc = TestUtil.getDbControl(); |
2722 |
11 Oct 06 |
nicklas |
322 |
PluginDefinition pd = PluginDefinition.getById(dc, id); |
2722 |
11 Oct 06 |
nicklas |
323 |
RoleKey rk = RoleKey.getById(dc, SystemItems.getRoleKeyId(itemType)); |
2722 |
11 Oct 06 |
nicklas |
324 |
pd.setPermissions(rk, granted, denied); |
2657 |
22 Sep 06 |
martin |
325 |
pd.setUsePermissions(usePermission); |
2657 |
22 Sep 06 |
martin |
326 |
dc.commit(); |
2722 |
11 Oct 06 |
nicklas |
327 |
write("--Set plugin permission OK"); |
2646 |
18 Sep 06 |
martin |
328 |
} |
2646 |
18 Sep 06 |
martin |
329 |
catch (Throwable ex) |
2657 |
22 Sep 06 |
martin |
330 |
{ |
2722 |
11 Oct 06 |
nicklas |
331 |
write("--Set plugin permission FAILED"); |
2722 |
11 Oct 06 |
nicklas |
332 |
ok = false; |
2657 |
22 Sep 06 |
martin |
333 |
ex.printStackTrace(); |
2657 |
22 Sep 06 |
martin |
334 |
} |
2657 |
22 Sep 06 |
martin |
335 |
finally |
2646 |
18 Sep 06 |
martin |
336 |
{ |
2657 |
22 Sep 06 |
martin |
337 |
if (dc != null) dc.close(); |
2646 |
18 Sep 06 |
martin |
338 |
} |
2657 |
22 Sep 06 |
martin |
339 |
} |
2657 |
22 Sep 06 |
martin |
340 |
|
2722 |
11 Oct 06 |
nicklas |
341 |
static void test_list_permissions(int id) |
2657 |
22 Sep 06 |
martin |
342 |
{ |
2722 |
11 Oct 06 |
nicklas |
343 |
if (id == 0) return; |
2657 |
22 Sep 06 |
martin |
344 |
DbControl dc = null; |
2657 |
22 Sep 06 |
martin |
345 |
try |
2657 |
22 Sep 06 |
martin |
346 |
{ |
2657 |
22 Sep 06 |
martin |
347 |
dc = TestUtil.getDbControl(); |
2722 |
11 Oct 06 |
nicklas |
348 |
PluginDefinition pd = PluginDefinition.getById(dc, id); |
2722 |
11 Oct 06 |
nicklas |
349 |
ItemQuery<RoleKey> q = RoleKey.getQuery(); |
2722 |
11 Oct 06 |
nicklas |
350 |
ItemResultList<RoleKey> l = q.list(dc); |
2722 |
11 Oct 06 |
nicklas |
351 |
for (int i = 0; i<l.size(); i++) |
2657 |
22 Sep 06 |
martin |
352 |
{ |
2722 |
11 Oct 06 |
nicklas |
353 |
RoleKey key = l.get(i); |
2722 |
11 Oct 06 |
nicklas |
354 |
write_item(i, key, pd.getGranted(key), pd.getDenied(key)); |
2702 |
04 Oct 06 |
nicklas |
355 |
} |
2722 |
11 Oct 06 |
nicklas |
356 |
write("--List plugin permissions OK ("+l.size()+")"); |
2657 |
22 Sep 06 |
martin |
357 |
} |
2657 |
22 Sep 06 |
martin |
358 |
catch (Throwable ex) |
2722 |
11 Oct 06 |
nicklas |
359 |
{ |
2722 |
11 Oct 06 |
nicklas |
360 |
write("--List plugin permissions FAILED"); |
2722 |
11 Oct 06 |
nicklas |
361 |
ok = false; |
2722 |
11 Oct 06 |
nicklas |
362 |
ex.printStackTrace(); |
2702 |
04 Oct 06 |
nicklas |
363 |
} |
2702 |
04 Oct 06 |
nicklas |
364 |
finally |
2702 |
04 Oct 06 |
nicklas |
365 |
{ |
2702 |
04 Oct 06 |
nicklas |
366 |
if (dc != null) dc.close(); |
2702 |
04 Oct 06 |
nicklas |
367 |
} |
2657 |
22 Sep 06 |
martin |
368 |
} |
2657 |
22 Sep 06 |
martin |
369 |
|
2722 |
11 Oct 06 |
nicklas |
370 |
|
930 |
13 Jul 05 |
samuel |
371 |
static void write_header() |
930 |
13 Jul 05 |
samuel |
372 |
{ |
930 |
13 Jul 05 |
samuel |
373 |
if (!TestUtil.getSilent()) |
930 |
13 Jul 05 |
samuel |
374 |
{ |
930 |
13 Jul 05 |
samuel |
375 |
write(" \tID \tName \tDescription\tVersion\tCopyright\tContact\tEmail\tUrl"); |
930 |
13 Jul 05 |
samuel |
376 |
write("-- \t-- \t--------- \t-----------\t-------\t---------\t-------\t-----\t---"); |
930 |
13 Jul 05 |
samuel |
377 |
} |
930 |
13 Jul 05 |
samuel |
378 |
} |
930 |
13 Jul 05 |
samuel |
379 |
static void write_item(int i, PluginDefinition pd) |
930 |
13 Jul 05 |
samuel |
380 |
throws BaseException |
930 |
13 Jul 05 |
samuel |
381 |
{ |
930 |
13 Jul 05 |
samuel |
382 |
if (!TestUtil.getSilent()) |
930 |
13 Jul 05 |
samuel |
383 |
{ |
930 |
13 Jul 05 |
samuel |
384 |
System.out.println(i+":\t"+pd.getId()+"\t"+pd.getName()+"\t"+pd.getDescription()+ |
930 |
13 Jul 05 |
samuel |
385 |
"\t"+pd.getVersionString()+"\t"+pd.getCopyright()+"\t"+ |
930 |
13 Jul 05 |
samuel |
386 |
pd.getContact()+"\t"+pd.getEmail()+"\t"+pd.getUrl()); |
930 |
13 Jul 05 |
samuel |
387 |
} |
930 |
13 Jul 05 |
samuel |
388 |
} |
2722 |
11 Oct 06 |
nicklas |
389 |
|
2722 |
11 Oct 06 |
nicklas |
390 |
static void write_item(int i, RoleKey key, Set<Permission> granted, Set<Permission> denied) |
2722 |
11 Oct 06 |
nicklas |
391 |
{ |
2722 |
11 Oct 06 |
nicklas |
392 |
if (!TestUtil.getSilent()) |
2722 |
11 Oct 06 |
nicklas |
393 |
{ |
2722 |
11 Oct 06 |
nicklas |
394 |
System.out.println(i+":\t"+key.getName()+"\t"+granted+"\t"+denied); |
2722 |
11 Oct 06 |
nicklas |
395 |
} |
2722 |
11 Oct 06 |
nicklas |
396 |
} |
2722 |
11 Oct 06 |
nicklas |
397 |
|
930 |
13 Jul 05 |
samuel |
398 |
static void write(String message) |
930 |
13 Jul 05 |
samuel |
399 |
{ |
930 |
13 Jul 05 |
samuel |
400 |
System.out.println(message); |
930 |
13 Jul 05 |
samuel |
401 |
} |
930 |
13 Jul 05 |
samuel |
402 |
|
930 |
13 Jul 05 |
samuel |
403 |
} |
930 |
13 Jul 05 |
samuel |
404 |
|