KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > ant > ComponentTasksTest


1 package org.objectweb.petals.tools.ant;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5
6 import junit.framework.TestCase;
7
8 import org.objectweb.petals.tools.ant.InstallComponentTask;
9 import org.objectweb.petals.tools.ant.ListBindingComponentsTask;
10 import org.objectweb.petals.tools.ant.ListServiceEnginesTask;
11 import org.objectweb.petals.tools.ant.ShutdownComponentTask;
12 import org.objectweb.petals.tools.ant.StartComponentTask;
13 import org.objectweb.petals.tools.ant.StopComponentTask;
14 import org.objectweb.petals.tools.ant.UninstallComponentTask;
15 import org.objectweb.petals.tools.ant.util.ServerUtil;
16
17 /**
18  * Test the component the ant tasks
19  *
20  * @author ddesjardins - eBMWebsourcing
21  */

22 public class ComponentTasksTest extends TestCase {
23
24     /**
25      * Port of the JMX server
26      */

27     private static int port = 9988;
28
29     public void setUp() throws Exception JavaDoc {
30         ServerUtil.start(port);
31     }
32
33     public void tearDown() throws IOException JavaDoc {
34         ServerUtil.stop();
35     }
36
37     /**
38      * Test the exception throwing
39      *
40      * @throws Exception
41      *
42      */

43     public void testExceptionCompoUnsinstalled() throws Exception JavaDoc {
44         testInstall();
45         StartComponentTask startComponentTask = new StartComponentTask();
46         startComponentTask.setPort("" + port);
47         startComponentTask.setName("uninstalledCompo");
48         try {
49             startComponentTask.execute();
50             fail();
51         } catch (Exception JavaDoc e) {
52
53         }
54     }
55
56     /**
57      * Test the exception throwing
58      *
59      */

60     public void testExceptionFileInvalid() {
61         InstallComponentTask installComponentTask = new InstallComponentTask();
62         try {
63             installComponentTask.setFile("foo");
64             installComponentTask.execute();
65             fail();
66         } catch (Exception JavaDoc e) {
67         }
68     }
69
70     /**
71      * Test the exception throwing
72      *
73      */

74     public void testExceptionNameNotSet() {
75         InstallComponentTask installComponentTask = new InstallComponentTask();
76         try {
77             installComponentTask.execute();
78             fail();
79         } catch (Exception JavaDoc e) {
80         }
81     }
82
83     /**
84      * Test the exception throwing
85      *
86      * @throws Exception
87      *
88      */

89     public void testExceptionNameNull() throws Exception JavaDoc {
90         testInstall();
91         StartComponentTask startComponentTask = new StartComponentTask();
92         startComponentTask.setPort("" + port);
93         try {
94             startComponentTask.execute();
95             fail();
96         } catch (Exception JavaDoc e) {
97
98         }
99     }
100
101     /**
102      * Test the exception throwing
103      *
104      * @throws Exception
105      *
106      */

107     public void testExceptionNameNull1() throws Exception JavaDoc {
108         testInstall();
109         UninstallComponentTask uninstallComponentTask = new UninstallComponentTask();
110         uninstallComponentTask.setPort("" + port);
111         try {
112             uninstallComponentTask.execute();
113             fail();
114         } catch (Exception JavaDoc e) {
115
116         }
117     }
118
119     /**
120      * Test the exception throwing
121      *
122      * @throws Exception
123      *
124      */

125     public void testExceptionServerJMX2() throws Exception JavaDoc {
126         testInstall();
127         StartComponentTask startComponentTask = new StartComponentTask();
128         startComponentTask.setPort("" + port);
129         startComponentTask.setName("foo001");
130         try {
131             tearDown();
132             startComponentTask.execute();
133             fail();
134         } catch (Exception JavaDoc e) {
135
136         }
137     }
138     
139     /**
140      * Test the exception throwing
141      *
142      * @throws Exception
143      *
144      */

145     public void testExceptionServerJMX3() throws Exception JavaDoc {
146         testInstall();
147         UninstallComponentTask uninstallComponentTask = new UninstallComponentTask();
148         uninstallComponentTask.setPort("" + port);
149         uninstallComponentTask.setName("foo001");
150         try {
151             tearDown();
152             uninstallComponentTask.execute();
153             fail();
154         } catch (Exception JavaDoc e) {
155
156         }
157     }
158
159     /**
160      * Test the exception throwing
161      *
162      */

163     public void testExceptionServerNotStarted() {
164         InstallComponentTask installComponentTask = new InstallComponentTask();
165         try {
166             tearDown();
167             installComponentTask.setFile("foo");
168             installComponentTask.execute();
169             fail();
170         } catch (Exception JavaDoc e) {
171         }
172     }
173
174     /**
175      * Test the exception throwing
176      *
177      * @throws Exception
178      *
179      */

180     public void testExceptionServiceAssemblyNotDeployed() throws Exception JavaDoc {
181         ListBindingComponentsTask listBindingComponentsTask = new ListBindingComponentsTask();
182         listBindingComponentsTask.setPort("" + port);
183         listBindingComponentsTask.setServiceAssemblyName("foo");
184         listBindingComponentsTask.setBindingComponentName("bar");
185 // listBindingComponentsTask.setSharedLibraryName("test");
186
testInstall();
187         listBindingComponentsTask.execute();
188     }
189
190     /**
191      * Test the exception throwing
192      *
193      */

194     public void testExceptionStateInvalid() {
195         ListBindingComponentsTask listBindingComponentsTask = new ListBindingComponentsTask();
196         listBindingComponentsTask.setPort("" + port);
197         listBindingComponentsTask.setState("fooState");
198         try {
199             testInstall();
200             listBindingComponentsTask.execute();
201             fail();
202         } catch (Exception JavaDoc e) {
203         }
204     }
205
206     /**
207      * Test the exception throwing
208      *
209      */

210     public void testExceptionStateInvalid1() {
211         ListServiceEnginesTask listServiceEnginesTask = new ListServiceEnginesTask();
212         listServiceEnginesTask.setPort("" + port);
213         listServiceEnginesTask.setState("InvalidState");
214         try {
215             testInstall();
216             listServiceEnginesTask.execute();
217             fail();
218         } catch (Exception JavaDoc e) {
219         }
220     }
221
222     /**
223      * Test the component installation task
224      *
225      * @throws Exception
226      * @throws Exception
227      * @throws IOException
228      */

229     public void testInstall() throws Exception JavaDoc {
230         // port = ServerUtil.start(port);
231
String JavaDoc baseDir = this.getClass().getResource(".").toString();
232         baseDir = baseDir.substring(0, baseDir.indexOf("target"));
233         baseDir = baseDir.substring(baseDir.indexOf(":")+1);
234         InstallComponentTask installComponentTask = new InstallComponentTask();
235         installComponentTask.setFile("file:" + baseDir + "src" + File.separator
236                 + "test-data" + File.separator + "clock.zip");
237         installComponentTask.setPort("" + port);
238         installComponentTask.execute();
239     }
240
241     /**
242      * Test the list of bindings component task
243      *
244      * @throws Exception
245      */

246     public void testListBC() throws Exception JavaDoc {
247         testInstall();
248         ListBindingComponentsTask listBindingComponentsTask = new ListBindingComponentsTask();
249         listBindingComponentsTask.setPort("" + port);
250         listBindingComponentsTask.execute();
251     }
252
253     /**
254      * Test the list of service engine task
255      */

256     public void testListSE() {
257         ListServiceEnginesTask listServiceEnginesTask = new ListServiceEnginesTask();
258         listServiceEnginesTask.setPort("" + port);
259         listServiceEnginesTask.execute();
260     }
261
262     /**
263      * Test the list of service engine task
264      *
265      * @throws Exception
266      */

267     public void testListSE1() throws Exception JavaDoc {
268         testInstall();
269         ListServiceEnginesTask listServiceEnginesTask = new ListServiceEnginesTask();
270         listServiceEnginesTask.setPort("" + port);
271         listServiceEnginesTask.setServiceAssemblyName("test");
272         listServiceEnginesTask.setXmlOutput("test");
273 // listServiceEnginesTask.setSharedLibraryName("foo");
274
listServiceEnginesTask.setServiceEngineName("bar");
275         listServiceEnginesTask.execute();
276     }
277
278     /**
279      * Test the list with xml output
280      *
281      * @throws Exception
282      *
283      */

284     public void testListXMLOutput() throws Exception JavaDoc {
285         ListBindingComponentsTask listBindingComponentsTask = new ListBindingComponentsTask();
286         listBindingComponentsTask.setPort("" + port);
287         listBindingComponentsTask.setXmlOutput("output");
288         testInstall();
289         listBindingComponentsTask.execute();
290     }
291
292     /**
293      * Test the component shutdown task
294      *
295      * @throws Exception
296      */

297     public void testShutdown() throws Exception JavaDoc {
298         testInstall();
299         ShutdownComponentTask shutdownComponentTask = new ShutdownComponentTask();
300         shutdownComponentTask.setName("foo001");
301         shutdownComponentTask.setPort("" + port);
302         shutdownComponentTask.execute();
303     }
304
305     /**
306      * Test the component starting task
307      *
308      * @throws Exception
309      */

310     public void testStart() throws Exception JavaDoc {
311         testInstall();
312         StartComponentTask startComponentTask = new StartComponentTask();
313         startComponentTask.setName("foo001");
314         startComponentTask.setPort("" + port);
315         startComponentTask.execute();
316     }
317
318     /**
319      * Test the component stoping task
320      *
321      * @throws Exception
322      */

323     public void testStop() throws Exception JavaDoc {
324         testInstall();
325         StopComponentTask stopComponentTask = new StopComponentTask();
326         stopComponentTask.setName("foo001");
327         stopComponentTask.setPort("" + port);
328         stopComponentTask.execute();
329     }
330
331     /**
332      * Test the component uninstallation task
333      *
334      * @throws Exception
335      */

336     public void testUninstall() throws Exception JavaDoc {
337         testInstall();
338         UninstallComponentTask uninstallComponentTask = new UninstallComponentTask();
339         uninstallComponentTask.setName("foo001");
340         uninstallComponentTask.setPort("" + port);
341         uninstallComponentTask.execute();
342     }
343     
344     /**
345      * Test the component starting task
346      *
347      * @throws Exception
348      */

349     public void testStart1() throws Exception JavaDoc {
350         testInstall();
351         StartComponentTask startComponentTask = new StartComponentTask();
352         startComponentTask.setName("foo001");
353         startComponentTask.setPort("" + port);
354         startComponentTask.setHost("localhost");
355         startComponentTask.setFailOnError("true");
356         startComponentTask.setUsername("");
357         startComponentTask.setPassword("");
358         startComponentTask.execute();
359     }
360
361 }
Popular Tags